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:
“The American mood, perhaps even the American character, has changed. There are few manifestations any longer of the old American self-assurance which so irritated Dickens.... Instead, there is a sense of frustration so perceptible that even our politicians ... have attempted to exploit it.”
—Archibald MacLeish (18921982)
“What is Americanism? Every one has a different answer. Some people say it is never to submit to the dictation of a King. Others say Americanism is the pride of liberty and the defence of an insult to the flag with their gore. When some half-developed person tramples on that flag, we should be ready to pour out the blood of the nation, they say. But do we not sit in silence when that flag waves over living conditions which should be an insult to all patriotism?”
—Anna Howard Shaw (18471919)
“What sort of space is that which separates a man from his fellows and makes him solitary?”
—Henry David Thoreau (18171862)