English

Quicksort Is Optimal For Many Equal Keys

Data Structures and Algorithms 2019-05-07 v4 Probability

Abstract

I prove that the average number of comparisons for median-of-kk Quicksort (with fat-pivot a.k.a. three-way partitioning) is asymptotically only a constant αk\alpha_k times worse than the lower bound for sorting random multisets with Ω(nε)\Omega(n^\varepsilon) duplicates of each value (for any ε>0\varepsilon>0). The constant is αk=ln(2)/(Hk+1H(k+1)/2)\alpha_k = \ln(2) / \bigl(H_{k+1}-H_{(k+1)/2} \bigr), which converges to 1 as kk\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.

Keywords

Cite

@article{arxiv.1608.04906,
  title  = {Quicksort Is Optimal For Many Equal Keys},
  author = {Sebastian Wild},
  journal= {arXiv preprint arXiv:1608.04906},
  year   = {2019}
}

Comments

v4 is a major reorganization of sections; a shortened version appears in the proceedings of ANALCO 2018

R2 v1 2026-06-22T15:22:03.575Z