THE ANALYSIS OF RANGE QUICKSELECT AND RELATED PROBLEMS

Size: px
Start display at page:

Download "THE ANALYSIS OF RANGE QUICKSELECT AND RELATED PROBLEMS"

Transcription

1 THE ANALYSIS OF RANGE QUICKSELECT AND RELATED PROBLEMS CONRADO MARTÍNEZ, ALOIS PANHOLZER, AND HELMUT PRODINGER ABSTRACT. Rage Quickselect, a simple modificatio of the well kow Quickselect algorithm for selectio, ca be used to efficietly fid a elemet with rak k i a give rage [i..j], out of give elemets. We study basic cost measures of Rage Quickselect by computig exact ad asymptotic results for the expected umber of passes, comparisos ad data moves durig the executio of this algorithm. The key elemet appearig i the aalysis of Rage Quickselect is a trivariate recurrece that we solve i full geerality. The geeral solutio of the recurrece proves to be very useful, as it allows us to tackle several related problems, besides the aalysis that origially motivated us. I particular, we have bee able to carry out a precise aalysis of the expected umber of moves of the pth elemet whe selectig the jth smallest elemet with stadard Quickselect, where we are able to give both exact ad asymptotic results. Moreover, we ca apply our geeral results to obtai exact ad asymptotic results for several parameters i biary search trees, amely the expected umber of commo acestors of the odes with rak i ad j, the expected size of the subtree rooted at the least commo acestor of the odes with rak i ad j, ad the expected distace betwee the odes of raks i ad j.. INTRODUCTION Quickselect, also called Hoare s FIND algorithm, is a very flexible ad easy to implemet recursive algorithm to fid the elemet of give rak k (i. e., the kth smallest elemet i a give data array A[..] of legth. The Quickselect algorithm uses partitioig of the array ito two subarrays aroud a pivot elemet, as i the popular Quicksort, also by C. A. R. Hoare [5, 6]. The behavior of fudametal quatities like the umber of comparisos betwee data elemets ad the umber of passes (recursive calls of the algorithm i Quickselect has bee extesively studied, see, for istace [4, 8, 0, 4] ad refereces therei. These quatities have also bee studied for may variats of the stadard algorithm, for example, for the media-of-three partitioig scheme [9]. I the preset work we cosider a variat of Quickselect, that we have dubbed Rage Quickselect, which receives as iput the data array ad a rage [i..j]. Its goal is to fid a elemet whose rak falls i the give rage. The aalysis of Rage Quickselect poses several quite atural questios related to the Quickselect algorithm that do ot seem to have bee treated up to ow. Rage Quickselect (RQS, for short is useful whe we are ot ecessarily iterested i a exact order statistic, but some order statistic withi a rage [i..j] of raks. For example, istead of fidig 2000 Mathematics Subject Classificatio. 05A5, 68P0, 68W40. Key words ad phrases. Quickselect, Hoare s Fid, moves, Rage Quickselect, biary search trees, average-case aalysis. This work was supported by the Spaish-Austria research agreemet Accioes Itegradas, grat ES 0/2008 ad by the Spaish-South Africa research agreemet Accioes Itegradas, grat HS The first author was supported by the Spaish Mi. of Sciece ad Techology, project TIN (ALINEX. The secod author was supported by the Austria Sciece Foudatio FWF, grat S9608. The third author was supported by the South Africa Sciece Foudatio NRF, grat This research was also supported by the Ceter for Mathematical Research (CRM, Bellaterra, Spai, while the first ad the third authors held research visitig positios there.

2 2 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER the exact media we could be cotet with a elemet whose rak is, say, betwee 0.48 ad This relaxatio of the Quickselect algorithm will lead, depedig o the rage [i..j], to a reductio of the umber of passes ad of the umber of comparisos betwee elemets i the array durig the executio, ad thus will lead to a faster executio time. We compute the exact average umber of passes ad the exact average umber of comparisos betwee elemets whe executig RQS ad as a cosequece we ca give results quatifyig the average amout of savigs compared to stadard Quickselect. I particular, give some measure of performace X, we compare the differece betwee X,i, the average value of X correspodig to Quickselect whe give a iput of size ad lookig for the ith smallest elemet, ad X,i d,i+d, the average value of X correspodig to Rage Quickselect whe give a iput of size ad lookig for a elemet whose rak falls i the rage [i d, i + d]. The asymptotic behavior of that differece i terms of ad d provides a clear picture of the beefits of Rage Quickselect ad the trade-off betwee speed ad accuracy. The descriptio of the algorithm ad the aalysis of the expected behavior of its fudametal performace characteristics form the core of Sectio 2. The aalysis of Rage Quickselect ivolves the solutio of trivariate recurreces which we have bee able to solve i full geerality. The result (Theorem 2 that we obtai i Subsectio 2.3 turs out be very useful i the aalysis of other iterestig parameters, icludig the umber of moves of a particular elemet durig the executio of the stadard Quickselect algorithm ad the total umber of moves made durig the executio of Rage Quickselect. I particular, we give exact results for the average umber of moves of the elemet with rak p made while selectig the jth smallest elemet out of, ad also for the average total umber of moves durig the executio of the Rage Quickselect algorithm, whe fidig a elemet with rak k [i..j] out of (Sectio 3. These parameters give a further isight ito the fuctioality of the Quickselect algorithms ad moreover, sice moves of elemets correspod to variable assigmets i the algorithm, these quatities appear whe measurig the total cost of the Quickselect algorithms. We also wat to metio here two recet related studies, oe about the umber of moves of particular elemets i the Quicksort sortig algorithm [8] ad the other o the total umber of moves i Quickselect, but for a radomly chose rak [3]. The close coectio betwee Quickselect ad radom biary search trees surfaces also i this paper, like i may previous works of the area (see, for istace [7]. We establish i Sectio 4 the relatio betwee Rage Quickselect ad several parameters i radom biary search trees that ivolve two give odes. We study the average umber of commo acestors of the odes with raks i ad j, the average size of the subtree rooted at the least commo acestor of the odes with raks i ad j, ad the average distace (umber of edges from the ode of rak i to the ode of rak j. Despite these results ca be obtaied (ad have bee obtaied by other meas, we show that all of them follow from direct applicatio of Theorem 2. This is a further example of the geerality ad usefuless of this tool, which qualifies as oe of the importat cotributios of this paper. We shall isist here that i this paper we restrict our aalysis to the expected value of the quatities cosidered. I all cases, we shall cosider that the iput is a array of distict elemets, the! possible orderigs take equally likely. This assumptio is stadard i the probabilistic aalysis of compariso-based sortig ad selectio algorithms (see, for istace, []. Furthermore, the assumptio that the iput is a radom permutatio ca be removed if we cosider that the pivot of each recursive stage is picked uiformly at radom amog the elemets of the curret subarray. Ideed, whatever the iitial permutatio is, if we pick pivots at radom the the probability that we choose the kth smallest elemet out of N is /N for all k, k N. Whe we assume that the source of radomess comes from the algorithm itself, expectatios are with respect the radom choices made

3 ANALYSIS OF RANGE QUICKSELECT 3 by the algorithm, ot by assumig ay particular distributio o the iputs. Both approaches yield the same results, but we will talk i terms of the radom permutatio model for the rest of the article. It is also worth metioig that, apart from the study of the umber of moves of a particular elemet i Quickselect where depedecies betwee the quatities appearig i the recursive descriptio occur (see Sectio 3, our aalysis could, at least i priciple, be exteded to higher momets, most otably to the secod momet ad thus to the variace, although the computatioal effort would be cosiderable (see, for istace [8]. We coclude this sectio with a few remarks cocerig otatios used i this paper. We use Iverso s bracket otatio [Q] for a statemet Q: [Q] = if Q is true ad [Q] = 0 otherwise [3]. The harmoic umbers are always deoted by H := k, for a positive iteger. Moreover, the radom variable E always deotes the idicator fuctio of the evet E, which gives the value whe E occurs ad gives the value 0 otherwise. Throughout this paper we use for all quatities cosidered a calligraphic letter as P, C, etc. to deote radom variables, whereas the correspodig ordiary letters deote their expectatios, e. g., P = E (P. 2. RANGE QUICKSELECT 2.. The algorithm. We begi with a descriptio of the stadard Quickselect algorithm for selectio. The call QUICKSELECT(A, j, l, r will fid the (j l + th smallest elemet amogst all elemets i the array A[l..r], with l j r. I full rigor, the algorithm will retur a elemet x of A[l..r] such that there are at least j l + elemets i the subarray which are less or equal to x. To have a eat defiitio of rak, we shall assume that the give elemets are distict. This will simplify the discussio about the algorithms ad their correctess alog the paper, ad it is also essetial for our aalysis, as we have already poited out i the itroductio After executig this algorithm, it holds that A[j] stores the elemet of the desired rak j l + i A[l..r]; i particular, the iitial call QUICKSELECT(A, j,, will brig the jth smallest elemet of A[..] to A[j]. Moreover, the algorithm rearrages the cotets of the array i such a way that it holds that A[m] A[j], for all l m < j, ad A[j] A[m], for all j < m r. If r l, the subarray cotais at most oe elemet, ad the problem is trivially solved, sice A[l] must cotai the sought elemet. Whe l < r, we perform a partitioig phase, i which oe of the elemets i the array, say A[l], is chose as a pivot elemet. By comparig this pivot elemet v with all remaiig elemets i the array ad iterchagig elemets, the pivot elemet will be brought to its correct positio i the array, say A[k], such that all elemets i the array A[l..k ] are smaller tha or equal to v = A[k] ad all elemets i the array A[k +..r] are larger tha or equal to v. The partitioig algorithm is give i full detail i Subsectio 3., whe we aalyze the umber of moves carried out by Quickselect ad Rage Quickselect. For the time beig, it is eough to ote that the partitioig algorithm will make exactly = r l comparisos betwee the pivot ad the remaiig elemets i the (subarray of size ; moreover, if the subarray cotais a radom permutatio of elemets, the two subarrays that we obtai after partitioig are radom permutatios too. After the partitioig phase, three cases ca occur: ( if j = k we kow the that v = A[k] = A[j] is the (j l + th smallest elemet i A[l..r] ad the algorithm termiates, (2 if j < k we kow that the required elemet is cotaied i the left subarray ad we proceed by searchig for the (j l +th smallest elemet i the array A[l..k ] with a recursive call of Quickselect, ad (3 if j > k we kow that the required elemet is cotaied i the right subarray ad we proceed by searchig for the Both stadard Quickselect ad Rage Quickselect work correctly i the presece of repeated elemets; they retur a elemet such that there are at least some umber, say k, of elemets smaller or equal to it.

4 4 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER (j kth smallest elemet i the array A[k +..r], agai with a recursive call of Quickselect. The algorithm is detailed as Algorithm. Algorithm The Quickselect algorithm Require: array A[l..r], iteger j with l j r Esure: Returs j, A[j] cotais the (j l + th smallest elemet i the array A[l..r] procedure QUICKSELECT(A, j, l, r if r l the retur l ed if PARTITION(A, l, r, k m : (l m < k A[m] A[k], ad m : (k < m r A[k] A[m] if j < k the retur QUICKSELECT(A, j, l, k else if j > k the retur QUICKSELECT(A, j, k +, r else retur k ed if ed procedure Two simple modificatios of the Quickselect algorithm allow us to solve the problem of rage selectio. Rage Quickselect is give the array A, the lower ad upper idices l ad r that delimit the subarray that cotais the elemets of iterest, ad the values i ad j that specify a rage of raks. The call RQS(A, i, j, l, r returs a value k such that the elemet at A[k] has a rak betwee i l + ad j l + amogst all elemets i the array A[l..r], for l i j r. A call to RQS(A, i, j,, returs a value k such that A[k] has a rak k [i..j] amog the elemets i A[..]. Like i Quickselect, it also holds that A[m] A[k], for all l m < k, ad that A[k] A[m], for all k < m r. Compared to the stadard Quickselect algorithm we eed oly to make the followig two modificatios. First, we stop if j i r l, sice the subarray cotais elemets whose raks are betwee i ad j ad ay of them will do 2. The other modificatio comes after the partitioig phase, that is, after the pivot elemet v is brought to its correct positio A[k] i the array, with all elemets i the array A[l..k ] smaller tha or equal to v = A[k] ad all elemets i the array A[k +..r] larger tha or equal to v. We have three cases: ( if i k j the pivot has a rak i the rage [i l +..j l + ] ad we ca retur k ad termiate the algorithm, (2 if j < k we kow that each elemet of iterest is cotaied i the left subarray ad we cotiue with the selectio of a elemet with a rak betwee i l + ad j l + i the array A[l..k ] by makig a recursive call of Rage Quickselect o A[i..k ], ad (3 if i > k we kow that each elemet of iterest is cotaied i the right subarray ad we recursively proceed lookig for a elemet with a rak betwee i k ad j k i the array A[k +..r]. A implemetatio of this algorithm is give as Algorithm The umber of passes. We start our aalysis of Rage Quickselect with the average behavior of the radom variable P,i,j which couts the umber of passes, i. e., (recursive calls, of the algorithm RQS util a elemet with a rak betwee i ad j is foud i a array A[..]. Here, ad for the rest of the paper, as we have already discussed i the itroductio, we assume that the array cotais a radom permutatio of distict elemets. We also assume that we choose the first elemet of the curret subarray as the pivot of each recursive stage. 2 Equivaletly, we stop if i l ad r j.

5 Algorithm 2 The Rage Quickselect algorithm ANALYSIS OF RANGE QUICKSELECT 5 Require: Array A[l..r], itegers i ad j with l i j r Esure: Returs k, with i k j, A[k] has rak betwee i l + ad j l + i the array A[l..r] procedure RQS(A, i, j, l, r if r l j i the retur l ed if PARTITION(A, l, r, k m : (l m < k A[m] A[k], ad m : (k < m r A[k] A[m] if j < k the retur RQS(A, i, j, l, k else if i > k the retur RQS(A, i, j, k +, r else retur k ed if ed procedure Theorem. The expected umber of passes P,i,j = E (P,i,j of the algorithm Rage Quickselect util a elemet with a rak betwee i ad j is foud i a array of elemets is P,i,j = H j + H i+ 2H j i+ +, for i j = log j + log( i + 2 log(j i + + O(. The asymptotic estimate give holds uiformly for i j ad. Whe i = j the formula yields the well kow average umber of passes of Quickselect (see, for istace, [7]: P,j,j = H j + H j+, for j. I order to show this theorem we start with a recursive descriptio of P,i,j. Sice we assume that the iput is a radom permutatio of size we get that the probability that the pivot elemet v = A[] is the kth smallest elemet i the array is / for all k, k. After the partitioig phase the left subarray A[..k ] ad the right subarray A[k +..] cotai radom permutatios of legths k ad k, respectively. If i k j the algorithm termiates ad we oly have to cout the origial call to RQS. If k < i we proceed with a recursive call of RQS for the right subarray ad if k > j we proceed with a recursive call of RQS for the left subarray. I these latter cases we have to add the umber of calls of RQS occurrig therei to the origial call. These cosideratios immediately lead to the followig propositio (see for istace [4, 20] ad refereces therei for backgroud o distributioal recurreces like the oe below. Propositio. The radom variable P,i,j satisfies the followig distributioal recurrece: (d P,i,j = + U<i P ( U,i U,j U + U>j P (2 U,i,j, for i j, ad P,i,j = 0, if i < or j < i or j >, where the rak U of the pivot elemet is uiformly distributed o {, 2,..., } ad it is idepedet of (P,i,j,i,j, (P (,i,j,i,j ad (P (2,i,j,i,j; furthermore (P (,i,j,i,j ad (P (2,i,j,i,j are idepedet copies of (P,i,j,i,j. Propositio immediately leads to the followig recurrece for the expectatio P,i,j of the umber of passes: P,i,j = + i P k,i k,j k + P k,i,j, for i j, (

6 6 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER ad P,i,j = 0, if i < or j < i or j >. It is ot difficult to show by iductio that the closed form for P,i,j give i Theorem is ideed the solutio of the recurrece above. This recurrece ad other that we will fid later ca i priciple be solved usig more or less stadard techiques i a ad-hoc fashio; however, the details of the derivatio are already cumbersome for ( ad they get eve worse whe we have to deal with more complicated recurreces. Therefore, we will take a detour i the ext sectio, where we will ivestigate the geeral solutio of trivariate recurreces whose shape is that of (, but with a geeric o-recursive cost T,i,j. With this systematic ad geeral approach the solutio of ( will be the a by-product of the mai result i the ext subsectio (Theorem 2. We will eed oly to set T,i,j = ad apply the theorem. The rewards of this geeral aalysis will be maifest soo afterwards, whe we use Theorem 2 to obtai the expected umber of comparisos of Rage Quickselect (Subsectio 2.4, later i Sectio 3 whe we aalyze the umber of moves of particular elemets made by Quickselect ad the total umber of moves made by Rage Quickselect, ad fially, i Sectio 4 whe we ivestigate several parameters of radom biary search trees Solvig a trivariate recurrece. We cosider the followig recurrece for umbers X,i,j, which appears i our studies of the Quickselect ad Rage Quickselect algorithms, ad later for biary search trees: X,i,j = i X k,i k,j k + X k,i,j + T,i,j, for i j. (2 Furthermore we defie X,i,j = 0, if i < or j < i or < j. For the toll fuctio T,i,j we also defie T,i,j = 0, if i < or j < i or < j. We remark that (2 is a geeralizatio of the ordiary Quickselect recurrece which appears whe studyig the momets of the umber of comparisos ad passes of Quickselect to select the jth smallest elemet i a array of size. Ideed, the ordiary Quickselect recurrece is the special istace of (2 where i = j. The ordiary Quickselect recurrece was first studied by Kuth [0]; a exact solutio for arbitrary toll fuctios has bee give by Kuba i [2]. To treat recurrece (2 we itroduce the followig trivariate geeratig fuctios: X(z, u, u 2 := X,i,j z u i u j 2, i j i j T (z, u, u 2 := T,i,j z u i u j 2. i j i j Multiplyig (2 by z u i uj 2 ad summig up for all values i j leads, after straightforward computatios, to the followig differetial equatio for the geeratig fuctio X(z, u, u 2 : ( z X(z, u, u 2 = z + u u 2 X(z, u, u 2 + zu u 2 z T (z, u, u 2, with iitial coditio X(0, u, u 2 = 0. The solutio of this first order liear differetial equatio, which ca be obtaied by stadard techiques, is: X(z, u, u 2 = ( z( zu u 2 z 0 ( t( u u 2 t( t T (t, u, u 2 dt. (3

7 ANALYSIS OF RANGE QUICKSELECT 7 The umbers X,i,j ca the be obtaied by extractig coefficiets from the solutio (3. By takig ito accout that T,i,j = [z u i uj 2 ]T (z, u, u 2 = 0, if i < or j < i or < j, we get the, for i j : X,i,j = [z u i u j 2 ]X(z, u, u 2 i = [z l u i l u j l 2 ] z = = = l=0 i l l=0 k=j l i l l=0 k=j l i l l=0 k=j l l= k=j i+l [z k u i l z u j l 2 ] 0 z 0 ( t( u u 2 t( t T (t, u, u 2 dt ( t( u u 2 t( t T (t, u, u 2 dt k [zk u i l u j l 2 ]( z( u u 2 z z T (z, u, u 2 ( kt k,i l,j l (k T k,i l,j l (k T k,i l,j l k + (k 2T k 2,i l,j l. The expressio ca be simplified easily by straightforward maipulatios, thus [ i i+l kt k,l,j i+l (k T k,l,j i+l X,i,j = k = = = i i+l l= k=j i+l i i+l+ l= k=j i+l+ i i+l l= k=j i+l i i i+l l= k=j i+l i+l l= k=j i+l Further simplificatios yield X,i,j = i i+l l= k=j i+l (k T k,l,j i+l (k 2T k 2,l,j i+l k kt k,l,j i+l (k T k,l,j i+l k (k T k,l,j i+l (k 2T k 2,l,j i+l k kt k,l,j i+l (k T k,l,j i+l k kt k,l,j i+l (k T k,l,j i+l k + kt k,l,j i+l (k T k,l,j i+l k(k + kt k,l,j i+l k(k + i i+l l= k=j i+l + k=j kt k,l,j i+l (k + (k ] kt k,i,j (k T k,i,j. k k=j kt k,i,j k k=j kt k,i,j k +

8 8 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER i = i+l l= k=j i+l i 2T k,l,j i+l (k + (k l= We collect our results i the followig theorem. T i+l,l,j i+l i + l + + k=j T k,i,j k + + T,i,j. Theorem 2. Let the sequece of umbers X,i,j, for i j, satisfy the followig recurrece: X,i,j = i X k,i k,j k + X k,i,j + T,i,j, with T,i,j, i j, a arbitrary sequece, such that T,i,j = 0 if i <, j < i or < j. The X,i,j, for i j, is give by the explicit formula i X,i,j = i+l l= k=j i+l i 2T k,l,j i+l (k + (k l= T i+l,l,j i+l i + l + + k=j T k,i,j k + + T,i,j. We remark that settig i = j above gives a exact solutio of the geeric Quickselect recurrece. The solutio thus obtaied is slightly differet from the oe give i [2] ad it is stated i the followig corollary. Corollary. Let the sequece of umbers X,j, for j, satisfy the followig recurrece: j X,j = X k,j k + X k,j + T,j, (4 with T,j, j, a arbitrary sequece such that T,j = 0 if j < or < j. The X,j, for j, is give by the explicit formula j X,j = l= j+l k=l j 2T k,l (k + (k l= T j+l,l, j + l + + k=j T k,j k + + T,j. Recurrece ( studied i Subsectio 2.2 is the istace of recurrece (2 for the particular toll fuctio T,i,j =, i j. We ca the obtai the exact solutio of ( applyig Theorem 2, which gives after easy summatios: i P,i,j = i+l l= k=j i+l i = l= k=j i+l i = l= This proves Theorem. i+l ( 2 i 2 (k + (k l= i + l + + k=j k + + ( 2 k + + H H i+ + H H j + k + 2 j i + l + i + l + = H j + H i+ 2H j i+ +, for i j. + 2H H i+ H j +

9 ANALYSIS OF RANGE QUICKSELECT The umber of comparisos. Next we study the average behavior of the radom variable C,i,j, with i j, which couts the umber of comparisos i the partitioig phase betwee elemets i the array ad the pivot elemet, whe executig the algorithm Rage Quickselect util a elemet with a rak betwee i ad j is foud i the array A[..]. Theorem 3. The expected umber of elemet comparisos C,i,j = E (C,i,j made while executig the algorithm Rage Quickselect util a elemet with a rak betwee i ad j is foud i a array of size is: C,i,j = 2( + H + 2(j i + 4H j i+ 2(j + 2H j 2( i + 3H i+ + 2 j + i 2 2 log + 2(j i + log(j i + 2j log j 2( i + log( i + + O(log 2, for i j The asymptotic equivalece holds uiformly for i j ad. Settig i = j above, we obtai the average umber of comparisos to select the jth smallest elemet out of [0]: C,j,j = 2 (( + H (j + 2H j ( j + 3H j+, for j. Aother immediate cosequece of the theorem is that the value C,i,j is always Θ(, amely, C,i,j = c(i/, j/ + o(, with c(a, b = 2( a l( a 2b l b + 2(b a l(b a + 2 (b a. The proof of this theorem is fully aalogous to that of Theorem i Subsectio 2.2. First we obtai a distributioal recurrece for C,i,j, which has the same structure as the oe give i Propositio. Here, we oly have to take ito accout that durig the partitioig phase ad idepedet of the actual rak of the pivot, we perform exactly comparisos betwee the pivot elemet ad the other elemets i the array. Propositio 2. The radom variable C,i,j satisfies the followig distributioal recurrece: (d C,i,j = + U<i C ( U,i U,j U + U>j C (2 U,i,j, for i j, ad C,i,j = 0, if i < or j < i or j >, where the rak U of the pivot elemet is uiformly distributed o {, 2,..., } ad idepedet of (C,i,j,i,j, (C (,i,j,i,j ad (C (2,i,j,i,j; the last two are idepedet copies of (C,i,j,i,j. Propositio 2 gives the the followig recurrece for the expectatio C,i,j of the umber of comparisos: C,i,j = + i C k,i k,j k + C k,i,j, for i j, (5 ad C,i,j = 0, if i < or j < i or j >. This recurrece is exactly the recurrece studied i Subsectio 2.3 for the particular toll fuctio T,i,j =, for i j. Applyig Theorem 2 easily leads the, for i j, to a exact formula for C,i,j ad proves Theorem 3: i C,i,j = i+l l= k=j i+l i 2(k (k + (k l= i + l i + l + + k=j k k + +

10 0 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER i = = i+l l= k=j i+l + ( i ( 4 k k + 2 i + l= ( 2 + i + l + ( 4(H i+l H j i+l + 6(H i+l+ H j i+l+ l= + i 2(H H i+ + j 2(H H j + = 2( + H + 2(j i + 4H j i+ 2(j + 2H j 2( i + 3H i+ + 2 j + i 2. To obtai the fial result we just used the basic summatio formula k=j ( 2 k + H k = ( H. ( Savigs ad grad averages. Give ay measure of performace X,i,j of Rage Quickselect whe lookig for a elemet whose rak falls i the rage [i..j], out of elemets, it is quite obvious that X,i,j X,k,k, for ay k [i..j]. I other words, o matter what measure we cosider, Rage Quickselect will ever perform worse tha Quickselect whe the sought rak k belogs to the rage [i..j] give as iput to Rage Quickselect. The iequality above of course carries over expectatios, thus X,i,j X,k,k for k [i..j]. It makes sese the to itroduce the differece X,i,d = X,i,i X,i d,i+d, d < i < + d, 0 d ( /2 which measures the savigs of Rage Quickselect over Quickselect whe lookig for the ith smallest elemet ad Rage Quickselect is give a rage of size 2d + aroud i. As we shall see, i some cases, X,i,d does ot deped (or its mai order term does ot deped o i, so usig the size d of the rage to express the savigs yielded by Rage Quickselect turs out to be a relevat choice. Obtaiig both explicit ad asymptotic formulaæ for P,i,d ad C,i,d is straightforward from the explicit expressios give by Theorems ad 3, ad the well-kow asymptotic expasio of the harmoic umbers H = log + γ + O(, with γ deotig the Euler-Mascheroi costat. Aother iterestig set of quatities that we study i this sectio (ad o those forthcomig are the grad averages. We fix a size 2d + for the rage give to Rage Quickselect ad the average over all possible i, i. e., we are iterested i the expected value of X,i d,i+d whe i is uiformly distributed i [d +.. d]. Such quatities are ofte called grad averages [4, 9]. Thus, X,d = 2d d<i d X,i d,i+d, 0 d ( /2. Notice that X,0 is the expected value for quickselect with radom rak. As before, we will also be iterested i the grad average savigs X,d = X,0 X,d, 0 d ( /2.

11 ANALYSIS OF RANGE QUICKSELECT I the case of passes ad comparisos, explicit ad asymptotic expressios for the grad averages ad the average savigs follow easily from the explicit formulæ available for these measures of cost. The followig corollary summarizes the relevat results. Corollary 2. Let d ad i be such that 0 d ( /2 ad d < i < + d. The asymptotic estimates below hold uiformly for all d > 0, uless explicitly stated otherwise, whe. ( Let P,i,d = P,i,i P,i d,i+d be the average umber of passes saved if we use Rage Quickselect with rage [i d..i + d] istead of Quickselect with rak i. The (2 Let P,i,d = (H i H i+d + (H + i H + i+d + 2H 2d+ 2 2 log d + Θ(. P,d = 2d d<i<+ d P,i d,i+d be the average umber of passes made by Rage Quickselect for a rage of size 2d+ cetered aroud a rak chose uiformly at radom. The P,d = 2 + 2d (H H 2d d { 2 log(/d + O(, if 0 < d = o(, 2 2δ log(/2δ + O(/, if d = δ + o(, with 0 < δ < /2. Furthermore, the grad average of the savigs is P,d = P,0 P,d 2 log d + O(. (3 Let C,i,d = C,i,i C,i d,i+d be the average umber of elemet comparisos that we save if we use Rage Quickselect with rage [i d..i + d] istead of Quickselect with rak i. The C,i,d = 8 2(i + 2H i 2( i + 3H + i 2(2d + 4H 2d+ + 2(i + d + 2H i+d + 2( i dh ++d i + 2d { 4d log ( d + Θ(d, if 0 < d = o(, 2c(α, δ 8 log + O(, if d = δ + o(, with 0 < δ < /2, where c(α, δ = δ + ( α + δ log( α + δ + (α + δ log(α + δ α log α ( α log( α 2δ log(2δ. The secod asymptotic estimate holds uiformly for i = α + o( ad. (4 Let C,d = C,i d,i+d 2d d<i<+ d be the average umber of comparisos made by Rage Quickselect for a rage of size 2d + cetered aroud a rak chose uiformly at radom. The C,d = 3 4(d + 2( + 4(d + 2 (H H 2d d 2d

12 2 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER { ( 3 4(d + 2 log ( d + Θ(d, if 0 < d = o(, 3 + 4δ log(2δ 2δ + Θ(, if d = δ + o(, with 0 < δ < /2. Furthermore, the grad average of the savigs is { 4d log(/d + Θ(d, if 0 < d = o(, C,d = C,0 C,d 4δ log(/2δ 2δ 8 log + Θ(, if d = δ + o(, 0 < δ < /2. To coclude, a few words o the practical sigificace of these fidigs. For istace, we ca fid a elemet whose rak is /2 ± ad save up to Θ( log comparisos, or fid a elemet of rak α( ± δ, for some δ > 0 ad save a liear umber of comparisos. Savigs of the order Θ( log might seem too small to bother with, sice the algorithm rus i liear time; however, for moderate sizes of the array, savigs such as these are oticeable i practice. For istace, with a rage of size 2 + aroud the desired rak, the algorithm allows us to save 555 comparisos o average for a array of size 0000 (the rage aroud the sought rak is of size 20, ad we save 2400 comparisos o the average whe the size is (the rage is the of size MOVES IN QUICKSELECT AND RANGE QUICKSELECT We start with the defiitio of the quatities i our study of moves of elemets i the stadard Quickselect ad Rage Quickselect algorithms. The radom variable M,p,j, with p, j, couts the umber of moves of the elemet with rak p, i. e., assigmets appearig i lie 8, lie 3 or 7 where the right-had side cotais the pth elemet, i the PARTITION procedure (give as Algorithm 3 i ext page while executig the algorithm Quickselect to fid a elemet with rak j i a array A[..]. The radom variable V,i,j, with i j, couts the total umber of moves, i. e., assigmets appearig i lie 8, lie 3 or 7, of array elemets i the procedure PARTITION whe executig the algorithm RQS to fid the elemet with rak k [i..j] i a array A[..]. We coclude this itroductio by statig the followig well-kow radomess preservatio property (see, e.g., [] of the partitio algorithm PARTITION as described i Subsectio 3. (we remark that this property also holds for other commoly used partitio procedures. Whe startig with a radom permutatio of distict values a l < a l+ < < a r as iput data A[l..r] for the partitio algorithm PARTITION(A, l, r, k it holds that after executig this procedure the left subarray A[l..k ] is itself a radom permutatio of a l < a l+ < < a k, ad the right subarray A[k +..r] is itself a radom permutatio of a k+ < a k+2 < < a r. This radomess preservatio property allows a recursive descriptio of the parameters studied i this paper ad is thus heavily used i the aalysis carried out i what follows. 3.. The Partitio procedure. There are several stadard implemetatios of the partitioig phase used i practice for the algorithm Quickselect (ad, of course, also for Quicksort. The procedure PARTITION give as Algorithm 3 is just oe particular implemetatio, which we assume to be used i both Quickselect ad Rage Quickselect. While for the aalysis of moves, we cotiue assumig that all elemets are distict, the implemetatio of PARTITION cotemplates the more geeral case where repetitios may occur. At this poit, we wat to poit out that other stadard implemetatios of the partitioig procedure will likely lead to similar, although slightly differet, results for the quatities studied here. After executig PARTITION(A, l, r, k a pivot elemet v is brought to its correct positio v = A[k] i the array, such that all elemets i the array A[l..k ] are smaller tha or equal to v ad all elemets i the array A[k +..r] are larger tha or equal to v.

13 ANALYSIS OF RANGE QUICKSELECT 3 To do this the procedure starts by choosig as pivot elemet v the first elemet A[l] i the array A[l..r], which is stored. The, by usig two poiters a ad b that are iitialized by a = l ad b = r, the array is scaed i a alteratig way from right ad from left, where each elemet is compared with the pivot elemet v. Whe scaig from right we search for the first elemet A[b], which is smaller tha or equal to v; this elemet is the stored at positio A[a] ad oe cotiues with scaig from left. Whe scaig from left we search for the first elemet A[a], which is larger tha or equal to v; this elemet is the stored at positio A[b] ad oe cotiues with scaig from right. The sca stops if a = b, i. e., if the two poiters a ad b meet each other. The it remais to store the pivot elemet v at its correct place A[a] i the array ad retur this fial locatio of the pivot elemet. Algorithm 3 The PARTITION procedure Require: Array A[l..r] Esure: m : (l m < k A[m] A[k], ad m : (k < m r A[k] A[m] : procedure PARTITION(A, l, r, k 2: if l > r the retur Nothig will be doe 3: ed if 4: a := l; b := r; v := A[a] 5: while a < b do 6: while A[b] > v do b := b Sca from right 7: ed while 8: A[a] := A[b] 9: a := a + 0: if a < b the : while A[a] < v do a := a + Sca from left 2: ed while 3: A[b] := A[a] 4: b := b 5: ed if 6: ed while 7: A[a] := v 8: k := a Task fiished 9: ed procedure 3.2. The umber of moves of particular elemets i Quickselect. We study here the average behavior of the radom variable M,p,j, with p, j, which couts the umber of moves, i. e., assigmets A[.] := a p of the elemet with rak p i the PARTITION procedure whe executig the algorithm Quickselect to fid the elemet with rak j i a array of size. The followig theorem provides a exact formula for the expectatio M,p,j := E (M,p,j. Theorem 4. The expected umber of moves M,p,j = E (M,p,j of the elemet with rak p durig the executio the algorithm Quickselect to fid the elemet with rak j i a array of size, is M,p,j = 3 H + 6 H j + 6 H p+ 2 3 H j p+ + (p (p + 2(p (p (p j 6(j (p (p 2 3(, for p < j, j p +

14 4 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER M,p,j = 3 H + 6 H p + 6 H j+ 2 3 H (p 2 p j+ + 3 (p j(p j 3 (p j(p j + 6( j + 6( j (p (p 2 3( M,p,j = 3 H + 6 H j + 6 H j+ + (j 2 (j (j ( 3j + 2 [j = ] 2 [j = ], for p = j, j ad 2, M,, =. + 3p + 2, for j < p, 3(p j + Despite the formulæ for M,p,j whe p < j ad M,p,j whe p > j seem to be related via the substitutio p p +, j j +, this is ot the case, as the reader ca readily covice herself by substitutig a few values. The differece betwee the formula M,p,j for p > j, call it M (2,p,j, ad the formula M,p,j for p < j, call it M (,i,j, whe we substitute p by + p ad j by + j is very small, amely, M (2,p,j = M (,p,j + O(. For completitude we will later give separate asymptotic formulæ i Corollary 3 for M,p,j whe p < j ad whe p > j, although that should be ot ecessary because of the relatio just oted. To prove this theorem we start with a recursive descriptio of M,p,j, which is obtaied by cosiderig a call of Quickselect for a array A[..]. We assume ow that the pivot elemet v = A[] is the kth smallest elemet i the array; sice our iput data are formig a radom permutatio of legth it holds that the probability that the pivot elemet has rak k is /, for k. Now we study whether the elemet with rak p will be moved, i. e., a assigmet A[ ] :=... where the right-had side cotais the elemet with rak i is performed, durig the executio of the partitio procedure PARTITION. We have to distiguish three cases: ( if k = p the the elemet with rak p (i this case this is the pivot elemet will always be moved, (2 if k < p the elemet with rak p will be moved oly if it is located i the subarray A[2..k]; the probability that this happes is thus k, ad (3 if k > p the elemet with rak p will be moved oly if it is located i the subarray A[k..]; the probability that this happes is the k+. After the partitioig phase the left subarray A[..k ] ad the right subarray A[k +..] are each formig a radom permutatio of legths k ad k, respectively. Next we observe that if the pivot elemet has a rak betwee p ad j, i. e., depedig o the order of the cosidered elemets either p k j or j k p, the fial umber of moves of the elemet with rak p durig the executio of Quickselect is already reached. This holds sice the either the Quickselect algorithm termiates (k = j or it cotiues executig i a subarray that does ot cotai the elemet with rak p. Oly if k < p j or k < j p we proceed with a recursive call of Quickselect for the right subarray, ad if k > j p or k > p j we proceed with a recursive call of Quickselect for the left subarray. I these latter cases we have to add the umber of moves of the elemet with rak p durig the executio of Quickselect occurrig therei. These cosideratios immediately lead to the followig propositio. Propositio 3. The radom variable M,p,j satisfies, for p, j, the followig distributioal recurrece: M,p,j (d = U<p M ( U,p U,j U + U>j M (2 U,p,j + T,p,U, for p j, M,p,j (d = U<j M ( U,p U,j U + U>p M (2 U,p,j + T,p,U, for j < p,

15 ANALYSIS OF RANGE QUICKSELECT 5 ad M,p,j = 0, if mi(p, j < or max(p, j >. The rak U of the pivot elemet is uiformly distributed o {, 2,..., } ad idepedet of (M,p,j,p,j, (M (,p,j,p,j ad (M (2,p,j,p,j, which are idepedet copies of (M,p,j,p,j. Here the radom variable T,p,k is the idicator fuctio of the evet that the elemet with rak p is moved durig the executio of the partitio procedure PARTITION for a radomly chose permutatio of legth leadig to a pivot elemet of rak k. It holds the, for p, k : k, k < p, P {T,p,k = } = k+, k > p,, k = p, ad P {T,p,k = 0} = P {T,p,k = }. We remark here that i the distributioal recurrece give as Propositio 3 the radom variables T,p,k ad M ( k,p k,j k (ad also T,p,k ad M (2 k,p,j are depedet as ca be checked easily for cocrete examples (e. g., for = 3 ad i = j =. Thus Propositio 3 will oly allow to treat the expectatio M,p,j of the umber of moves, whereas a study of higher momets would require a more refied descriptio of M,p,j. However, Propositio 3 immediately leads to a recurrece for the expected value M,p,j. It is here advatageous to distiguish betwee the cases p < j, p = j ad p > j. We start with the case p < j, where we obtai, for p < j : M,p,j = p M k,p k,j k + M k,p,j + E (T,p,k p = M k,p k,j k + p = M k,p k,j k + M k,p,j + M k,p,j + ( p k + + (p (p 2 2( + k=p+ k + ( p( p + 2( To get a exact solutio of M,p,j we ca thus apply Theorem 2 for the particular toll fuctio T,p,j = (p (p 2 2( + ( p( p + 2( +, p < j. +. We omit here the computatios leadig to the exact formula of M,p,j, p < j, give i Theorem 4, sice othig more is required tha basic summatio formulæ. For the case p = j we obtai, for j : j M,p,j = M k,p k,j k + = i M k,p k,j k + + { (j (j 2 2( M k,p,j + M k,p,j + ( j( j+ 2( +, for 2,, for =. E (T,p,k

16 6 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER Thus, a exact solutio of M,p,j with p = j ca be obtaied by itroducig M,j := M,p,j ad applyig Corollary for the particular toll fuctio T,j := { (j (j 2 2( + ( j( j+ 2( +, for j ad 2,, for j = =. After carryig out the computatios occurrig, which are omitted here, we obtai the exact formula of M,j,j, j, give i Theorem 4. Fially we cosider the case p > j, where we obtai, for j < p : M,p,j = j M k,p k,j k + M k,p,j + E (T,p,k j = M k,p k,j k + k=p+ k=p+ M k,p,j + (p (p 2 2( + ( p( p + 2( Whe itroducig M,p,j := M,j,p this recurrece ca be writte as follows, with p < j : p M,p,j = M k,p k,j k + M k,p,j + (j (j 2 2( + ( j( j + 2( A exact solutio of M,p,j, p < j, ca be obtaied by applyig Theorem 2 for the particular toll fuctio T,p,j = (j (j 2 2( + ( j( j + 2( +, p < j. After back substitutio we thus obtai a exact solutio of M,p,j, with j < p, which is give i Theorem 4. Agai the straightforward computatios are omitted. Last but ot least, we ca obtai asymptotic equivalets with little effort. Corollary 3. The expected umber of moves M,p,j = E (M,p,j of the elemet with rak p whe executig the algorithm Quickselect to fid the elemet with rak j i a array of size has the followig asymptotic equivalets, which hold for ad uiformly for the give rage of p ad j: M,p,j = 3 log + 6 log j + 6 log( p log(j p + + O(, p < j, M,p,j = 3 log + 6 log p + 6 log( j log(p j + + O(, j < p, M,j,j = 3 log + 6 log j + 6 log( j + + O(, j. I particular, we get the followig importat estimates whe j = β + o(, 0 < β < : M,p,j 6 log β + 6 log( α 2 α2 log(β α + 3 6β 2 2α 3β + 2 α 3 + α2 3, for p = α + o(, ad 0 < α < β <, M,p,j 6 log α + 6 log( β 2 ( α2 2( α log(α β + 3 6( β 2 3( β + 2 α 3 + α2 3, for p = α + o(, ad 0 < β < α <,

17 ANALYSIS OF RANGE QUICKSELECT 7 M,p,j 2 ( κ log, 3 for j p K κ, with 0 < κ < ad K 0, M,p,j 2 3 log, for j p = O((log κ for some κ > The total umber of moves i Rage Quickselect. Now we study the average behavior of the radom variable V,i,j, with i j, which couts the total umber of moves, i. e., assigmets A[ ] := of array elemets, i the partitio procedure PARTITION whe executig the algorithm RQS to fid the elemet with rak k [i..j] i a array A[..]. Theorem 5. The expected total umber of moves V,i,j = E (V,i,j of array elemets i the partitio procedure PARTITION whe executig the algorithm RQS to fid the elemet with rak k [i..j] i a array A[..] filled with a radom permutatio of legth, for i j, is give by the followig exact formula: V,i,j = 2 3 ( + H 6 (4j + H j 6 (4 4i + 5H i (2j 2i + H j i+ j 3 + i 3 +, for i < j, 2 V,j,j = 2 3 ( + H 6 (4j + H j 6 (4 4j + 5H j V,, = [j = j = ], for j ad 2, 36 Asymptotically, for i = α + o( ad j i = δ + o(, V,i,j 3 ( 2δ log δ 2( α log( α 2(α + δ log(α + δ + 2 δ, 0 < δ < α. We derive this theorem from a recursive descriptio of V,i,j, which is agai obtaied by cosiderig a call of RQS for a array A[..]. We assume that the pivot elemet v = A[] is the kth smallest elemet i the array; the probability that this happes is /, for k. Now we wat to cout the total umber of moves, i. e., a assigmet A[.] := (appearig i lie 8, lie 3 or 7, of array elemets i the partitio procedure PARTITION. We distiguish betwee two cases: ( if k = the there is exactly oe move durig the partitioig phase, amely the assigmet of the pivot elemet i lie 7, (2 if k 2 the there may occur the followig two situatios: Elemet A[k] has a rak i the rage..(k ad exactly l elemets with a rak i the rage..(k are located i the subarray A[k..]. It follows the that exactly l elemets with a rak i the rage (k+.. are located i the subarray A[2..k ]. I this situatio we obtai the that exactly 2l, i. e., l (lie 8 + l (lie 3 + (lie 7, moves are carried out durig the partitioig phase. By elemetary combiatorial cosideratios we get the followig probability that this evet occurs: ( ( ( k 2 ( k k 2 k l l (k!( k! =, for l k. (! l l ( k

18 8 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER Elemet A[k] has a rak i the rage (k +.. ad exactly l elemets with a rak i the rage..(k are located i the subarray A[k +..]. It follows the that exactly l elemets with a rak i the rage (k +.. are located i the subarray A[2..k]. I this situatio we obtai the that exactly 2l +, i. e., l (lie 8 + l (lie 3 + (lie 7, moves are carried out durig the partitioig phase. This gives the followig probability that this evet occurs: ( k 2 (! l ( k l (k!( k! = ( k 2 ( k l l ( k, for l k. Of course, after the partitioig phase the left subarray A[..k ] ad the right subarray A[k+..] are each formig a radom permutatio of legths k ad k, respectively. But as ca be show easily (permutig the elemets with a rak i the rage..(k ad of the elemets with a rak i the rage (k +.., respectively, i the iput data array leads to easy-describable permutatios of the elemets i the subarrays A[..k ] ad A[k +..] after the partitioig phase eve more is true. Namely, if we cosider oly those permutatios, such that the umber of moves i the procedure PARTITION is exactly l, with a arbitrary l, the it also holds that after the partitioig phase the left subarray A[..k ] ad the right subarray A[k +..] are each formig a radom permutatio of legths k ad k, respectively. Thus the umber of moves durig the partitioig phase is idepedet of the umber of moves, which are made durig a recursive call of RQS for the right subarray A[k +..] (if k < i or the left subarray A[..k ] (if k > j ad that have to be added to get the total umber of moves. This idepedece property appearig i the distributioal recurrece stated i the followig propositio would allow also to study higher momets of V,i,j or could be a startig poit for cosideratios cocerig the limitig distributioal behavior of V,i,j (see, e.g., [4, 7] for limitig distributio results studyig the parameter umber of comparisos i Quickselect. Propositio 4. The radom variable V,i,j satisfies, for i j, the followig distributioal recurrece: V,i,j (d = U<i V ( U,i U,j U + U>j V (2 U,i,j + T,U, for i j, ad V,i,j = 0, if i <, j < i or j >, where the sequeces (U, (T,k,k, (V (,i,j,i,j ad (V (2,i,j,j of radom variables are all idepedet. Here V (,i,j ad V(2,i,j are idepedet copies of V,i,j, whereas U is uiformly distributed o {, 2,..., }. Furthermore, T,k is, for k, distributed as follows: P {T, = } =, P {T,k = 2l} = P {T,k = 2l + } = ( k 2 ( k l l ( k ( k 2 ( k l l ( k, for k 2 ad l k,, for k 2 ad l k.

19 ANALYSIS OF RANGE QUICKSELECT 9 Propositio 4 immediately gives the followig recurrece for the expectatio V,i,j of the total umber of moves: V,i,j = i V k,i k,j k + V k,i,j + E (T,k, for i j, (7 ( k l= ad V,i,j = 0, if i <, j < i or j >. It holds that E (T, =, whereas for k 2 we obtai: E (T,k = k ( ( k 2 k 2l + l l ( k k l= ( k 2 l ( k l (2l + ( k + (2k =, where we used the Chu-Vadermode idetity (see, e. g., [3]. Easy computatios give the { E (T,k = , for 2,, for =. Thus (7 ca be writte as follows: V,i,j = i V k,i k,j k + V k,i,j + T,i,j, for i j, (8 with T,, = ad T,i,j = , for i j ad 2. A exact solutio of this recurrece ca be obtaied by simply applyig Theorem 2, which shows Theorem 5; the straightforward computatios are omitted here. We remark here that settig i = j leads to results cocerig the total umber of moves i stadard Quickselect, e. g., V,j,j is the radom variable that couts the total umber of moves made by Quickselect whe selectig the jth smallest elemet out of. As we have doe for passes ad comparisos, we ca compare the savigs of Rage Quickselect relative to Quickselect. The followig corollaries provide the exact ad asymptotic formulæ for the savigs ad the grad average. Corollary 4. Let V,i,d = V,i,i V,i d,i+d, that is, the average umber of data moves that we save if we use Rage Quickselect with rage [i d..i + d] istead of Quickselect with rak i, for d < i < + d ad 0 d ( /2. The V,i,d = 6 (4i + (H i+d H i + 6 (4 4i + 5(H ++d i H + i + 2d 3 (H i+d + H ++d i + 2H 2d+ + 5 [d > 0] 8 where { 4 3 d log ( d + Θ(d, if 0 < d = o(, c(α, δ 8 log + O(, if d = δ + o(, with 0 < δ < /2, 2 3 c(α, δ = δ + ( α + δ log( α + δ + (α + δ log(α + δ α log α ( α log( α 2δ log(2δ.

20 20 C. MARTÍNEZ, A. PANHOLZER, AND H. PRODINGER The first asymptotic estimate holds uiformly for all d = o( ad. The secod asymptotic estimate holds uiformly for i = α + o( ad. Observe that for ay valid i ad d, V,i,d 3 C,i,d; actually, V,i,j 3 C,i,j P,i,j +O(. Corollary 5. Let V,d = 2d d<i<+ d V,i d,i+d, 0 ( /2, that is, V,d is the average total umber of moves made by Rage Quickselect for a rage of size 2d + cetered aroud a rak chose uiformly at radom. The (4d + ( + ( V,d = H H 2d+ + 3( 2d 2 4d +, for d, 3( 2d V,0 = + 3 H + 7 9, for 2, 8 V,0 =. Moreover, it holds { (4d+ 3 log ( d + Θ(d if 0 < d = o(, V,d ( + + Θ(, if d = δ + o(, with 0 < δ < /2. 4δ log(2δ 3( 2δ The first asymptotic estimate holds uiformly for all d = o(, whe. Furthermore, the grad average of the savigs is V,d = V,0 V,d { 4d 3 log(/d + Θ(d, if 0 < d = o(, 4δ log(/2δ 3( 2δ 3 log + Θ(, if d = δ + o(, 0 < δ < /2. 4. SOME PARAMETERS IN BINARY SEARCH TREES Biary search trees are biary trees geerated by successively isertig elemets ito a origially empty tree via a simple recursive algorithm (see for istace [2]. If elemet x has to be iserted ito a empty tree oe creates a ew ode cotaiig x. If elemet x has to be iserted ito a o-empty tree oe has to compare x with the elemet k of the root: if x < k the x will be iserted ito the left subtree, whereas if x k the x will be iserted ito the right subtree. For the average-case aalysis of the quatities cosidered for biary search trees we also always use the radom permutatio model, i. e., we assume that all! permutatios of a sequece of distict values a < a 2 < < a are chose with equal probability as iput data to geerate a biary search tree of size. We defie ow the three parameters for radom biary search trees we will cosider i this paper. The radom variable A,i,j, with i j, couts the umber of commo acestors (i a rooted tree B a ode v is a acestor of ode w if v is lyig o the uique path from the root of B to w of the odes with rak i ad j i a radom biary search tree of size. The radom variable S,i,j, with i j, couts the size of the subtree rooted at the least commo acestor of the odes with rak i ad j i a radom biary search tree of size (i. e., the size of the smallest subtree cotaiig the odes with rak i ad j. Fially, the radom variable D,i,j, with i j, is the distace (umber of edges i the uique path from the ith ode to the jth ode i a radom BST of size.

21 ANALYSIS OF RANGE QUICKSELECT 2 FIGURE. A example of the parameters A,i,j, S,i,j ad D,i,j A example of a biary search tree together with the quatities cosidered i this paper is give as Figure. The biary search tree depicted is of size 6 ad was geerated by isertig the elemets [5, 5, 0, 6, 8, 2, 3, 2,, 4, 6, 4, 7, 9, 3, ], i that order. The odes i = 8 ad j = 2 have A 6,8,2 = 3 commo acestors (odes 5, 5, ad 0. The size of the subtree rooted at the least commo acestor of odes i = 8 ad j = 2 (which is ode 0 is S 6,8,2 = 9. The distace betwee the two odes is D 6,8,2 = 3. Both A,i,j ad D,i,j have received attetio i the literature [9, 22, 2]. The correspodig results i the followig subsectios are thus alterative derivatios, usig Theorem 2, of the formulæ that were already kow. Other authors have also ivestigated the umber of commo acestors ad the distace betwee two radomly chose odes i a radom biary search tree [5]. The results give here (Subsectio 4.2 about the size of the subtree rooted at the least commo acestor of two give odes are ew, to the best of our kowledge. 4.. Commo acestors. We cosider ow the radom variable A,i,j, with i j, which couts the umber of commo acestors of the odes with rak i ad j i a radom biary search tree of size. We fid that the distributio of A,i,j has bee dealt with already i Sectio 2. Theorem 6. The radom variable A,i,j ad the umber of passes made by Rage Quickselect P,i,j, which has bee defied i Subsectio 2.2, are equally distributed, i. e., A,i,j (d = P,i,j. Therefore, the expected umber of commo acestors A,i,j = E (A,i,j of the odes with rak i ad j i a radom biary search tree of size is, for i j, give by the followig exact ad asymptotic formula (which uiformly holds for i j ad : A,i,j = H j + H i+ 2H j i+ + = log + log( i + 2 log(j i + + O(. This ca be show easily, where we use a recursive descriptio of A,i,j, which is obtaied via the decompositio of a biary search tree of size ito the root ode ad its left ad right subtree. Assumig the radom permutatio model we get that with probability / the root ode has rak k, for all k. I ay case the root ode is a commo acestor of the odes with rak i ad j. If

CS / MCS 401 Homework 3 grader solutions

CS / MCS 401 Homework 3 grader solutions CS / MCS 401 Homework 3 grader solutios assigmet due July 6, 016 writte by Jāis Lazovskis maximum poits: 33 Some questios from CLRS. Questios marked with a asterisk were ot graded. 1 Use the defiitio of

More information

Analysis of Algorithms. Introduction. Contents

Analysis of Algorithms. Introduction. Contents Itroductio The focus of this module is mathematical aspects of algorithms. Our mai focus is aalysis of algorithms, which meas evaluatig efficiecy of algorithms by aalytical ad mathematical methods. We

More information

Math 155 (Lecture 3)

Math 155 (Lecture 3) Math 55 (Lecture 3) September 8, I this lecture, we ll cosider the aswer to oe of the most basic coutig problems i combiatorics Questio How may ways are there to choose a -elemet subset of the set {,,,

More information

An Introduction to Randomized Algorithms

An Introduction to Randomized Algorithms A Itroductio to Radomized Algorithms The focus of this lecture is to study a radomized algorithm for quick sort, aalyze it usig probabilistic recurrece relatios, ad also provide more geeral tools for aalysis

More information

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis Recursive Algorithms Recurreces Computer Sciece & Egieerig 35: Discrete Mathematics Christopher M Bourke cbourke@cseuledu A recursive algorithm is oe i which objects are defied i terms of other objects

More information

4.3 Growth Rates of Solutions to Recurrences

4.3 Growth Rates of Solutions to Recurrences 4.3. GROWTH RATES OF SOLUTIONS TO RECURRENCES 81 4.3 Growth Rates of Solutios to Recurreces 4.3.1 Divide ad Coquer Algorithms Oe of the most basic ad powerful algorithmic techiques is divide ad coquer.

More information

Recurrence Relations

Recurrence Relations Recurrece Relatios Aalysis of recursive algorithms, such as: it factorial (it ) { if (==0) retur ; else retur ( * factorial(-)); } Let t be the umber of multiplicatios eeded to calculate factorial(). The

More information

Analysis of Algorithms -Quicksort-

Analysis of Algorithms -Quicksort- Aalysis of Algorithms -- Adreas Ermedahl MRTC (Mälardales Real-Time Research Ceter) adreas.ermedahl@mdh.se Autum 2004 Proposed by C.A.R. Hoare i 962 Worst- case ruig time: Θ( 2 ) Expected ruig time: Θ(

More information

Random Models. Tusheng Zhang. February 14, 2013

Random Models. Tusheng Zhang. February 14, 2013 Radom Models Tusheg Zhag February 14, 013 1 Radom Walks Let me describe the model. Radom walks are used to describe the motio of a movig particle (object). Suppose that a particle (object) moves alog the

More information

Problem Set 2 Solutions

Problem Set 2 Solutions CS271 Radomess & Computatio, Sprig 2018 Problem Set 2 Solutios Poit totals are i the margi; the maximum total umber of poits was 52. 1. Probabilistic method for domiatig sets 6pts Pick a radom subset S

More information

6.3 Testing Series With Positive Terms

6.3 Testing Series With Positive Terms 6.3. TESTING SERIES WITH POSITIVE TERMS 307 6.3 Testig Series With Positive Terms 6.3. Review of what is kow up to ow I theory, testig a series a i for covergece amouts to fidig the i= sequece of partial

More information

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS DEMETRES CHRISTOFIDES Abstract. Cosider a ivertible matrix over some field. The Gauss-Jorda elimiatio reduces this matrix to the idetity

More information

CS284A: Representations and Algorithms in Molecular Biology

CS284A: Representations and Algorithms in Molecular Biology CS284A: Represetatios ad Algorithms i Molecular Biology Scribe Notes o Lectures 3 & 4: Motif Discovery via Eumeratio & Motif Represetatio Usig Positio Weight Matrix Joshua Gervi Based o presetatios by

More information

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22 CS 70 Discrete Mathematics for CS Sprig 2007 Luca Trevisa Lecture 22 Aother Importat Distributio The Geometric Distributio Questio: A biased coi with Heads probability p is tossed repeatedly util the first

More information

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ. 2 5. Weighted umber of late jobs 5.1. Release dates ad due dates: maximimizig the weight of o-time jobs Oce we add release dates, miimizig the umber of late jobs becomes a sigificatly harder problem. For

More information

Infinite Sequences and Series

Infinite Sequences and Series Chapter 6 Ifiite Sequeces ad Series 6.1 Ifiite Sequeces 6.1.1 Elemetary Cocepts Simply speakig, a sequece is a ordered list of umbers writte: {a 1, a 2, a 3,...a, a +1,...} where the elemets a i represet

More information

Lecture Overview. 2 Permutations and Combinations. n(n 1) (n (k 1)) = n(n 1) (n k + 1) =

Lecture Overview. 2 Permutations and Combinations. n(n 1) (n (k 1)) = n(n 1) (n k + 1) = COMPSCI 230: Discrete Mathematics for Computer Sciece April 8, 2019 Lecturer: Debmalya Paigrahi Lecture 22 Scribe: Kevi Su 1 Overview I this lecture, we begi studyig the fudametals of coutig discrete objects.

More information

Convergence of random variables. (telegram style notes) P.J.C. Spreij

Convergence of random variables. (telegram style notes) P.J.C. Spreij Covergece of radom variables (telegram style otes).j.c. Spreij this versio: September 6, 2005 Itroductio As we kow, radom variables are by defiitio measurable fuctios o some uderlyig measurable space

More information

Average-Case Analysis of QuickSort

Average-Case Analysis of QuickSort Average-Case Aalysis of QuickSort Comp 363 Fall Semester 003 October 3, 003 The purpose of this documet is to itroduce the idea of usig recurrece relatios to do average-case aalysis. The average-case ruig

More information

1 Hash tables. 1.1 Implementation

1 Hash tables. 1.1 Implementation Lecture 8 Hash Tables, Uiversal Hash Fuctios, Balls ad Bis Scribes: Luke Johsto, Moses Charikar, G. Valiat Date: Oct 18, 2017 Adapted From Virgiia Williams lecture otes 1 Hash tables A hash table is a

More information

A Probabilistic Analysis of Quicksort

A Probabilistic Analysis of Quicksort A Probabilistic Aalysis of Quicsort You are assumed to be familiar with Quicsort. I each iteratio this sortig algorithm chooses a pivot ad the, by performig comparisios with the pivot, splits the remaider

More information

Test One (Answer Key)

Test One (Answer Key) CS395/Ma395 (Sprig 2005) Test Oe Name: Page 1 Test Oe (Aswer Key) CS395/Ma395: Aalysis of Algorithms This is a closed book, closed otes, 70 miute examiatio. It is worth 100 poits. There are twelve (12)

More information

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) = AN INTRODUCTION TO SCHRÖDER AND UNKNOWN NUMBERS NICK DUFRESNE Abstract. I this article we will itroduce two types of lattice paths, Schröder paths ad Ukow paths. We will examie differet properties of each,

More information

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia) 1 CS 332: Algorithms Liear-Time Sortig. Order statistics. Slide credit: David Luebke (Virgiia) Quicksort: Partitio I Words Partitio(A, p, r): Select a elemet to act as the pivot (which?) Grow two regios,

More information

Legendre-Stirling Permutations

Legendre-Stirling Permutations Legedre-Stirlig Permutatios Eric S. Egge Departmet of Mathematics Carleto College Northfield, MN 07 USA eegge@carleto.edu Abstract We first give a combiatorial iterpretatio of Everitt, Littlejoh, ad Wellma

More information

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU. Sortig Algorithms Algorithms Kyuseo Shim SoEECS, SNU. Desigig Algorithms Icremetal approaches Divide-ad-Coquer approaches Dyamic programmig approaches Greedy approaches Radomized approaches You are ot

More information

The Random Walk For Dummies

The Random Walk For Dummies The Radom Walk For Dummies Richard A Mote Abstract We look at the priciples goverig the oe-dimesioal discrete radom walk First we review five basic cocepts of probability theory The we cosider the Beroulli

More information

Optimally Sparse SVMs

Optimally Sparse SVMs A. Proof of Lemma 3. We here prove a lower boud o the umber of support vectors to achieve geeralizatio bouds of the form which we cosider. Importatly, this result holds ot oly for liear classifiers, but

More information

x a x a Lecture 2 Series (See Chapter 1 in Boas)

x a x a Lecture 2 Series (See Chapter 1 in Boas) Lecture Series (See Chapter i Boas) A basic ad very powerful (if pedestria, recall we are lazy AD smart) way to solve ay differetial (or itegral) equatio is via a series expasio of the correspodig solutio

More information

Hoggatt and King [lo] defined a complete sequence of natural numbers

Hoggatt and King [lo] defined a complete sequence of natural numbers REPRESENTATIONS OF N AS A SUM OF DISTINCT ELEMENTS FROM SPECIAL SEQUENCES DAVID A. KLARNER, Uiversity of Alberta, Edmoto, Caada 1. INTRODUCTION Let a, I deote a sequece of atural umbers which satisfies

More information

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2 Geeral remarks Week 2 1 Divide ad First we cosider a importat tool for the aalysis of algorithms: Big-Oh. The we itroduce a importat algorithmic paradigm:. We coclude by presetig ad aalysig two examples.

More information

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018) Radomized Algorithms I, Sprig 08, Departmet of Computer Sciece, Uiversity of Helsiki Homework : Solutios Discussed Jauary 5, 08). Exercise.: Cosider the followig balls-ad-bi game. We start with oe black

More information

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018 CSE 353 Discrete Computatioal Structures Sprig 08 Sequeces, Mathematical Iductio, ad Recursio (Chapter 5, Epp) Note: some course slides adopted from publisher-provided material Overview May mathematical

More information

Lecture 7: Properties of Random Samples

Lecture 7: Properties of Random Samples Lecture 7: Properties of Radom Samples 1 Cotiued From Last Class Theorem 1.1. Let X 1, X,...X be a radom sample from a populatio with mea µ ad variace σ

More information

MT5821 Advanced Combinatorics

MT5821 Advanced Combinatorics MT5821 Advaced Combiatorics 9 Set partitios ad permutatios It could be said that the mai objects of iterest i combiatorics are subsets, partitios ad permutatios of a fiite set. We have spet some time coutig

More information

Chapter 6. Advanced Counting Techniques

Chapter 6. Advanced Counting Techniques Chapter 6 Advaced Coutig Techiques 6.: Recurrece Relatios Defiitio: A recurrece relatio for the sequece {a } is a equatio expressig a i terms of oe or more of the previous terms of the sequece: a,a2,a3,,a

More information

Math 475, Problem Set #12: Answers

Math 475, Problem Set #12: Answers Math 475, Problem Set #12: Aswers A. Chapter 8, problem 12, parts (b) ad (d). (b) S # (, 2) = 2 2, sice, from amog the 2 ways of puttig elemets ito 2 distiguishable boxes, exactly 2 of them result i oe

More information

Sequences of Definite Integrals, Factorials and Double Factorials

Sequences of Definite Integrals, Factorials and Double Factorials 47 6 Joural of Iteger Sequeces, Vol. 8 (5), Article 5.4.6 Sequeces of Defiite Itegrals, Factorials ad Double Factorials Thierry Daa-Picard Departmet of Applied Mathematics Jerusalem College of Techology

More information

Application to Random Graphs

Application to Random Graphs A Applicatio to Radom Graphs Brachig processes have a umber of iterestig ad importat applicatios. We shall cosider oe of the most famous of them, the Erdős-Réyi radom graph theory. 1 Defiitio A.1. Let

More information

Seunghee Ye Ma 8: Week 5 Oct 28

Seunghee Ye Ma 8: Week 5 Oct 28 Week 5 Summary I Sectio, we go over the Mea Value Theorem ad its applicatios. I Sectio 2, we will recap what we have covered so far this term. Topics Page Mea Value Theorem. Applicatios of the Mea Value

More information

SNAP Centre Workshop. Basic Algebraic Manipulation

SNAP Centre Workshop. Basic Algebraic Manipulation SNAP Cetre Workshop Basic Algebraic Maipulatio 8 Simplifyig Algebraic Expressios Whe a expressio is writte i the most compact maer possible, it is cosidered to be simplified. Not Simplified: x(x + 4x)

More information

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016 CS161: Algorithm Desig ad Aalysis Hadout #10 Staford Uiversity Wedesday, 10 February 2016 Lecture #11: Wedesday, 10 February 2016 Topics: Example midterm problems ad solutios from a log time ago Sprig

More information

Lecture 2: April 3, 2013

Lecture 2: April 3, 2013 TTIC/CMSC 350 Mathematical Toolkit Sprig 203 Madhur Tulsiai Lecture 2: April 3, 203 Scribe: Shubhedu Trivedi Coi tosses cotiued We retur to the coi tossig example from the last lecture agai: Example. Give,

More information

Polynomial identity testing and global minimum cut

Polynomial identity testing and global minimum cut CHAPTER 6 Polyomial idetity testig ad global miimum cut I this lecture we will cosider two further problems that ca be solved usig probabilistic algorithms. I the first half, we will cosider the problem

More information

SOME TRIBONACCI IDENTITIES

SOME TRIBONACCI IDENTITIES Mathematics Today Vol.7(Dec-011) 1-9 ISSN 0976-38 Abstract: SOME TRIBONACCI IDENTITIES Shah Devbhadra V. Sir P.T.Sarvajaik College of Sciece, Athwalies, Surat 395001. e-mail : drdvshah@yahoo.com The sequece

More information

Linear Regression Demystified

Linear Regression Demystified Liear Regressio Demystified Liear regressio is a importat subject i statistics. I elemetary statistics courses, formulae related to liear regressio are ofte stated without derivatio. This ote iteds to

More information

Mathematical Induction

Mathematical Induction Mathematical Iductio Itroductio Mathematical iductio, or just iductio, is a proof techique. Suppose that for every atural umber, P() is a statemet. We wish to show that all statemets P() are true. I a

More information

Chapter 22 Developing Efficient Algorithms

Chapter 22 Developing Efficient Algorithms Chapter Developig Efficiet Algorithms 1 Executig Time Suppose two algorithms perform the same task such as search (liear search vs. biary search). Which oe is better? Oe possible approach to aswer this

More information

Information-based Feature Selection

Information-based Feature Selection Iformatio-based Feature Selectio Farza Faria, Abbas Kazeroui, Afshi Babveyh Email: {faria,abbask,afshib}@staford.edu 1 Itroductio Feature selectio is a topic of great iterest i applicatios dealig with

More information

A PROOF OF THE TWIN PRIME CONJECTURE AND OTHER POSSIBLE APPLICATIONS

A PROOF OF THE TWIN PRIME CONJECTURE AND OTHER POSSIBLE APPLICATIONS A PROOF OF THE TWI PRIME COJECTURE AD OTHER POSSIBLE APPLICATIOS by PAUL S. BRUCKMA 38 Frot Street, #3 aaimo, BC V9R B8 (Caada) e-mail : pbruckma@hotmail.com ABSTRACT : A elemetary proof of the Twi Prime

More information

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials. Divide-ad-coquer algorithms Divide & Coquer Strategy: Divide the problem ito smaller subproblems of the same type of problem Solve the subproblems recursively Combie the aswers to solve the origial problem

More information

Definition 4.2. (a) A sequence {x n } in a Banach space X is a basis for X if. unique scalars a n (x) such that x = n. a n (x) x n. (4.

Definition 4.2. (a) A sequence {x n } in a Banach space X is a basis for X if. unique scalars a n (x) such that x = n. a n (x) x n. (4. 4. BASES I BAACH SPACES 39 4. BASES I BAACH SPACES Sice a Baach space X is a vector space, it must possess a Hamel, or vector space, basis, i.e., a subset {x γ } γ Γ whose fiite liear spa is all of X ad

More information

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 3

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 3 Machie Learig Theory Tübige Uiversity, WS 06/07 Lecture 3 Tolstikhi Ilya Abstract I this lecture we will prove the VC-boud, which provides a high-probability excess risk boud for the ERM algorithm whe

More information

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary Recursive Algorithm for Geeratig Partitios of a Iteger Sug-Hyuk Cha Computer Sciece Departmet, Pace Uiversity 1 Pace Plaza, New York, NY 10038 USA scha@pace.edu Abstract. This article first reviews the

More information

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES Peter M. Maurer Why Hashig is θ(). As i biary search, hashig assumes that keys are stored i a array which is idexed by a iteger. However, hashig attempts to bypass

More information

Principle Of Superposition

Principle Of Superposition ecture 5: PREIMINRY CONCEP O RUCUR NYI Priciple Of uperpositio Mathematically, the priciple of superpositio is stated as ( a ) G( a ) G( ) G a a or for a liear structural system, the respose at a give

More information

Introduction to Machine Learning DIS10

Introduction to Machine Learning DIS10 CS 189 Fall 017 Itroductio to Machie Learig DIS10 1 Fu with Lagrage Multipliers (a) Miimize the fuctio such that f (x,y) = x + y x + y = 3. Solutio: The Lagragia is: L(x,y,λ) = x + y + λ(x + y 3) Takig

More information

arxiv: v1 [math.co] 23 Mar 2016

arxiv: v1 [math.co] 23 Mar 2016 The umber of direct-sum decompositios of a fiite vector space arxiv:603.0769v [math.co] 23 Mar 206 David Ellerma Uiversity of Califoria at Riverside August 3, 208 Abstract The theory of q-aalogs develops

More information

Lecture 2: Monte Carlo Simulation

Lecture 2: Monte Carlo Simulation STAT/Q SCI 43: Itroductio to Resamplig ethods Sprig 27 Istructor: Ye-Chi Che Lecture 2: ote Carlo Simulatio 2 ote Carlo Itegratio Assume we wat to evaluate the followig itegratio: e x3 dx What ca we do?

More information

CALCULATING FIBONACCI VECTORS

CALCULATING FIBONACCI VECTORS THE GENERALIZED BINET FORMULA FOR CALCULATING FIBONACCI VECTORS Stuart D Aderso Departmet of Physics, Ithaca College 953 Daby Road, Ithaca NY 14850, USA email: saderso@ithacaedu ad Dai Novak Departmet

More information

Section 4.3. Boolean functions

Section 4.3. Boolean functions Sectio 4.3. Boolea fuctios Let us take aother look at the simplest o-trivial Boolea algebra, ({0}), the power-set algebra based o a oe-elemet set, chose here as {0}. This has two elemets, the empty set,

More information

HOMEWORK 2 SOLUTIONS

HOMEWORK 2 SOLUTIONS HOMEWORK SOLUTIONS CSE 55 RANDOMIZED AND APPROXIMATION ALGORITHMS 1. Questio 1. a) The larger the value of k is, the smaller the expected umber of days util we get all the coupos we eed. I fact if = k

More information

Goodness-of-Fit Tests and Categorical Data Analysis (Devore Chapter Fourteen)

Goodness-of-Fit Tests and Categorical Data Analysis (Devore Chapter Fourteen) Goodess-of-Fit Tests ad Categorical Data Aalysis (Devore Chapter Fourtee) MATH-252-01: Probability ad Statistics II Sprig 2019 Cotets 1 Chi-Squared Tests with Kow Probabilities 1 1.1 Chi-Squared Testig................

More information

CALCULATION OF FIBONACCI VECTORS

CALCULATION OF FIBONACCI VECTORS CALCULATION OF FIBONACCI VECTORS Stuart D. Aderso Departmet of Physics, Ithaca College 953 Daby Road, Ithaca NY 14850, USA email: saderso@ithaca.edu ad Dai Novak Departmet of Mathematics, Ithaca College

More information

Polynomials with Rational Roots that Differ by a Non-zero Constant. Generalities

Polynomials with Rational Roots that Differ by a Non-zero Constant. Generalities Polyomials with Ratioal Roots that Differ by a No-zero Costat Philip Gibbs The problem of fidig two polyomials P(x) ad Q(x) of a give degree i a sigle variable x that have all ratioal roots ad differ by

More information

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability.

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability. CSE 0 Homework 1 Matthias Spriger, A9950078 1 Problem 1 Notatio a b meas that a is matched to b. a < b c meas that b likes c more tha a. Equality idicates a tie. Strog istability Yes, there does always

More information

1 Statement of the Game

1 Statement of the Game ANALYSIS OF THE CHOW-ROBBINS GAME JON LU May 10, 2016 Abstract Flip a coi repeatedly ad stop wheever you wat. Your payoff is the proportio of heads ad you wish to maximize this payoff i expectatio. I this

More information

Math 2784 (or 2794W) University of Connecticut

Math 2784 (or 2794W) University of Connecticut ORDERS OF GROWTH PAT SMITH Math 2784 (or 2794W) Uiversity of Coecticut Date: Mar. 2, 22. ORDERS OF GROWTH. Itroductio Gaiig a ituitive feel for the relative growth of fuctios is importat if you really

More information

CHAPTER 10 INFINITE SEQUENCES AND SERIES

CHAPTER 10 INFINITE SEQUENCES AND SERIES CHAPTER 10 INFINITE SEQUENCES AND SERIES 10.1 Sequeces 10.2 Ifiite Series 10.3 The Itegral Tests 10.4 Compariso Tests 10.5 The Ratio ad Root Tests 10.6 Alteratig Series: Absolute ad Coditioal Covergece

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms Probabilistic aalysis ad Radomized algorithms Referece: CLRS Chapter 5 Topics: Hirig problem Idicatio radom variables Radomized algorithms Huo Hogwei 1 The hirig problem

More information

Bertrand s Postulate

Bertrand s Postulate Bertrad s Postulate Lola Thompso Ross Program July 3, 2009 Lola Thompso (Ross Program Bertrad s Postulate July 3, 2009 1 / 33 Bertrad s Postulate I ve said it oce ad I ll say it agai: There s always a

More information

Lecture 4 The Simple Random Walk

Lecture 4 The Simple Random Walk Lecture 4: The Simple Radom Walk 1 of 9 Course: M36K Itro to Stochastic Processes Term: Fall 014 Istructor: Gorda Zitkovic Lecture 4 The Simple Radom Walk We have defied ad costructed a radom walk {X }

More information

Probability, Expectation Value and Uncertainty

Probability, Expectation Value and Uncertainty Chapter 1 Probability, Expectatio Value ad Ucertaity We have see that the physically observable properties of a quatum system are represeted by Hermitea operators (also referred to as observables ) such

More information

Math 172 Spring 2010 Haiman Notes on ordinary generating functions

Math 172 Spring 2010 Haiman Notes on ordinary generating functions Math 72 Sprig 200 Haima Notes o ordiary geeratig fuctios How do we cout with geeratig fuctios? May eumeratio problems which are ot so easy to hadle by elemetary meas ca be solved usig geeratig fuctios

More information

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer.

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer. 6 Itegers Modulo I Example 2.3(e), we have defied the cogruece of two itegers a,b with respect to a modulus. Let us recall that a b (mod ) meas a b. We have proved that cogruece is a equivalece relatio

More information

Discrete Mathematics for CS Spring 2008 David Wagner Note 22

Discrete Mathematics for CS Spring 2008 David Wagner Note 22 CS 70 Discrete Mathematics for CS Sprig 2008 David Wager Note 22 I.I.D. Radom Variables Estimatig the bias of a coi Questio: We wat to estimate the proportio p of Democrats i the US populatio, by takig

More information

Math 113, Calculus II Winter 2007 Final Exam Solutions

Math 113, Calculus II Winter 2007 Final Exam Solutions Math, Calculus II Witer 7 Fial Exam Solutios (5 poits) Use the limit defiitio of the defiite itegral ad the sum formulas to compute x x + dx The check your aswer usig the Evaluatio Theorem Solutio: I this

More information

Random Walks on Discrete and Continuous Circles. by Jeffrey S. Rosenthal School of Mathematics, University of Minnesota, Minneapolis, MN, U.S.A.

Random Walks on Discrete and Continuous Circles. by Jeffrey S. Rosenthal School of Mathematics, University of Minnesota, Minneapolis, MN, U.S.A. Radom Walks o Discrete ad Cotiuous Circles by Jeffrey S. Rosethal School of Mathematics, Uiversity of Miesota, Mieapolis, MN, U.S.A. 55455 (Appeared i Joural of Applied Probability 30 (1993), 780 789.)

More information

subcaptionfont+=small,labelformat=parens,labelsep=space,skip=6pt,list=0,hypcap=0 subcaption ALGEBRAIC COMBINATORICS LECTURE 8 TUESDAY, 2/16/2016

subcaptionfont+=small,labelformat=parens,labelsep=space,skip=6pt,list=0,hypcap=0 subcaption ALGEBRAIC COMBINATORICS LECTURE 8 TUESDAY, 2/16/2016 subcaptiofot+=small,labelformat=pares,labelsep=space,skip=6pt,list=0,hypcap=0 subcaptio ALGEBRAIC COMBINATORICS LECTURE 8 TUESDAY, /6/06. Self-cojugate Partitios Recall that, give a partitio λ, we may

More information

Output Analysis and Run-Length Control

Output Analysis and Run-Length Control IEOR E4703: Mote Carlo Simulatio Columbia Uiversity c 2017 by Marti Haugh Output Aalysis ad Ru-Legth Cotrol I these otes we describe how the Cetral Limit Theorem ca be used to costruct approximate (1 α%

More information

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016 COMPSCI 330: Desig ad Aalysis of Algorithms 1/19/2016 ad 1/21/2016 Lecturer: Debmalya Paigrahi Divide ad Coquer Scribe: Tiaqi Sog 1 Overview I this lecture, a importat algorithm desig techique called divide-ad-coquer

More information

CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo Coutig Methods CSE 191, Class Note 05: Coutig Methods Computer Sci & Eg Dept SUNY Buffalo c Xi He (Uiversity at Buffalo CSE 191 Discrete Structures 1 / 48 Need for Coutig The problem of coutig the umber

More information

A Combinatoric Proof and Generalization of Ferguson s Formula for k-generalized Fibonacci Numbers

A Combinatoric Proof and Generalization of Ferguson s Formula for k-generalized Fibonacci Numbers Jue 5 00 A Combiatoric Proof ad Geeralizatio of Ferguso s Formula for k-geeralized Fiboacci Numbers David Kessler 1 ad Jeremy Schiff 1 Departmet of Physics Departmet of Mathematics Bar-Ila Uiversity, Ramat

More information

Mathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis

Mathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis Mathematics review for CSCI 303 Sprig 019 Departmet of Computer Sciece College of William & Mary Robert Michael Lewis Copyright 018 019 Robert Michael Lewis Versio geerated: 13 : 00 Jauary 17, 019 Cotets

More information

Lecture 3: August 31

Lecture 3: August 31 36-705: Itermediate Statistics Fall 018 Lecturer: Siva Balakrisha Lecture 3: August 31 This lecture will be mostly a summary of other useful expoetial tail bouds We will ot prove ay of these i lecture,

More information

2.4 - Sequences and Series

2.4 - Sequences and Series 2.4 - Sequeces ad Series Sequeces A sequece is a ordered list of elemets. Defiitio 1 A sequece is a fuctio from a subset of the set of itegers (usually either the set 80, 1, 2, 3,... < or the set 81, 2,

More information

Lecture 1: Basic problems of coding theory

Lecture 1: Basic problems of coding theory Lecture 1: Basic problems of codig theory Error-Correctig Codes (Sprig 016) Rutgers Uiversity Swastik Kopparty Scribes: Abhishek Bhrushudi & Aditya Potukuchi Admiistrivia was discussed at the begiig of

More information

FLOOR AND ROOF FUNCTION ANALOGS OF THE BELL NUMBERS. H. W. Gould Department of Mathematics, West Virginia University, Morgantown, WV 26506, USA

FLOOR AND ROOF FUNCTION ANALOGS OF THE BELL NUMBERS. H. W. Gould Department of Mathematics, West Virginia University, Morgantown, WV 26506, USA INTEGERS: ELECTRONIC JOURNAL OF COMBINATORIAL NUMBER THEORY 7 (2007), #A58 FLOOR AND ROOF FUNCTION ANALOGS OF THE BELL NUMBERS H. W. Gould Departmet of Mathematics, West Virgiia Uiversity, Morgatow, WV

More information

Let us consider the following problem to warm up towards a more general statement.

Let us consider the following problem to warm up towards a more general statement. Lecture 4: Sequeces with repetitios, distributig idetical objects amog distict parties, the biomial theorem, ad some properties of biomial coefficiets Refereces: Relevat parts of chapter 15 of the Math

More information

IP Reference guide for integer programming formulations.

IP Reference guide for integer programming formulations. IP Referece guide for iteger programmig formulatios. by James B. Orli for 15.053 ad 15.058 This documet is iteded as a compact (or relatively compact) guide to the formulatio of iteger programs. For more

More information

62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 +

62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 + 62. Power series Defiitio 16. (Power series) Give a sequece {c }, the series c x = c 0 + c 1 x + c 2 x 2 + c 3 x 3 + is called a power series i the variable x. The umbers c are called the coefficiets of

More information

Basics of Probability Theory (for Theory of Computation courses)

Basics of Probability Theory (for Theory of Computation courses) Basics of Probability Theory (for Theory of Computatio courses) Oded Goldreich Departmet of Computer Sciece Weizma Istitute of Sciece Rehovot, Israel. oded.goldreich@weizma.ac.il November 24, 2008 Preface.

More information

1 of 7 7/16/2009 6:06 AM Virtual Laboratories > 6. Radom Samples > 1 2 3 4 5 6 7 6. Order Statistics Defiitios Suppose agai that we have a basic radom experimet, ad that X is a real-valued radom variable

More information

(A sequence also can be thought of as the list of function values attained for a function f :ℵ X, where f (n) = x n for n 1.) x 1 x N +k x N +4 x 3

(A sequence also can be thought of as the list of function values attained for a function f :ℵ X, where f (n) = x n for n 1.) x 1 x N +k x N +4 x 3 MATH 337 Sequeces Dr. Neal, WKU Let X be a metric space with distace fuctio d. We shall defie the geeral cocept of sequece ad limit i a metric space, the apply the results i particular to some special

More information

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions CSE 09/09 Topics i ig Data Aalytics Sprig 2017; Homework 1 Solutios Note: Solutios to problems,, ad 6 are due to Marius Nicolae. 1. Cosider the followig algorithm: for i := 1 to α log e do Pick a radom

More information

Advanced Stochastic Processes.

Advanced Stochastic Processes. Advaced Stochastic Processes. David Gamarik LECTURE 2 Radom variables ad measurable fuctios. Strog Law of Large Numbers (SLLN). Scary stuff cotiued... Outlie of Lecture Radom variables ad measurable fuctios.

More information

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 19 11/17/2008 LAWS OF LARGE NUMBERS II THE STRONG LAW OF LARGE NUMBERS

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 19 11/17/2008 LAWS OF LARGE NUMBERS II THE STRONG LAW OF LARGE NUMBERS MASSACHUSTTS INSTITUT OF TCHNOLOGY 6.436J/5.085J Fall 2008 Lecture 9 /7/2008 LAWS OF LARG NUMBRS II Cotets. The strog law of large umbers 2. The Cheroff boud TH STRONG LAW OF LARG NUMBRS While the weak

More information

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006 MATH 34 Summer 006 Elemetary Number Theory Solutios to Assigmet Due: Thursday July 7, 006 Departmet of Mathematical ad Statistical Scieces Uiversity of Alberta Questio [p 74 #6] Show that o iteger of the

More information

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 17 Lecturer: David Wagner April 3, Notes 17 for CS 170

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 17 Lecturer: David Wagner April 3, Notes 17 for CS 170 UC Berkeley CS 170: Efficiet Algorithms ad Itractable Problems Hadout 17 Lecturer: David Wager April 3, 2003 Notes 17 for CS 170 1 The Lempel-Ziv algorithm There is a sese i which the Huffma codig was

More information

Vector Quantization: a Limiting Case of EM

Vector Quantization: a Limiting Case of EM . Itroductio & defiitios Assume that you are give a data set X = { x j }, j { 2,,, }, of d -dimesioal vectors. The vector quatizatio (VQ) problem requires that we fid a set of prototype vectors Z = { z

More information