EXACT L 2 -DISTANCE FROM THE LIMIT FOR QUICKSORT KEY COMPARISONS EXTENDED ABSTRACT) arxiv:20.6445v [math.pr] 3 Ja 202 PATRICK BINDJEME JAMES ALLEN FILL Abstract Usigarecursiveapproach, weobtaiasimpleexactexpressioforthel 2 -distacefrom the limit i Régier s [5] classical limit theorem for the umber of key comparisos required by QuickSort. A previous study by Fill ad Jaso [] usig a similar approach foud that the d 2-distace is of order betwee log ad /2, ad aother by Neiiger ad Ruschedorf [4] foud that the Zolotarev ζ 3-distace is of exact order log. Our expressio reveals that the L 2 -distace is asymptotically equivalet to 2 l) /2.. Itroductio, review of related literature, ad summary We cosider Hoare s [3] QuickSort sortig algorithm applied to a ifiite stream of iid idepedet ad idetically distributed) uiform radom variables U,U 2,... QuickSortchoosesthe first key U as the pivot, compareseach of the other keys to it, ad the proceeds recursively to sort both the keys smaller tha the pivot ad those larger tha it. If, for example, the iitial roud of comparisos fids U 2 < U, the U 2 is used as the pivot i the recursive call to the algorithm that sorts the keys smaller tha U because it is the first elemet i the sequece U,U 2,... which is smaller tha U. I a atural ad obvious way, a realizatio requirig ifiite time) of the algorithm produces a ifiite rooted biary search tree which with probability oe has the completeess property that each ode has two child-odes. Essetially the same algorithm ca of course be applied to the trucated sequece U,U 2,...,U for ay fiite, where the recursio eds by declarig that a list of size 0 or is alreadysorted. Let K deote the umber of key comparisosrequired by QuickSort to sort U,U 2,...,U. The, with the way we have set thigs up, all the radom variables K are defied o a commo probability space, ad K is odecreasig i. Ideed, K K is simply the cost of isertig U ito the usual fiite) biary search tree formed from U,...,U. I this framework, Régier [5] used martigale techiques to establish the followig L p -limit theorem; she also proved almost sure covergece. We let µ : EK. Date: Jauary 26, 202. Research supported by the Acheso J. Duca Fud for the Advacemet of Research i Statistics.
2 PATRICK BINDJEME JAMES ALLEN FILL Theorem. Régier [5]). There exists a radom variable T satisfyig for every fiite p. Y : K µ L p T Rösler [6] characterized the distributio of Régier s limitig T as the uique fixed poit of a certai distributioal trasformatio, but he also described explicitly how to costruct a radom variable havig the same distributio as T. We will describe his explicit costructio i equivalet terms, but first we eed two paragraphs of otatio. The odes of the complete ifiite biary search tree are labeled i the atural biary way: the root gets a empty label writte ε here, the left respectively, right) child is labeled 0 resp., ), the left child of ode 0 is labeled 00, etc. We write Θ : 0 k< {0,} k for the set of all such labels. If V θ deotes the key iserted at odeθ Θ, let L θ resp.,r θ ) deote the largestkeysmallertha V θ resp., smallest key larger tha V θ ) iserted at ay acestor of θ, with the exceptios L θ : 0 ad R θ : if the specified acestor keys do ot exist. Further, for each ode θ, defie.) φ θ : R θ L θ, U θ : φ θ0 /φ θ, G θ : φ θ CU θ ) φ θ 2φ θ lφ θ +2φ θ0 lφ θ0 +2φ θ lφ θ, where for 0 < x < we defie.2) Cx) : +2xlx+2 x)l x). Let p <. The d p -metric is the metric o the space of all probability distributios with fiite pth absolute momet defied by d p F,F 2 ) : if X X 2 p, wherewetaketheifimum ofl p -distacesoverallpairsofradomvariablesx ad X 2 defied o the same probability space) with respective margial distributios F ad F 2. By the d p -distace betwee two radom variables we mea the d p - distace betwee their distributios. We are ow prepared to state Rösler s mai result. Note: Here ad later results have bee adjusted slightly as ecessary to utilize the same deomiator + rather tha ) that Régier used. Theorem.2 Rösler[6]). For ay fiite p, the ifiite series Y j0 θ j G θ coverges i L p, ad the sequece Y K µ )/) coverges i the d p -metric to Y. Of course it follows from Theorems..2 that T ad Y have the same distributio. The purpose of the preset exteded abstract is to show that i fact T Y ad to provide a simple explicit expressio for the L 2 -distace betwee Y ad Y valid for every ; this is doe i Theorem.4 below. We are aware of oly two previous studies of the rate of covergece of Y to Y, ad both of those cocer certai distaces betwee distributios rather tha betwee radom variables. The first study, by Fill ad Jaso [], provides upper ad lower bouds o d p Y,Y) for geeral p; we choose to focus here o d 2. Theorem.3 Fill ad Jaso []). There is a costat c > 0 such that for ay we have c l d 2 Y,Y) < 2 /2.
EXACT L 2 -DISTANCE FOR QUICKSORT KEY COMPARISONS 3 To our kowledge, the gap betwee the rates log)/ ad /2 has ot bee arrowed. Neiiger ad Ruschedorff [4] used the Zolotarev ζ 3 -metric ad foud that the correct rate i that metric is log, but their techiques are ot sufficietly sharp to obtai ζ 3 Y,Y) c l for some costat c. I our mai Theorem.4, proved usig the same recursive approach as i Fill ad Jaso [], we fid ot oly the lead-order asymptotics for the L 2 -distace Y Y 2, but i factaexactexpressioforgeeral. It isiterestigtootethat therate /2 log) /2 forl 2 -covergeceislargerevethatheupper-boudrate of /2 for d 2 -covergece from Theorem.3. Theorem.4 mai theorem). For 0 we have Y Y 2 2 ) 2H ++ 6 ) 4 k k 2 2 l +O ), where H : j is the th harmoic umber ad the asymptotic expressio holds as. The remaider of this exteded abstract is devoted to a proof of Theorem.4, which is completed i Sectio 5. 2. Prelimiaries I this sectio we provide recursive represetatios of Y for geeral ) ad Y that will be useful i provig Theorem.4. Our first propositio cocers the limit Y ad gives a sample-poitwise extesio of the very well kow [6] distributioal idetity satisfied by Y. Recall the otatio.) ad the defiitio of Y i Theorem.2 as the ifiite series j0 θ j G θ i L 2. Propositio 2.. There exist radom variables F θ ad H θ for θ Θ such that i) the joit distributios of G θ : θ Θ), of F θ : θ Θ), ad of H θ : θ Θ) agree; ii) F θ : θ Θ) ad H θ : θ Θ) are idepedet; iii) the series 2.) Y 0) : F θ ad Y ) : coverge i L 2 ; iv) the radom variables Y 0) ad Y ) are idepedet, each with the same distributio as Y, ad 2.2) Y CU)+UY 0) +UY ). Here U : U, with U : U, ad C is defied at.2). Proof. Recall from.) that G θ φ θ 2φ θ lφ θ +2φ θ0 lφ θ0 +2φ θ lφ θ. For θ Θ, defie the radom variable ϕ θ respectively, ψ θ ) by H θ ϕ θ : φ 0θ /U resp., ψ θ : φ θ /U).
4 PATRICK BINDJEME JAMES ALLEN FILL The U ad ϕ θ are idepedet resp., U ad ψ θ are idepedet), ϕ θ ad ψ θ each have the same distributio as φ θ, ad where G 0θ UF θ ad G θ UH θ, F θ : ϕ θ 2ϕ θ lϕ θ +2ϕ θ0 lϕ θ0 +2ϕ θ lϕ θ, H θ : ψ θ 2ψ θ lψ θ +2ψ θ0 lψ θ0 +2ψ θ lψ θ. The propositio follows easily from the clear equality of joit laws ad the fact that Y LF θ : θ Θ) LG θ : θ Θ) LH θ : θ Θ), G θ G ε + G 0θ + CU)+U F θ +U CU)+UY 0) +UY ). We ext proceed to provide a aalogue [amely, 2.4)] of 2.2) for each Y, rather tha Y, but first we eed a little more otatio. Give 0 x < y, let U xy ) be the subsequece of U ) that falls i x,y). The radom variable K x,y) is defied to be the radom) umber of key comparisos used to sort U xy,...,uxy usig QuickSort. The distributio of K x,y) of course does ot deped o x,y). We ow defie the radom variable H θ G θ 2.3) Y,θ : [K νθ )L θ,r θ ) µ νθ )]/[ν θ )+], with the ceterig here motivated by the fact that µ νθ ) is the coditioal expectatio of K νθ )L θ,r θ ) give ν θ ),L θ,r θ ). The for we have 2.4) Y C ν 0 )+)+ ν 0)+ Y,0 + ν )+ Y,, where, as i [2], for i we defie C i) : +µ i +µ i µ ). We ote for future referece that the classical divide-ad-coquer recurrece for µ asserts precisely that 2.5) for. C i) 0 i
EXACT L 2 -DISTANCE FOR QUICKSORT KEY COMPARISONS 5 It follows from 2.2) ad 2.4) that for we have [ [ ] ν0 )+ Y Y Y,0 UY ]+ 0) ν )+ Y, UY ) [ ] + C ν 0 )+) CU) 2.6) : W +W 2 +W 3. CoditioallygiveU adν 0 ), theradomvariablesw adw 2 areidepedet, each with vaishig mea, ad W 3 is costat. Hece E[Y Y) 2 U,ν 0 )] E[W 2 U,ν 0)]+E[W 2 2 U,ν 0)]+W 2 3 ad thus, takig expectatios ad usig symmetry, for we have 2.7) a 2 : EY Y) 2 EW 2 +EW 2 2 +EW 2 3 2EW 2 +EW 2 3. Note that 2.8) a 2 0 EY 2 : 7 2 3 π2 for example, [2]). 3. Aalysis of EW 2 I this sectio we aalyze EW 2, producig the followig result. Recall the defiitio of at 2.8). Propositio 3.. Let. For W defied as at 2.6), we have EW 2 ) 2 k +) 2 a 2 k + For that, we first prove the followig two lemmas. Lemma 3.2. For ay, we have [ ν0 ) 2 )+ 2] E Y,0 Y 0)) Lemma 3.3. For ay, we have [ ν0 ) 2 )+ 2] E U Y 0)) 6). ) 2 k + a 2 k. 6). Proof of Lemma 3.2. There is a probabilistic copy Y Y ) of the stochastic process Y ) such that Y,0 Y ν 0) ad Y ad Y 0) are idepedet of U,ν 0 )). This implies [ ν0 ) [ 2 ν0 )+ 2] E Y,0 Y 0)) ) ] 2 )+ E Yν Y0)) 2 0).
6 PATRICK BINDJEME JAMES ALLEN FILL By coditioig o ν 0 ), which is uiformly distributed o {0,..., }, we get [ ν0 ) [ 2 ν0 )+ 2] E Y,0 Y 0)) ) ] 2 )+ E a 2 ν 0) ) 2 k + a 2 k. Proof of Lemma 3.3. Coditioally give ν 0 ) ad Y 0), we have that U is distributed as the order statistic of rak ν 0 ) + from a sample of size from the uiform0,) distributio, amely, Betaν 0 )+, ν 0 )), with expectatio [ν 0 )+]/) ad variace [ν 0 )+) ν 0 ))]/[) 2 +2)]. So, usig also the idepedece of ν 0 ) ad Y 0), we fid [ ν0 ) 2 )+ 2] E U Y 0)) [ ν0 )+) ν 0 )) E ) 2 Y 0)) ] [ ] 2 ν0 )+) ν 0 )) E +2) ) 2 +2) ) 2 +2) 6). k +) k) Proof of Propositio 3.. We have [ ] 2 EW 2 ν0 )+ E Y,0 UY 0) [ ν0 )+ E Y,0 Y 0)) ν0 )+ + [ ν0 ) 2 )+ 2] E Y,0 Y 0)) [ ν0 ) ] 2 )+ +E U Y 0) ) 2 [ ν0 )+ +2E ) 2 +2) 6 )+2) ] 2 U )Y 0) Y,0 Y 0)) ] ν 0 )+ U )Y 0). The result follows from Lemmas 3.2 3.3, ad the fact that, coditioally give ν 0 ),Y,0,Y 0) ), the radom variable U is distributed Betaν 0 )+, ν 0 )), so that the last expectatio i the precedig equatio vaishes. 4. Aalysis of EW 2 3 I this sectio we aalyze EW 2 3, producig the followig result.
EXACT L 2 -DISTANCE FOR QUICKSORT KEY COMPARISONS 7 Propositio 4.. For ay we have b 2 : EW2 3 σ2 7 3 + 4 3 ) +2 H 2) + 4 3) 2H, where H j is the th harmoic umber ad H 2) : j 2 is the th harmoic umber of the secod order. For that, we first prove the followig two lemmas. Lemma 4.2. For ay k we have D,k) : Bk, k +) where B is the beta fuctio. Lemma 4.3. For ay we have 0 t k t) k lt)dt H k H, E[C ν 0 )+)CU)] E[C ν 0 )+)] 2. Proof of Lemma 4.2. The result ca be proved for each fixed by backwards iductio o k ad itegratio by parts, but we give a simpler proof. Recall the defiig expressio Bα,β) 0 t α t) β dt for the beta fuctio whe α,β > 0. Differetiatig with respect to α gives 0 t α t) β lt)dt Bα,β)[ψα) ψα+β)], where ψ is the classical digamma fuctio, i.e., the logarithmic derivative of the gamma fuctio. But it is well kow that ψj) H j for positive itegers j, so the lemma follows by settig α k ad β k +. Proof of Lemma 4.3. We kow that ν 0 )+ uif{,2,...,} ad that, coditioally give ν 0 ), the radom variable U has the Betaν 0 ) +, ν 0 )) distributio. So from Lemma 4.2, repeated use of 2.5), ad the very well kow ad easily derived explicit expressio µ 2)H 4, 0,
8 PATRICK BINDJEME JAMES ALLEN FILL we have E[C ν 0 )+)CU)] C j) Bj, j +) 0 t j t) j Ct)dt j C j)[+2 H j + j H )+2 H j+ H )] ) ) ) as desired. C j)[2jh j +2 j +)H j+ ] C j)[2jh j 4j )+2 j +)H j 4 j)] C j)[µ j +µ j ] ) C j)[µ j +µ j µ ] C j) 2 E[C ν 0 )+)] 2, Proof of Propositio 4.. It follows from Lemma 4.3 that ] 2 [ b 2 E C ν 0 )+) CU) ) 2 E[C ν 0 )+)] 2 2 ECU) 2 ) 2 E[C ν 0 )+)] 2. ) E[C ν 0 )+)CU)]+ECU) 2 Kowig that ECU) 2 /3, ad from the proof of Lemma A.5 i [2] that E[C ν 0 )+)] 2 ) 7 3 + 2 ) ) 4 3 + 2 + 2) H 4 3 3 H, we have as claimed. b 2 σ2 7 3 + 4 3 ) +2 H 2) 4 + 3) 2H, 5. A closed form for a 2 I this fial sectio we complete the proof of Theorem.4, for which we eed oe more lemma. Lemma 5.. For H 2) j 2, the th harmoic umber of the secod order, we have H 2) j )H 2) H for ay oegative iteger.
EXACT L 2 -DISTANCE FOR QUICKSORT KEY COMPARISONS 9 The lemma is well kow ad easily proved. Proof of mai Theorem.4. For we have from the decompositio 2.7) ad Propositios 3. ad 4. that a 2 2 ) 2 k +) 2 a 2 k + σ2 +2 3 ) 7 3 + 4 3 ) +2 H 2) + 4 3) 2H, ad we recall from 2.8) that a 2 0 σ2. Settig x : ) 2 a 2, we have x 0 ad x 2 x k +c for, with c : σ2 3 +2)) 7 3 )2 + 4 3 +2))H2) + 4 3 H. This is a stadard divide-ad-coquer recurrece relatio for x, with solutio [ ] x ) kc k k )c k +, 0. kk +) k After straightforward computatio ivolvig the idetity i Lemma 5., oe fids a 2 ) 2H ++ 6 ) + 7+4H 2) as claimed. ) 2H ++ 6 ) 4 Refereces k k 2 2 l ) +O, [] James Alle Fill ad Svate Jaso. Quicksort asymptotics. J. Algorithms, 44):4 28, 2002. Aalysis of algorithms. [2] James Alle Fill ad Svate Jaso. Quicksort Asymptotics : Appedix. Upublished, Available from http://www.ams.jhu.edu/~fill/, 2004. [3] C. A. R. Hoare. Quicksort. Comput. J., 5:0 5, 962. [4] Ralph Neiiger ad Ludger Rüschedorf. Rates of covergece for Quicksort. J. Algorithms, 44):5 62, 2002. Aalysis of algorithms. [5] M. Régier. A limitig distributio of Quicksort. RAIRO Iformatique Théorique et Applicatios, 23:335 343, 989. [6] U. Rösler. A limit theorem for Quicksort. RAIRO Iformatique Théorique et Applicatios, 25:85 00, 99. Departmet of Applied Mathematics ad Statistics, The Johs Hopkis Uiversity, 34th ad Charles Streets, Baltimore, MD 228-2682 USA E-mail address: bidjeme@ams.jhu.edu ad jimfill@jhu.edu