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:
“What we do is as American as lynch mobs. America has always been a complex place.”
—Jerry Garcia (19421995)
“Theres an enduring American compulsion to be on the side of the angels. Expediency alone has never been an adequate American reason for doing anything. When actions are judged, they go before the bar of God, where Mom and the Flag closely flank His presence.”
—Jonathan Raban (b. 1942)
“We thought it would be worth the while to read the epitaphs where so many were lost at sea; however, as not only their lives, but commonly their bodies also, were lost or not identified, there were fewer epitaphs of this sort than we expected, though there were not a few. Their graveyard is the ocean.”
—Henry David Thoreau (18171862)