American Flag Sort

An american flag sort is an efficient, in-place variant of radix sort that distributes items into hundreds of buckets. Non-comparative sorting algorithms such as radix sort and american flag sort are typically used to sort large objects such as strings, for which comparison is not a unit-time operation.

American flag sort iterates through the bits of the objects, considering several bits of each object at a time. For each set of bits, american flag sort makes two passes through the array of objects: first to count the number of objects that will fall in each bin, and second to place each object in its bucket. This works especially well when sorting a byte at a time, using 256 buckets. With some optimizations, it is twice as fast as quicksort for large sets of strings.

The name comes by analogy with the Dutch national flag problem in the last step: efficiently partition the array into many "stripes".

Read more about American Flag Sort:  Algorithm, Sample Implementation in Python

Famous quotes containing the words american, flag and/or sort:

    Even American women are not felt to be persons in the same sense as the male immigrants among the Hungarians, Poles, Russian Jews,—not to speak of Italians, Germans, and the masters of all of us—the Irish!
    Mary Putnam Jacobi (1842–1906)

    “Justice” was done, and the President of the Immortals, in Æschylean phrase, had ended his sport with Tess. And the d’Urberville knights and dames slept on in their tombs unknowing. The two speechless gazers bent themselves down to the earth, as if in prayer, and remained thus a long time, absolutely motionless: the flag continued to wave silently. As soon as they had strength they arose, joined hands again, and went on.
    The End
    Thomas Hardy (1840–1928)

    Even the wisest man grows tense
    With some sort of violence
    Before he can accomplish fate,
    Know his work or choose his mate.

    Poet and sculptor, do the work,
    Nor let the modish painter shirk
    William Butler Yeats (1865–1939)