Quicksort Is Optimal For Many Equal Keys

I prove that the average number of comparisons for median-of-$k$ Quicksort (with fat-pivot a.k.a. three-way partitioning) is asymptotically only a constant $\alpha_k$ times worse than the lower bound for sorting random multisets with $\Omega(n^\varepsilon)$ duplicates of each value (for any $\varepsilon>0$). The constant is $\alpha_k = \ln(2) / \bigl(H_{k+1}-H_{(k+1)/2} \bigr)$, which converges to 1 as $k\to\infty$, so Quicksort is asymptotically optimal for inputs with many duplicates. This resolves a conjecture by Sedgewick and Bentley (1999, 2002) and constitutes the first progress on the analysis of Quicksort with equal elements since Sedgewick's 1977 article.

[1]  L. Devroye The Equivalence of Weak, Strong and Complete Convergence in $L_1$ for Kernel Density Estimates , 1983 .

[2]  Robert E. Tarjan,et al.  Self-adjusting binary search trees , 1985, JACM.

[3]  Chak-Kuen Wong,et al.  Binary search trees with limited rotation , 1983, BIT Comput. Sci. Sect..

[4]  Rainer Kemp Binary Search Trees Constructed from Nondistinct Keys with/without Specified Probabilities , 1996, Theor. Comput. Sci..

[5]  R. B. Hayward,et al.  Large Deviations for Quicksort , 1996, J. Algorithms.

[6]  C. Wong,et al.  Average number of rotations and access cost in iR-trees , 1984 .

[7]  Neelima Gupta,et al.  Distribution-Sensitive Algorithms , 1999, Nord. J. Comput..

[8]  Daniel W. Lozier,et al.  NIST Digital Library of Mathematical Functions , 2003, Annals of Mathematics and Artificial Intelligence.

[9]  C. A. R. Hoare,et al.  Algorithm 64: Quicksort , 1961, Commun. ACM.

[10]  D. Greene Labelled formal languages and their uses , 1983 .

[11]  Robert Sedgewick Quicksort with Equal Keys , 1977, SIAM J. Comput..

[12]  Hosam M. Mahmoud,et al.  Evolution of random search trees , 1991, Wiley-Interscience series in discrete mathematics and optimization.

[13]  William H. Burge An Analysis of Binary Search Trees Formed from Sequences of Nondistinct Keys , 1976, JACM.

[14]  Kerstin Vogler,et al.  Table Of Integrals Series And Products , 2016 .

[15]  Thomas N. Hibbard,et al.  Some Combinatorial Properties of Certain Trees With Applications to Searching and Sorting , 1962, JACM.

[16]  Robert Sedgewick,et al.  The analysis of Quicksort programs , 1977, Acta Informatica.

[17]  Derick Wood,et al.  Locally Balanced Binary Trees , 1976, Comput. J..

[18]  Eli Upfal,et al.  Probability and Computing: Randomized Algorithms and Probabilistic Analysis , 2005 .

[19]  R. Seidel Backwards Analysis of Randomized Geometric Algorithms , 1993 .

[20]  Venkatesh Raman,et al.  Sorting Multisets and Vectors In-Place , 1991, WADS.

[21]  C. SIAMJ. OPTIMAL SAMPLING STRATEGIES IN QUICKSORT AND QUICKSELECT , 2001 .

[22]  J. Ian Munro,et al.  Sorting and Searching in Multisets , 1976, SIAM J. Comput..

[23]  J. Ian Munro,et al.  The Analysis of a Fringe Heuristic for Binary Search Trees , 1985, J. Algorithms.

[24]  C. Q. Lee,et al.  The Computer Journal , 1958, Nature.

[25]  P. Gács,et al.  Algorithms , 1992 .

[26]  M. Habib Probabilistic methods for algorithmic discrete mathematics , 1998 .

[27]  Jyrki Katajainen,et al.  Sorting multisets stably in minimum space , 1992, Acta Informatica.

[28]  L. Devroye Non-Uniform Random Variate Generation , 1986 .

[29]  Derick Wood,et al.  A survey of adaptive sorting algorithms , 1992, CSUR.

[30]  T. F. Móri On random trees , 2002 .

[31]  Philippe Flajolet,et al.  Analytic Combinatorics , 2009 .

[32]  Alessandro Panconesi,et al.  Concentration of Measure for the Analysis of Randomized Algorithms , 2009 .

[33]  Sebastian Wild,et al.  Average Case Analysis of Java 7's Dual Pivot Quicksort , 2012, ESA.

[34]  J. Ian Munro,et al.  Self-organizing binary search trees , 1976, 17th Annual Symposium on Foundations of Computer Science (sfcs 1976).

[35]  Julien Clément,et al.  Average depth in a binary search tree with repeated keys , 2006 .

[36]  Jyrki Katajainen,et al.  Stable minimum space partitioning in linear time , 1992, BIT.

[37]  C. McDiarmid Concentration , 1862, The Dental register.

[38]  Jon Louis Bentley,et al.  Engineering a sort function , 1993, Softw. Pract. Exp..

[39]  Sebastian Wild,et al.  Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Practical Potential , 2016 .