Abstract
We consider the standard Quicksort algorithm that sorts $n$ distinct keys with all possible $n!$ orderings of keys being equally likely. Equivalently, we analyze the total path length $L(n)$ in a randomly built binary search tree. Obtaining the limiting distribution of $L(n)$ is still an outstanding open problem. In this paper, we establish an integral equation for the probability density of the number of comparisons $L(n)$. Then, we investigate the large deviations of $L(n)$. We shall show that the left tail of the limiting distribution is much "thinner" (i.e., double exponential) than the right tail (which is only exponential). Our results contain some constants that must be determined numerically. We use formal asymptotic methods of applied mathematics such as the WKB method and matched asymptotics.
Introduction
Quicksort remains the most widely utilized sorting algorithm in computer science, yet the exact shape of its performance distribution—specifically the probability of the number of comparisons $L(n)$—remains a classic puzzle. While the average-case performance of $O(n \log n)$ and the worst-case $O(n^2)$ are well-documented in introductory texts, the "large deviations" (how the algorithm behaves when it performs significantly better or worse than average) have lacked precise definition. This paper addresses this gap by applying advanced mathematical tools from theoretical physics and fluid dynamics to the analysis of algorithms.
Methodology
To move beyond traditional combinatorics, this study employs formal asymptotic methods to treat the Quicksort recurrence. The approach is structured around four primary pillars:
- Generating Functions: The authors define a bivariate generating function for the number of comparisons, transforming the discrete recurrence relation into a partial-differential functional equation.
- The WKB Method: Borrowing the Wentzel–Kramers–Brillouin (WKB) method from quantum mechanics—typically used to approximate solutions to the Schrödinger equation—the authors approximate the solution to the algorithm's performance equations.
- Matched Asymptotics: The research analyzes the algorithm's behavior across different "regimes" (e.g., performance near the mean versus performance at the extremes). These solutions are then mathematically "stitched" together to provide a continuous asymptotic picture.
- Integral Equations: The study establishes a non-linear integral equation for the probability density of comparisons, providing a robust framework for calculating the distribution's shape.
Key Insights: The Asymmetry of Performance
The most striking finding of this research is the extreme asymmetry in Quicksort's performance distribution. The "tails" of the probability curve—representing exceptionally fast or exceptionally slow runs—behave in fundamentally different ways.
The "Thinner" Left Tail
The "left tail," representing the probability of the algorithm being significantly faster than average, is remarkably "thin." The authors prove that this probability decays double-exponentially. This implies that the odds of a "super-fast" run vanish almost instantly as one moves away from the mean, making such performance gains statistically much rarer than previously assumed.
The Exponential Right Tail
Conversely, the "right tail," representing the probability of a slow run, is only exponential. While a significantly slow run is still rare, it is mathematically much more likely than a "super-fast" run of the same magnitude. This quantitative asymmetry provides a new perspective on the reliability and predictability of the algorithm.
Theoretical Connections
The analysis further reveals a direct link between sorting efficiency and information theory. The leading term in the asymptotic expansion is shown to be related to the entropy of a Bernoulli distribution. This suggests that the limits of Quicksort's performance are deeply rooted in the fundamental limits of information processing.
Results and Formulas
The authors successfully derived explicit asymptotic formulas for both tails. For a deviation of size $ny$, the right tail behaves approximately like $e^{-yw}$, while the left tail behaves like $\exp(-\alpha e^{\beta - z})$. These results refine and extend previous estimates by researchers such as McDiarmid and Hayward, providing more precise constants for tail probabilities.
Furthermore, the derivation of a non-linear integral equation for the moment generating function of the limiting distribution serves as a foundational tool for future numerical studies. This equation allows for a more granular understanding of the distribution than was previously possible through discrete analysis.
Limitations and Future Directions
While the paper provides a significant advancement in the analysis of Quicksort, it acknowledges certain limitations:
- Formal vs. Rigorous: The methods are described as "formal," prioritizing the discovery of solutions over rigorous epsilon-delta proofs of error bounds.
- Numerical Constants: Several constants within the final formulas (such as $C$ and $\beta$) cannot be determined through analytical methods alone and require numerical simulation for precise values.
- The Worst-Case Boundary: The current analysis focuses on large deviations within a specific range and does not yet fully bridge the gap to the absolute $O(n^2)$ worst-case scenario.
By demonstrating that tools from wave propagation and quantum tunneling are effective in discrete algorithm analysis, this paper opens new avenues for the study of complex computational structures.
Summary updated