|
|
|
|
|
|
|
|
|
|
Sorting an array that consists of a small number of unique keys is common in practice. One would like an algorithm that adapts to O(n) time when the number of unique keys is O(1). In this example, there are 4 unique keys.
The traditional 2-way partitioning quicksort exhibits its worse-case O(n2) behavior here. For this reason, any quicksort implementation should use 3-way partitioning, where the array is partitioned into values less than, equal, and greater than the pivot. Because the pivot values need not be sorted recursively, 3-way quick sort adapts to O(n) time in this case.
Shell sort also adapts to few unique keys, though I do not know its time complexity in this case.
above to restart
the animations in a row, a column, or the entire table.
Algorithms in Java, Parts 1-4, 3rd edition by Robert Sedgewick. Addison Wesley, 2003.
Programming Pearls by Jon Bentley. Addison Wesley, 1986.
Quicksort is Optimal by Robert Sedgewick and Jon Bentley, Knuthfest, Stanford University, January, 2002.
Comments
— posted by someone on 27-Jan-2010
— posted by someone on 13-Jan-2010
— posted by someone on 20-Dec-2009
— posted by someone on 8-Dec-2009