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:
“No man is good enough to govern another man, without that others consent. I say this is the leading principlethe sheet anchor of American republicanism.”
—Abraham Lincoln (18091865)
“Hath not the morning dawned with added light?
And shall not evening call another star
Out of the infinite regions of the night,
To mark this day in Heaven? At last, we are
A nation among nations; and the world
Shall soon behold in many a distant port
Another flag unfurled!”
—Henry Timrod (18281867)
“The beginning of reform is not so much to equalize property as to train the noble sort of natures not to desire more, and to prevent the lower from getting more.”
—Aristotle (384322 B.C.)