Matthew Russotto schrieb:
I think except as a demonstration piece for algorithm proof it is of no big use; I've seen it mentioned as being in use as part of quicksort when using a 'fat pivot', but usually the pivot is quite small. Knuth makes it the object of an exercise.
I have today implemented a Dutch National Flag Algorithm that takes N+2 calls to color() and an expected 0.38N or so calls to switch() on a uniform flag distribution, with worst case at 2/3N. This is better than the Bentley and McIlroy algorithm mentioned in Knuth, but were I to use it for quicksort, with the pivot much smaller than the rest of the data, I'd be less efficient than their algorithm (I think) because then I'd be moving the pivot around more.
Oh, and it's all nicely structured, of course.
The point is that this seems to be a sort that is of little practical use if you do 'real' sorting.
Hmm, reading
http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Flag/ ,there's a 3-way quicksort suggested. Doing two 3-way runs at .375N = .75 N to get 9 partitions is about as good as doing 3 2-way runs at 0.25N=.75 N switches. It probably comes down to looking at the overhead?
Does anyone know uses of the Dutch Flag in practice?
Cheers