Landers / The Shape of Quicksort CostDownload PDFGitHub repository

Quicksort's Lognormal Fit and Non-Normal Limit

Jonathan R. Landers

September 2026

Abstract

Best-case, worst-case, and average-case analyses compress an algorithm’s behavior to a few numbers. Yet different inputs produce a distribution of costs, and that distribution has a shape even when its mean is known. We examine the number of comparisons made by classical randomized-pivot Quicksort. Two seemingly conflicting facts hold. For every n≥4n\ge4, the best ordinary lognormal fit has a strictly higher expected log-density than the best normal fit. Nevertheless, a fitted lognormal does not approach Quicksort’s standardized limiting distribution: the latter retains skewness 0.854881…0.854881\ldots, while the lognormal becomes asymptotically normal after standardization. We give a moment-based, computer-assisted proof of the finite-size inequality and a short argument for the limiting separation. The main text develops the questions and their interpretation; proofs and exact certificate details follow in the appendix.

Keywords: Quicksort; comparison count; runtime distribution; lognormal fit; expected log score.

Beyond three numbers of complexity

An algorithm does not have a single running cost at a fixed input size. It has a collection of possible costs, one for each input and, for randomized algorithms, each sequence of random choices. Best-case and worst-case bounds describe the extremes. Average-case analysis describes a center once a probability model has been chosen. None of these numbers, by itself, says how common the costs between the extremes are.

That missing shape can answer natural questions. Is a run moderately above average unusual? Is the long-cost side heavier than the short-cost side? If two algorithms have the same expected cost, does one vary more? Such questions call for the distribution of cost over the input and randomness space. The distribution contains the familiar summaries, but also records their arrangement: spread, asymmetry, and tails.

There are two ways to study that shape. At a given input size, one can ask which simple probability family describes the costs better. As the size grows, one can ask whether that family becomes the true limiting shape after removing the changing center and scale. A fit can win the first comparison without winning the second. Quicksort offers a clean example of this distinction.

A distribution generated by recursive splits

We count comparisons, rather than wall-clock time, to isolate the algorithm from machine effects. Consider nn distinct keys. At each recursive call, choose a pivot uniformly among the keys in that subproblem, compare it with the other keys, and recurse on the two sides. Let CnC_n be the total count. With C0=C1=0C_0=C_1=0, its distribution satisfies, for n≥2n\ge2,

Cn=dn−1+CIn+C′n−1−In,In∼Unif{0,…,n−1},C_n\ \overset d=\ n-1+C_{I_n}+C'_{n-1-I_n}, \qquad I_n\sim\operatorname{Unif}\{0,\ldots,n-1\}, \label{eq:rec}(1)

Here =d\overset d= means equality in distribution, InI_n is uniform on the displayed integers, and the prime denotes an independent recursive copy. The two recursive counts are independent conditional on InI_n. Equation (1) describes an entire distribution, not just an expected runtime. Balanced splits tend to save comparisons; repeated uneven splits increase the count.

For a small illustration, the full distribution at n=4n=4 is

comparisons cc 4 5 6
probability Pr(C4=c)\Pr(C_4=c) 1/21/2 1/61/6 1/31/3

Its best case is 44, worst case is 66, and mean is 29/629/6. The table says more: the middle cost is the least common of the three. For large nn, the support and probabilities are far richer, but the same recurrence determines them.

Write μn=𝔼Cn\mu_n=\mathbb EC_n, vn=Var(Cn)v_n=\operatorname{Var}(C_n), and mr,n=𝔼(Cn−μn)rm_{r,n}=\mathbb E(C_n-\mu_n)^r for the mean, variance, and rrth central moment; 𝔼\mathbb E and Var\operatorname{Var} denote expectation and variance. Every CnC_n with n≥2n\ge2 is strictly positive. Standard identities give [3, 2]

μn=2(n+1)Hn−4n,vn=7n2+13n−2(n+1)Hn−4(n+1)2Hn(2),\begin{aligned} \mu_n&=2(n+1)H_n-4n, \label{eq:mean}\\ v_n&=7n^2+13n-2(n+1)H_n-4(n+1)^2H_n^{(2)}, \label{eq:var}\end{aligned}(2)
(3)

where Hn(r)=∑j=1nj−rH_n^{(r)}=\sum_{j=1}^n j^{-r} and Hn=Hn(1)H_n=H_n^{(1)}. All logarithms below are natural unless a base is shown.

The mean grows like nlognn\log n, while the standard deviation grows like nn. Relative fluctuations shrink, even though the number of comparisons still varies substantially on the nn scale. This observation will matter for both results.

Result 1: a lognormal wins the finite-size fit

A histogram of comparison counts can look somewhat bell-shaped, but with a longer right side. It is therefore natural to compare a normal density with an ordinary lognormal density; the latter is the distribution of eGe^G for a Gaussian variable GG. We make the phrase better fit precise: for each family, choose the parameters maximizing the expected log-density at the actual comparison count. This is a population score under the exact distribution of CnC_n, not a judgment by eye or a fit to a simulated sample.

Let SN(X)S_N(X) and SL(X)S_L(X) denote the optimal expected log-densities for normal and ordinary lognormal families when X>0X>0. The normal optimum matches the mean and variance of XX; the lognormal optimum matches the mean and variance of logX\log X in log space. The exact score difference is

Δ(X)=SL(X)−SN(X)=12logVarXVar(logX)−𝔼logX.\Delta(X)=S_L(X)-S_N(X) =\frac12\log\!\frac{\operatorname{Var}X}{\operatorname{Var}(\log X)}-\mathbb E\log X. \label{eq:maingap}(4)

Positive Δ\Delta means that the lognormal assigns a higher expected log-density to the observed counts. Counts are discrete and these models continuous; evaluating both densities at the same count is a comparative score, not a claim that either density is the exact probability mass function.

Histograms of Quicksort comparison counts at n equals 64 and 256 with normal and lognormal fit curves
Figure 1. Comparison-count histograms from 30,000 independent randomized-pivot runs at each displayed size. The normal and ordinary lognormal curves maximize the log-density on each simulated sample. The sample mean log-density favors the lognormal by 0.04200.0420 at n=64n=64 and 0.02790.0279 at n=256n=256; the all-size claim below concerns the exact population score.
Δ(Cn)>0for every integer n≥4.\boxed{\quad\Delta(C_n)>0\quad\text{for every integer }n\ge4.\quad} \label{eq:mainfinite}(5)

In plain terms, this comparison has no later crossover: under this particular scoring rule, the best lognormal beats the best normal at every size from four onward. The statement is stronger than a histogram comparison at a few sizes. It has a specific scope: ordinary lognormal and normal densities optimized by expected log-density. A different criterion or a shifted lognormal is a different question.

The proof turns the fit comparison into a condition on the third and fourth central moments. A useful general criterion is

minX≥23𝔼Xand3(𝔼X)𝔼(X−𝔼X)3>4𝔼(X−𝔼X)4⇒Δ(X)>0.\min X\ge\frac23\mathbb EX \quad\text{and}\quad 3(\mathbb EX)\mathbb E(X-\mathbb EX)^3>4\mathbb E(X-\mathbb EX)^4 \quad\Longrightarrow\quad\Delta(X)>0. \label{eq:maincriterion}(6)

Here minX\min X is the smallest value in the support of XX (its essential infimum in general). The third-moment term captures rightward asymmetry; the fourth moment controls the error in approximating the logarithm. For Quicksort, exact rational interval checks establish both conditions for 4≤n<10,0004\le n<10{,}000. Uniform analytic bounds establish them for every n≥10,000n\ge10{,}000. Appendix A provides the proof and certificate details. The calculation uses published Quicksort moment identities [3]; the all-size fit inequality is obtained by combining them with (6).

Result 2: the fitted shape does not become exact

Winning a finite-size score comparison does not mean that Quicksort is becoming lognormal. To ask about its eventual shape, first remove the moving mean and scale:

Ĉn=Cn−μnvn.\widehat C_n=\frac{C_n-\mu_n}{\sqrt{v_n}}. \label{eq:mainstandard}(7)

The classical Quicksort limit theorem says that Ĉn\widehat C_n converges in distribution to a non-normal random variable QQ [1, 2]. In particular, the known moment formulas give its skewness as

skew(Q)=16ζ(3)−19(7−2π2/3)3/2=0.854881867….\operatorname{skew}(Q) =\frac{16\zeta(3)-19}{(7-2\pi^2/3)^{3/2}} =0.854881867\ldots. \label{eq:mainskew}(8)

Here skew(W)=𝔼(W−𝔼W)3/(VarW)3/2\operatorname{skew}(W)=\mathbb E(W-\mathbb EW)^3/(\operatorname{Var}W)^{3/2} for a variable WW with positive variance, and ζ(r)=∑j=1∞j−r\zeta(r)=\sum_{j=1}^{\infty}j^{-r} for r>1r>1. The positive constant says that the long right side survives the passage to large inputs.

Now let LnL_n be an ordinary lognormal with the same mean and variance as CnC_n. Its relative spread shrinks:

vnμn=Θ(1/logn)→0.\frac{\sqrt{v_n}}{\mu_n}=\Theta(1/\log n)\longrightarrow0. \label{eq:mainrelative}(9)

The Θ\Theta notation means that the ratio of the two positive quantities stays between fixed positive constants for all sufficiently large nn. When a lognormal becomes narrow relative to its mean, its centered and standardized shape tends to a normal. Its skewness therefore tends to zero, while Quicksort’s tends to the nonzero constant above. More precisely, with L̂n=(Ln−μn)/vn\widehat L_n=(L_n-\mu_n)/\sqrt{v_n},

Ĉn⇒Q,L̂n⇒𝒩(0,1).\widehat C_n\Rightarrow Q,\qquad \widehat L_n\Rightarrow\mathcal N(0,1). \label{eq:mainlimits}(10)

The arrow ⇒\Rightarrow denotes convergence in distribution, and 𝒩(0,1)\mathcal N(0,1) is the normal law with mean zero and variance one. The largest gap between their cumulative distribution functions (CDFs) has a positive limit:

limn→∞supx|Pr(Cn≤x)−Pr(Ln≤x)|=dK(ℒ(Q),𝒩(0,1))>0.\lim_{n\to\infty}\sup_x\left|\Pr(C_n\le x)-\Pr(L_n\le x)\right| =d_K\bigl(\mathcal L(Q),\mathcal N(0,1)\bigr)>0. \label{eq:mainkolm}(11)

Here ℒ(Q)\mathcal L(Q) is the law of QQ, and dK(A,B)d_K(A,B) is the supremum of the absolute difference between the CDFs of laws AA and BB; it is unchanged by applying the same increasing affine transformation to both laws. This is a precise sense in which the lognormal approximation never converges to the true standardized Quicksort shape. The log-score-optimal ordinary lognormal from Result 1 also has an asymptotically normal standardized shape. Appendix B proves these statements.

Quicksort and lognormal cumulative curves at n equals 256 and 4096, then their distinct limiting curves, with CDF gaps below
Figure 2. Standardized CDFs at two finite sizes and in the limit; the lower row shows Quicksort minus fitted-model CDF. Each finite Quicksort curve uses 30,000 independent runs, and each dashed curve is the ordinary lognormal with the exact Quicksort mean and variance. The limiting Quicksort curve approximates QQ by Monte Carlo iteration of its recursive fixed-point equation; its dashed counterpart is the standard normal CDF. The estimated limiting maximum gap is 0.0580.058, and Equation (11) proves it remains positive.

Putting the two statements together

The results describe two scales of one phenomenon. On the scale of the raw positive count, a mild right asymmetry helps a lognormal beat a symmetric normal in expected log-density. On the scale of fluctuations around the mean, random recursive splits keep an asymmetric limiting shape. A fitted lognormal becomes approximately normal on that standardized scale because its relative spread shrinks.

This distinction is useful beyond Quicksort. When an algorithm’s cost is summarized by a fitted curve, ask what the fitting rule measures and whether that curve also describes the cost after centering and scaling. A good score at every finite size and an incorrect limiting law can coexist. These results apply to the uniform-pivot comparison-count model in (1); other implementations and costs require their own analysis.

Proof of the finite-size fit result

For a positive random variable XX, let SN(X)S_N(X) and SL(X)S_L(X) be the suprema of 𝔼logf(X)\mathbb E\log f(X) over ordinary normal densities on ℝ\mathbb R and ordinary lognormal densities on (0,∞)(0,\infty), respectively. The normal optimizers are 𝔼X,VarX\mathbb EX,\operatorname{Var}X; the lognormal’s log-location and log-variance optimizers are 𝔼logX,Var(logX)\mathbb E\log X,\operatorname{Var}(\log X). Direct substitution gives the exact score gap

Δ(X):=SL(X)−SN(X)=12logVarXVar(logX)−𝔼logX.\Delta(X):=S_L(X)-S_N(X) =\frac12\log\frac{\operatorname{Var}X}{\operatorname{Var}(\log X)}-\mathbb E\log X. \label{eq:gap}(12)

The quantity is dimensionless: changing the unit of XX cancels between the two terms.

Lemma 1 (Moment criterion). Let X>0X>0, μ=𝔼X\mu=\mathbb EX, v=VarXv=\operatorname{Var}X, mr=𝔼(X−μ)rm_r=\mathbb E(X-\mu)^r, and minX≥2μ/3\min X\ge2\mu/3. If 3μm3>4m43\mu m_3>4m_4, then Δ(X)>0\Delta(X)>0.

Proof. Put Z=(X−μ)/μ≥−1/3Z=(X-\mu)/\mu\ge-1/3. The elementary inequality

log2(1+z)≤z2−z3+43z4(z≥−1/3)\log^2(1+z)\le z^2-z^3+\tfrac43z^4\quad(z\ge-1/3) \label{eq:loglemma}(13)

implies Var(logX)≤𝔼log2(1+Z)<𝔼Z2=v/μ2\operatorname{Var}(\log X)\le \mathbb E\log^2(1+Z)<\mathbb EZ^2=v/\mu^2. Also 𝔼log(1+Z)<log(1+𝔼Z)=0\mathbb E\log(1+Z)<\log(1+\mathbb EZ)=0 by strict Jensen. Replacing Var(logX)\operatorname{Var}(\log X) in (12) by its strict upper bound shows Δ(X)>0\Delta(X)>0.

For completeness, (13) follows by expanding log2(1+z)=∑k≥2(−1)k(2Hk−1/k)zk\log^2(1+z)=\sum_{k\ge2}(-1)^k(2H_{k-1}/k)z^k for |z|<1|z|<1. For 0≤z≤10\le z\le1 the alternating-series bound through degree four is z2−z3+(11/12)z4z^2-z^3+(11/12)z^4. For z≥1z\ge1, use log2(1+z)≤z2≤z2−z3+4z4/3\log^2(1+z)\le z^2\le z^2-z^3+4z^4/3. For z=−yz=-y with 0≤y≤1/30\le y\le1/3, the coefficients from degree five onward are at most 5/65/6, so their sum is bounded by (5/6)y5/(1−y)≤(5/12)y4(5/6)y^5/(1-y)\le(5/12)y^4. Adding the degree-four coefficient 11/1211/12 gives 4/34/3. ◻

Theorem 1 (Strict log-score advantage). For the count in (1), SL(Cn)>SN(Cn)S_L(C_n)>S_N(C_n) for every integer n≥4n\ge4.

Proof. We certify the two hypotheses of Lemma Lemma 1. A balanced recursion tree yields the exact minimum

bn=(n+1)h−2h+1+2,h=⌊log2n⌋.b_n=(n+1)h-2^{h+1}+2,\qquad h=\lfloor\log_2n\rfloor. \label{eq:min}(14)

The published third and fourth central-moment formulas [3, Thms. 2.3–2.4] determine m3,nm_{3,n} and m4,nm_{4,n} from Hn(1),…,Hn(4)H_n^{(1)},\ldots,H_n^{(4)}. Their third-moment expression, for example, is

m3,n=−n(19n2+81n+104)+14(n+1)Hn+12(n+1)2Hn(2)+16(n+1)3Hn(3).\begin{aligned} m_{3,n}={}&-n(19n^2+81n+104)+14(n+1)H_n\nonumber\\ &+12(n+1)^2H_n^{(2)}+16(n+1)^3H_n^{(3)}. \label{eq:m3}\end{aligned}(15)

For the 9,996 sizes 4≤n<10,0004\le n<10{,}000, the accompanying exact-rational certificate evaluates these formulas by outward intervals and verifies

3bn−2μn>0,3μnm3,n−4m4,n>0.3b_n-2\mu_n>0,\qquad 3\mu_nm_{3,n}-4m_{4,n}>0. \label{eq:checks}(16)

No simulations or floating-point sign tests enter the assertions. The computation independently checks the moment identities against the full recurrence (1) for n≤12n\le12. The certificate procedure is summarized below.

For n≥N=10,000n\ge N=10{,}000, the same inequalities admit uniform analytic bounds. Set t=N−1t=N^{-1} and u=1+tu=1+t. The harmonic tail estimates

ζ(r)−1(r−1)nr−1<Hn(r)<ζ(r)(r>1),\zeta(r)-\frac{1}{(r-1)n^{r-1}}<H_n^{(r)}<\zeta(r) \quad(r>1), \label{eq:tails}(17)

and Hn≤logn+1H_n\le\log n+1 imply Hn/n<11/NH_n/n<11/N: the function (logx+1)/x(\log x+1)/x decreases for x>1x>1 and logN<10\log N<10. From (15), dropping positive terms where helpful, one gets

m3,nn3>16ζ(3)−19−81t−104t2−8u3t2>1150.\frac{m_{3,n}}{n^3}>16\zeta(3)-19-81t-104t^2-8u^3t^2 >\frac{11}{50}. \label{eq:large3}(18)

Substitution into the fourth-moment formula and removal of its remaining negative terms gives

m4,nn4<22609+96589t+154979t2+113579t3−168(ζ(2)−t)+12u2(11t)2+48u3(11t)ζ(2)+48u4ζ(2)2−96(ζ(4)−t33)<1110.\begin{aligned} \frac{m_{4,n}}{n^4}<{}&\frac{2260}{9}+\frac{9658}{9}t+\frac{15497}{9}t^2+\frac{11357}{9}t^3 -168\bigl(\zeta(2)-t\bigr)\nonumber\\ &+12u^2(11t)^2+48u^3(11t)\zeta(2) +48u^4\zeta(2)^2\nonumber\\ &-96\left(\zeta(4)-\frac{t^3}{3}\right)<\frac{11}{10}. \label{eq:large4}\end{aligned}(19)

The last numerical inequalities use rational enclosing bounds 1.6449<ζ(2)<1.6451.6449<\zeta(2)<1.645, ζ(3)>1.202\zeta(3)>1.202, and ζ(4)>1.0823\zeta(4)>1.0823, each certified by integral remainders after 200 terms. Further, μn>14n\mu_n>14n, since Hn>logn>9H_n>\log n>9 for n≥Nn\ge N; hence 3μnm3,n>3(14n)(11n3/50)>4(11n4/10)>4m4,n3\mu_nm_{3,n}>3(14n)(11n^3/50)>4(11n^4/10)>4m_{4,n}.

Finally, (14) gives bn/n≥log2n−2b_n/n\ge\log_2n-2. Together with Hn≤logn+1H_n\le\log n+1 and n≥Nn\ge N, this implies bn≥2μn/3b_n\ge2\mu_n/3: after rearrangement it suffices that

(1log2−43)logn≥23+4(logn+1)3n,\left(\frac1{\log2}-\frac43\right)\log n \ge\frac23+\frac{4(\log n+1)}{3n}, \label{eq:minbound}(20)

which holds at NN and strengthens as nn grows. Thus Lemma Lemma 1 applies on the entire tail as well. ◻

Proof of the limiting separation

The advantage above might suggest that Quicksort becomes lognormal at large nn. Its standardized limit says otherwise. Let LnL_n be the ordinary lognormal with the same mean μn\mu_n and variance vnv_n as CnC_n, and put

Ĉn=(Cn−μn)/vn,L̂n=(Ln−μn)/vn.\widehat C_n=(C_n-\mu_n)/\sqrt{v_n},\qquad \widehat L_n=(L_n-\mu_n)/\sqrt{v_n}.

Theorem 2 (Asymptotic separation). The variables Ĉn\widehat C_n converge to Quicksort’s standardized limit QQ, whereas L̂n⇒𝒩(0,1)\widehat L_n\Rightarrow\mathcal N(0,1). In particular,

limn→∞skew(Cn)=16ζ(3)−19(7−2π2/3)3/2=0.854881867…,\lim_{n\to\infty}\operatorname{skew}(C_n) =\frac{16\zeta(3)-19}{(7-2\pi^2/3)^{3/2}} =0.854881867\ldots, \label{eq:skew}(21)
while skew(Ln)→0\operatorname{skew}(L_n)\to0. Moreover, for the CDFs,
limn→∞supx|Pr(Cn≤x)−Pr(Ln≤x)|=dK(ℒ(Q),𝒩(0,1))>0.\lim_{n\to\infty}\sup_x \bigl|\Pr(C_n\le x)-\Pr(L_n\le x)\bigr| =d_K(\mathcal L(Q),\mathcal N(0,1))>0. \label{eq:kolm}(22)
The same normal limiting shape holds for the ordinary lognormal optimized in Theorem Theorem 1, after standardization by its own mean and standard deviation.

Proof. The Quicksort limit theorem establishes (Cn−μn)/n⇒Y(C_n-\mu_n)/n\Rightarrow Y with a continuous limiting distribution [1, 2]; vn/n2→σ2=7−2π2/3>0v_n/n^2\to\sigma^2=7-2\pi^2/3>0 from (3). Its limiting third central moment follows from (15): m3,n/n3→16ζ(3)−19m_{3,n}/n^3\to16\zeta(3)-19. Consequently Q=Y/σQ=Y/\sigma has the nonzero skewness in (21); see also [3]. The notation an∼bna_n\sim b_n below means an/bn→1a_n/b_n\to1, and an=O(bn)a_n=O(b_n) means |an|/bn|a_n|/b_n stays bounded for positive bnb_n.

For the limiting curve in Figure 2, we approximate YY using its recursive characterization [1]:

Y=dUY1+(1−U)Y2+1+2UlogU+2(1−U)log(1−U),Y\overset d= UY_1+(1-U)Y_2+1+2U\log U+2(1-U)\log(1-U),

where UU is uniform on (0,1)(0,1) and Y1,Y2Y_1,Y_2 are independent copies of YY, independent of UU. The plotted variable is Q=Y/σQ=Y/\sigma; the accompanying make_figures.py uses 25 population iterations of 400,000 values.

For the moment-matched lognormal, its underlying Gaussian log-variance is sn2=log(1+vn/μn2)=O(1/log2n)s_n^2=\log(1+v_n/\mu_n^2)=O(1/\log^2 n), since μn∼2nlogn\mu_n\sim2n\log n and vn∼σ2n2v_n\sim\sigma^2n^2. Hence sn→0s_n\to0 and

L̂n=exp(snZ−sn2/2)−1exp(sn2)−1⇒Z,Z∼𝒩(0,1).\widehat L_n=\frac{\exp(s_nZ-s_n^2/2)-1}{\sqrt{\exp(s_n^2)-1}} \Rightarrow Z,\qquad Z\sim\mathcal N(0,1).

Its skewness (esn2+2)esn2−1(e^{s_n^2}+2)\sqrt{e^{s_n^2}-1} therefore vanishes. Nonzero skewness proves Q≠𝒩(0,1)Q\ne\mathcal N(0,1). Continuity of both limit CDFs makes each Kolmogorov convergence uniform, proving (22) by the triangle inequality.

For the log-score-optimal lognormal, the minimum bound in the preceding proof and the fourth-moment bounds yield a Taylor expansion of logCn\log C_n around μn\mu_n: Var(logCn)∼vn/μn2→0\operatorname{Var}(\log C_n)\sim v_n/\mu_n^2\to0. Its log-variance thus also tends to zero, giving the same standardized normal limit. ◻

Exact certificate specification

This appendix records enough detail to reproduce the finite interval computation without sampling. Define Hr=Hn(r)H_r=H_n^{(r)} and a=n+1a=n+1. The fourth central moment used in the test is the published formula [3]

m4,n=n(2260n3+9658n2+15497n+11357)9−2a(42n2+78n+77)H1+12a2H12+[−4a2(42n2+78n+31)+48a3H1]H2−96a3H3+48a4H22−96a4H4.\begin{aligned} m_{4,n}={}&\frac{n(2260n^3+9658n^2+15497n+11357)}9\\ &-2a(42n^2+78n+77)H_1+12a^2H_1^2\\ &+\bigl[-4a^2(42n^2+78n+31)+48a^3H_1\bigr]H_2\\ &-96a^3H_3+48a^4H_2^2-96a^4H_4.\end{aligned}

For each n=4,…,9999n=4,\ldots,9999, maintain four integer sums

Sr(n)=∑j=1n⌊D/jr⌋,D=1024,r=1,2,3,4.S_r(n)=\sum_{j=1}^{n}\lfloor D/j^r\rfloor,\qquad D=10^{24},\quad r=1,2,3,4.

Substitute [Sr(n)/D,(Sr(n)+n)/D][S_r(n)/D,(S_r(n)+n)/D] for HrH_r in (2), (15), and the expression above. Ordinary outward interval addition and multiplication produce intervals for μn,m3,n,m4,n\mu_n,m_{3,n},m_{4,n}. Assert that the lower endpoints of 3bn−2μn3b_n-2\mu_n and 3μnm3,n−4m4,n3\mu_nm_{3,n}-4m_{4,n} are strictly positive. The integer floor bound gives an interval containing each harmonic number, so a passing lower endpoint proves the corresponding exact inequality. The certificate reports 9,996 successful sizes; direct probability mass functions generated from (1) independently cross-check the moment formulas for 2≤n≤122\le n\le12.

For the tail constants, set M=200M=200 and Tr=∑j=1Mj−rT_r=\sum_{j=1}^{M}j^{-r}. Integral comparison supplies rational enclosures

Tr+1(r−1)(M+1)r−1<ζ(r)<Tr+1(r−1)Mr−1(r=2,3,4).T_r+\frac1{(r-1)(M+1)^{r-1}}<\zeta(r)<T_r+\frac1{(r-1)M^{r-1}}\qquad(r=2,3,4).

They imply 1.6449<ζ(2)<1.6451.6449<\zeta(2)<1.645, ζ(3)>1.202\zeta(3)>1.202, and ζ(4)>1.0823\zeta(4)>1.0823. Substituting these rational values into the right sides of (18) and (19), with t=10−4t=10^{-4}, yields respectively >0.2238>0.2238 and <1.0194<1.0194. These estimates are deliberately looser than necessary; the displayed proof only needs 0.220.22 and 1.11.1. In particular, the logN<10\log N<10 observation controls Hn/nH_n/n through monotonicity of (logn+1)/n(\log n+1)/n; it is not applied as the false statement logn<10\log n<10 for all n≥Nn\ge N.

The minimum comparison formula (14) follows from splitting as evenly as possible at every node. If n=2hqn=2^h q with 1≤q<21\le q<2, then bn/n≥h−2/qb_n/n\ge h-2/q. Since log2q+2/q≤2\log_2 q+2/q\le2 on [1,2][1,2], this implies bn/n≥log2n−2b_n/n\ge\log_2 n-2. This final elementary inequality makes the analytic tail independent of the finite certificate.

References

  1. U. Rösler. A limit theorem for “Quicksort.” RAIRO Theoretical Informatics and Applications, 25(1):85–100, 1991. https://www.numdam.org/item/ITA_1991__25_1_85_0/.

  2. J. A. Fill and S. Janson. Quicksort asymptotics. Journal of Algorithms, 44(1):4–28, 2002. https://arxiv.org/abs/math/0105248.

  3. Y. Yao. A detailed analysis of Quicksort algorithms with experimental mathematics. Manuscript, 2019. https://sites.math.rutgers.edu/~yao/QuickSort.pdf.