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:
“Old age begins in the nursery, and before the young American is put into jacket and trowsers, he says, I want something which I never saw before and I wish I was not I.”
—Ralph Waldo Emerson (18031882)
“By the rude bridge that arched the flood,
Their flag to Aprils breeze unfurled,
Here once the embattled farmers stood
And fired the shot heard round the world.”
—Ralph Waldo Emerson (18031882)
“Ethnic life in the United States has become a sort of contest like baseball in which the blacks are always the Chicago Cubs.”
—Ishmael Reed (b. 1938)