Skip to main content
QUICK REVIEW

[Paper Review] A Detailed Analysis of Quicksort Running Time

Shalosh B. Ekhad, Doron Zeilberger|arXiv (Cornell University)|Mar 9, 2019
Algorithms and Data CompressionComputer Science5 references3 citations
TL;DR

This paper presents a symbolic computation approach to derive exact closed-form expressions for the expected number of comparisons and higher moments (mean, variance, skewness, kurtosis) in Quicksort's running time using generating functions and automated guessing. It leverages computer algebra to compute exact moment polynomials in terms of harmonic numbers, enabling precise approximation of Quicksort's distribution and performance limits beyond traditional asymptotic analysis.

ABSTRACT

One of the greatest algorithms of all time is Quicksort. Its average running time is famously O(nlog(n)), and its variance, less famously, is O(n^2) (hence its standard deviation is O(n)). But what about higher moments? Here we find explicit expressions for the first eight moments, their scaled limits, and we describe how to compute, approximately (but very accurately), percentiles of running time for any list-length

Motivation & Objective

  • To derive exact closed-form expressions for the expected number of comparisons in Quicksort using symbolic computation.
  • To compute higher-order moments (variance, skewness, kurtosis) of Quicksort's running time distribution.
  • To approximate the limiting distribution of Quicksort's comparison count using high-precision symbolic computation.
  • To demonstrate the power of experimental mathematics in algorithm analysis, replacing ad-hoc derivations with automated, data-driven guessing and verification.

Proposed method

  • Formulate a recurrence for the expected number of comparisons, $ c_n $, based on pivot selection and partitioning.
  • Use the probability generating function $ g_n(t) $ to model the distribution of comparisons and derive a non-linear recurrence.
  • Apply symbolic computation to compute $ g_n(t) $ exactly for $ n \leq 130 $, using rational arithmetic to avoid floating-point errors.
  • Extract factorial moments from $ g_n(1+w) $, truncated to desired order, to compute raw and central moments.
  • Use automated guessing to conjecture polynomial expressions for moments $ m_r(n) $ in terms of $ n $ and generalized harmonic numbers $ H_m(n) $.
  • Verify conjectures by testing against extensive numerical data and use rigorous proof tools when needed.

Experimental results

Research questions

  • RQ1What is the exact closed-form expression for the expected number of comparisons in Quicksort on a random input of size $ n $?
  • RQ2Can higher-order moments (variance, skewness, kurtosis) of Quicksort's running time be expressed in closed form?
  • RQ3What is the limiting distribution of the normalized comparison count $ Z_n = (X_n - c_n)/\sqrt{m_2(n)} $ as $ n \to \infty $?
  • RQ4How can symbolic computation and automated guessing replace traditional human-driven derivations in algorithm analysis?

Key findings

  • The expected number of comparisons $ c_n $ in Quicksort is exactly expressible as a polynomial in $ n $ and harmonic numbers $ H_1(n) $, with $ c_n = 2(n+1)H_n - 3n $.
  • The variance $ m_2(n) $ of the comparison count is also exactly expressible as a polynomial in $ n $ and $ H_1(n), H_2(n) $, with $ m_2(n) = \frac{1}{2}(n+1)(11H_n - 11H_{n+1} - 1) $.
  • The third through eighth standardized moments of the comparison count distribution were computed exactly, with values approximately $ [0.855, 4.178, 10.646, 44.427, 179.722, 858.203] $.
  • The limiting distribution of the normalized comparison count $ Z_n $ converges to a distribution approximated by $ Z_{130} $, with high accuracy for large $ n $.
  • The method enables precise approximation of tail probabilities, such as the likelihood that Quicksort exceeds a given number of comparisons for $ n = 10000 $.
  • The approach demonstrates that symbolic computation and automated guessing can replace complex human derivations, offering exact results and high-precision approximations.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.