ArticlePDF Available

Dual pivot Quicksort

Authors:

Abstract

In this paper, we analyze the dual pivot Quicksort, a variant of the standard Quicksort algorithm, in which two pivots are used for the partitioning of the array. We are solving recurrences of the expected number of key comparisons and exchanges performed by the algorithm, obtaining the exact and asymptotic total average values contributing to its time complexity. Further, we compute the average number of partitioning stages and the variance of the number of key comparisons. In terms of mean values, dual pivot Quicksort does not appear to be faster than ordinary algorithm.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Discrete Mathematics, Algorithms and Applications
Vol. 4, No. 3 (2012) 1250041 (13 pages)
c
World Scientific Publishing Company
DOI: 10.1142/S1793830912500413
DUAL PIVOT QUICKSORT
VASILEIOS ILIOPOULOSand DAVID B. PENMAN
Department of Mathematical Sciences
University of Essex, Wivenhoe Park
Colchester, CO4 3SQ, UK
viliop@essex.ac.uk
dbpenman@essex.ac.uk
Received 23 March 2012
Revised 18 April 2012
Published 1 August 2012
In this paper, we analyze the dual pivot Quicksort, a variant of the standard Quicksort
algorithm, in which two pivots are used for the partitioning of the array. We are solving
recurrences of the expected number of key comparisons and exchanges performed by the
algorithm, obtaining the exact and asymptotic total average values contributing to its
time complexity. Further, we compute the average number of partitioning stages and
the variance of the number of key comparisons. In terms of mean values, dual pivot
Quicksort does not appear to be faster than ordinary algorithm.
Keywords: Quicksort; sorting algorithm.
Mathematics Subject Classification 2000: 68W40, 60F05
1. Introduction
Quicksort is a sorting algorithm with an extensive literature regarding its mathe-
matical analysis and its applications. Without loss of generality, suppose that we
want to quick sort a random permutation of distinct keys {1,2,...,n}with all the
n! permutations equally likely. A key is randomly chosen as pivot and by pairwise
comparisons of the other elements with it, smaller keys are placed to left and greater
to right. Now, the pivot jis at its final position and the algorithm is recursively
invoked to sort independently the left and right subarrays of (j1) and (nj)
elements, respectively. Letting Cnbeing the number of comparisons for sorting n
keys, its average value is given by the following recursive relation
E(Cn)=n1+ 1
n
n
j=1
(E(Cj1)+E(Cnj))
=n1+ 2
n
n
j=1
E(Cj1),
1250041-1
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
with initial condition C0:= 0. Subtracting (n1)E(Cn1)fromnE(Cn)andtele-
scoping, the average number of comparisons is
E(Cn)=2(n+1)Hn4n2nln(n).(1.1)
Similarly, it is a routine matter to compute that the average number of exchanges
performed is
2(n+1)Hn3n
61
3nln(n),(1.2)
when at the first partitioning stage, the expected number of exchanges is
n
6+5
6n,(From [2]).
Recall that Hnis the nth harmonic number, defined by Hn:= n
j=1 1
jand H0:= 0.
Further, the sign denotes asymptotic equivalence between two functions f(n)and
g(n). That is f(n)g(n) if and only if limn→∞
f(n)
g(n)=1.(In[2,4], it is suggested
that small segments of size less than some parameter mbe sorted by a simpler
algorithm, such as insertion sort, as this is in practice quicker: In order to simplify
the calculations for the solutions of the recurrences, we assume that m=0.)
2. Partitioning on Two Pivots
The idea for this variant is that we can randomly select two elements as pivots
for the partitioning of the array. The number of comparisons obeys the following
recursive rule;
Cn= “Number of comparisons during first partitioning stage”
+Ci1+Cji1+Cnj,
since at the beginning, the pivots are compared each other and swapped if they
are not in order. If elements i<jare selected, the array is partitioned into three
subarrays: One with (i1) keys smaller than i, a subarray of (ji1) keys between
two pivots and the part of (nj) elements greater than j. The algorithm then is
recursively applied to each of these subarrays. The number of comparisons during
the first stage is
An=1+((i1) + 2(ji1) + 2(nj)),i=1,...,n1and
j=i+1,...,n.
because if an element is lower than i, then it is less than jautomatically, so i1
elements beneath ionly need to be compared with one of the pivots. However if an
element is greater than ithen it needs to be compared with the other pivot as well,
1250041-2
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
to determine whether or not it is greater than j. We refer to Sedgewick [4]forcode
for a version of this scheme. The average value of Anis
1
n
2
n1
i=1
n
j=i+1
(1 + (i1) + 2(ji1) + 2(nj))
=1
n
2
n1
i=1
n
j=i+1
(2ni2)
=2
n(n1) 5
6n32n2+7
6n=5n7
3.
Hence, the recurrence for the expected number of comparisons is
E(Cn)= 5n7
3+2
n(n1)
×
n1
i=1
n
j=i+1
E(Ci1)+
n1
i=1
n
j=i+1
E(Cji1)+
n1
i=1
n
j=i+1
E(Cnj)
.
Note that the three double sums above are equal. Therefore, the recurrence becomes
E(Cn)=5n7
3+6
n(n1)
n1
i=1
(ni)E(Ci1).
Letting an=E(Cn), we have
an=5n7
3+6
n(n1)
n1
i=1
(ni)ai1,n2.
Trivially, it holds that a0=a1= 0. Multiplying both sides by n
2,weobtain
n
2an=n
25n7
3+6
n(n1)
n1
i=1
(ni)ai1
=n(n1)(5n7)
6+3
n1
i=1
(ni)ai1.
We introduce the difference operator ∆ for the solution of this recurrence. The
operator is defined by
F(n):=F(n+1)F(n) and for higher orders,
kF(n):=∆
k1F(n+1)k1F(n).
1250041-3
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
Thus, we have
n
2an=n+1
2an+1 n
2an=5n23n
2+3
n1
i=0
ai,
2n
2an=∆
n+1
2an+1 n
2an=5n+1+3an.
By definition,
2n
2an=∆
n+1
2an+1 n
2an
=n+2
2an+2 2n+1
2an+1 +n
2an
and the recurrence becomes
(n+1)(n+2)an+2 2n(n+1)an+1 +n(n1)an
=2(5n+1+3an)(n+ 1)((n+2)an+2 (n2)an+1 )
(n+ 2)((n+1)an+1 (n3)an)=2(5n+1).
Dividing by (n+1)(n+ 2), we obtain the telescoping recurrence
(n+2)an+2 (n2)an+1
n+2 =(n+1)an+1 (n3)an
n+1 +2(5n+1)
(n+1)(n+2),
which yields
(n+2)an+2 (n2)an+1
n+2 =2
n
j=0
5j+1
(j+1)(j+2) =18
n+2+10Hn+1 18.
The recurrence is equivalent to
nan(n4)an1=18+10nHn118n.
Multiplying by (n1)(n2)(n3)
24 , this recurrence is transformed to a telescoping
one [4],
n
4an=n1
4an1+18(n1)(n2)(n3)
24 +10
n
4Hn118n
4.
Unwinding, we have
n
4an=18
n
j=1
(j1)(j2)(j3)
24 +10
n
j=1 j
4Hj118
n
j=1 j
4.(2.1)
Using Maple, we found that
n
j=1
(j1)(j2)(j3) = 6n
4
1250041-4
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
and for the other sums in Eq. (2.1),
n
j=1 j
4=n+1
5and
n
j=1 j
4Hj=n+1
5Hn+1 1
5.
Therefore
n
j=1 j
4Hj1=
n
j=1 j
4Hj1
j=
n
j=1 j
4Hj
n
j=1 j
41
j
=n+1
5Hn+1 1
51
24
n
j=1
(j1)(j2)(j3)
=n+1
5Hn+1 1
5n
41
4.
Now Eq. (2.1) becomes
n
4an=9
2n
4+10n+1
5Hn+1 1
51
4n
418n+1
5.
an=9
2+10n+1
5Hn+1 1
51
418(n+1)
5.
Finally, the expected number of comparisons, when two pivots are chosen is
an=2(n+1)Hn4n2nln(n).(2.2)
This is exactly the same as the expected number of comparisons in Eq. (1.1) com-
puted earlier for ordinary Quicksort. The dual pivot variant is claimed to be faster
in experimental measurements than the standard algorithm in [6]. A referee of this
article commented to us that the variant gives a 30% performance boost on ran-
domly permuted data.
We proceed to compute the average number of exchanges. Letting Sndenote
the total number of exchanges we carry out when sorting nobjects, we have that
Sn= “Number of exchanges during first partitioning stage”
+Si1+Sji1+Snj.
Now it is fairly clear that, again using that the pivots are chosen uniformly at
random, that the average values of last three quantities are equal. So our main
objective now is to determine the average number of exchanges during the first
partitioning stage. At the end of the partition routine, (i1) elements are less than
pivot i. Thus, the contribution to the number of exchanges is [4],
1
n
2
n1
i=1
n
j=i+1
(i1) = 1
n
2
n1
i=1
(ni)(i1) = 1
n
2n1
i=1
(ni)i
n1
i=1
(ni).
1250041-5
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
The first sum being evaluated gives
n1
i=1
(ni)i=n3n
6
and the second is just n(n1)/2. The average contribution is
2
n(n1) n3n
6n(n1)
2=n2
3.
Similarly, the average number of exchanges for the (nj) elements greater than
the second pivot is ( n2
3), since the double sums are equal. Adding the two final
“exchanges” to get the pivots in place, the average number of exchanges during the
partitioning routine is ( 2(n+1)
3). Therefore, the recurrence for the mean number of
exchanges in course of the algorithm is
E(Sn)= 2(n+1)
3+2
n(n1)
×
n1
i=1
n
j=i+1
E(Si1)+
n1
i=1
n
j=i+1
E(Sji1)+
n1
i=1
n
j=i+1
E(Snj)
=2(n+1)
3+6
n(n1)
n1
i=1
n
j=i+1
E(Si1)
=2(n+1)
3+6
n(n1)
n1
i=1
(ni)E(Si1).
This recurrence is solved in [4]: here we present a solution using generating functions.
Letting bn=E(Sn), we have
bn=2(n+1)
3+6
n(n1)
n
i=1
(ni)bi1.
Multiplying by n
2to clear fractions, we have
n
2bn=n
22(n+1)
3+6
n(n1)
n
i=1
(ni)bi1
=n(n1)(n+1)
3+3
n
i=1
(ni)bi1.
1250041-6
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
Multiplying by znand summing over n, in order to obtain the generating function
g(z)=
n=0 bnznof the coefficients bn,
n=0 n
2bnzn=1
3
n=0
n(n1)(n+1)zn+3
n=1
n
i=1
(ni)bi1zn,
z2
2
n=0
n(n1)bnzn2=z2
3
n=0
n(n1)(n+1)zn2+3
n=1
n
i=1
(ni)bi1zn,
z2
2
d2g(z)
dz2=z2
3
d3
dz3
n=0
zn+1+3
n=1
n
i=1
(ni)bi1zn.
The first term on the right-hand side of the previous equation is the third order
derivative of the following geometric series
n=0
zn+1 =z
1zand d3
dz3z
1z=6
(1 z)4,|z|<1.
The double sum is equal to
n=1
n
i=1
(ni)bi1zn=b0z2+(2b0+b1)z3+(3b0+2b1+b2)z4+···
=z2(b0+b1z+b2z2+···)+2z3(b0+b1z+b2z2+···)+···
=(z2+2z3+3z4+···)g(z)
=
n=0
nzn+1g(z).
The sum which multiplies g(z) on the last line is
n=0
nzn+1 =z
1z2
.
Therefore, our recurrence is transformed to the following differential equation
z2
2
d2g(z)
dz2=2z2
(1 z)4+3g(z)z
1z2
.
Changing variables v=1z,wehavethatf(v)=g(1 v). Thus, it holds
dkf(v)
dvk=(1)kdkg(1 v)
dvk.
The differential equation becomes
(1 v)2
2
d2f(v)
dv2=2(1 v)2
v4+3f(v)1v
v2
.
1250041-7
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
Using Maple, the general solution is
f(v)=c1v3+c2
v220 ln(v)+4
25v2,c
1,c
2R.
For the computation of constants, we consider the fact that f(1) = g(0) = 0 and
f(1) = g(0) = 0 (as b0=b1= 0). The resulting system of linear equations in c1
and c2has solution (c1,c
2)=(4
25 ,0). Therefore, the function is
f(v)= 4
25v320 ln(v)+4
25v2.
But, since
(1 z)2=
n=0
(n+1)znand ln(v)
v2=1
(1 z)2ln1
1z,
this can be written as a product of the following two series;
1
(1 z)2ln1
1z
=
n=1
nzn1
n=1
1
nzn
=(1+2z+3z2+4z3+···)z+z2
2+z3
3+z4
4+···
=z+2+1
2z2+3+2
2+1
3z3+4+3
2+2
3+1
4z4+···
=z+(H1+H2)z2+(H1+H2+H3)z3+···
=
n=0
((n+1)Hnn)zn.
Extracting the coefficients and discarding terms for n3, the exact mean number
of exchanges of dual pivot Quicksort is equal to,
bn=4
5((n+1)Hnn)4
25(n+1)
=4
5(n+1)Hn24n+4
25 4
5nln(n).(2.3)
Comparing the expected number of comparisons of this variant with the standard
algorithm, we see that they are identical. However, the mean number of exchanges
is 2.4 times greater than the figure of normal Quicksort.
In the lines that follow, we compute the average number of partitioning stages
E(Pn) of dual pivot Quicksort. The recurrence is much simpler;
Pn=1+Pi1+Pji1+Pnj.
1250041-8
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
Averaging over all n
2pairs of pivots iand jwe have
E(Pn)=1+ 6
n(n1)
n1
i=1
n
j=i+1
E(Pi1)
=1+ 6
n(n1)
n1
i=1
(ni)E(Pi1),
since the sums are equal. Again, we use generating functions for the solution of
the recurrence. Letting f(z)=
n=0 E(Pn)znour recurrence is transformed to the
following differential equation
f(z)z2
2=z2
(1 z)3+3f(z)z
1z2
.
Changing variables x=1zwe have h(x)=f(1 x) and the general solution is
h(x)= c2
x2+x3c11
2x.
Since h(1) = h(1) = 0 the constants are c1=1
10 and c2=2
5. Consequently, the
mean number of partitioning stages is found to be equal to
E(Pn)= 2
5(n+1)1
2.(2.4)
This is smaller than the expected number of stages of ordinary Quicksort, which is
n, when there is no switch to straight insertion for the sorting of small subfiles, [4].
3. Variance
Finally, we set up a recurrence for the computation of the variance of the number
of comparisons of dual pivot Quicksort. Recall that
An=2ni2andE(An)=5n7
3.
By the recurrence relation for the number of comparisons, we have
P(Cn=t)= 1
n
2
n1
i=1
n
j=i+1
P(Cn=t)
=1
n
2
n1
i=1
n
j=i+1
P(An+Ci1+Cji1+Cnj=t),
noting that the resulting subarrays are independently sorted, the above is
1
n
2
n1
i=1
n
j=i+1
l,m
(P(Ci1=l)P(Cji1=m)P(Cnj=tml2n+i+2)).
1250041-9
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
Letting fn(z)=
t=0 P(Cn=t)ztbe the ordinary probability generating function
for the number of comparisons needed to sort nkeys, we obtain
fn(z)= 1
n
2
n1
i=1
n
j=i+1
z2ni2fi1(z)fji1(z)fnj(z).(3.1)
It holds that fn(1) = 1 and f
n(1) = 2(n+1)Hn4n. Moreover, the second order
derivative of Eq. (3.1) evaluated at z= 1 is recursively given by
f
n(1) = 2
n(n1)
n1
i=1
n
j=i+1
(2ni2)2
n1
i=1
n
j=i+1
(2ni2)
+2
n1
i=1
n
j=i+1
(2ni2)E(Ci1)+2
n1
i=1
n
j=i+1
(2ni2)E(Cji1)
+2
n1
i=1
n
j=i+1
(2ni2)E(Cnj)+2
n1
i=1
n
j=i+1
E(Ci1)E(Cji1)
+2
n1
i=1
n
j=i+1
E(Ci1)E(Cnj)+2
n1
i=1
n
j=i+1
E(Cji1)E(Cnj)
+
n1
i=1
n
j=i+1
f
i1(1) +
n1
i=1
n
j=i+1
f
ji1(1) +
n1
i=1
n
j=i+1
f
nj(1)
.
The reader should not be discouraged by this long expression, since many of the
sums are equal. Specifically, the fourth and fifth turn out to be equal and by simple
manipulation of indices, the sums of the products of expected values are equal. The
double sum of the product of the mean number of comparisons can be simplified as
follows:
n1
i=1
n
j=i+1
E(Ci1)E(Cnj)
=
n1
i=1
E(Ci1)
ni1
j=0
E(Cj)
=
n1
i=1 (2iHi14(i1)) 2ni+1
2Hni+ni5(ni)2
2.
The next sum was computed using results from a paper [5], which contains inter-
esting identities and properties of sums involving harmonic numbers.
n1
i=1
ini+1
2Hi1Hni
=
n1
i=1
((i1) + 1)ni+1
2Hi1Hni
1250041-10
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
=
n1
i=1
(i1)ni
2Hi1Hni+
n1
i=1 ni
2Hi1Hni
+
n1
i=1
(i1)(ni)Hi1Hni+
n1
i=1
(ni)Hi1Hni.
The four sums can be evaluated using Corollary 3 in [5].
After some computations in our Maple worksheet,athe recurrence is
f
n(1) = 2(n+1)(n+2)(H2
nH(2)
n)Hn17
3n2+47
3n+6
+209
36 n2+731
36 n+13
6+6
n(n1)
n1
i=1
(ni)f
i1(1),
where H(2)
nis the second order harmonic number defined by H(2)
n:= n
k=1 1
k2.
Letting dn=f
n(1) and subtracting n
2dnfrom n+1
2dn+1,wehave
n
2dn=4n(n+1)(n+2)(H2
nH(2)
n)nHn
9(84n2+ 198n+ 42)
+3
n
i=1
di1+n
9(79n2+ 231n+ 14),
using the identity [4]
H2
n+1 H(2)
n+1 =H2
nH(2)
n+2Hn
n+1.
Further, it holds that
2n
2dn= 12(n+1)(n+2)(H2
nH(2)
n)
Hn(20n2+32n12) + 17n2+37n+3dn.
The previous equation is the same as
n+2
2dn+2 2n+1
2dn+1 +n
2dn
and our recurrence becomes
(n+1)(n+2)dn+2 2n(n+1)dn+1 +n(n1)dn
= 2(12(n+1)(n+2)(H2
nH(2)
n)Hn(20n2+32n12) + 17n2+37n+3dn).
aThe Maple worksheet containing the computations for the variance can be found at the web
page: http://www.essex.ac.uk/maths/staff/profile.aspx?ID=1326.
1250041-11
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
V. Iliopoulos & D. B. Penman
Dividing by (n+1)(n+ 2), we obtain the telescoping recurrence
(n+2)dn+2 (n2)dn+1
n+2
=(n+1)dn+1 (n3)dn
n+1
+2
12(H2
nH(2)
n)Hn(20n2+32n12)
(n+1)(n+2) +17n2+37n
(n+1)(n+2)
with solution
(n+2)dn+2 (n2)dn+1
=(24n2+ 100n+ 104)(H2
n+1 H(2)
n+1)Hn+1 (88n2+ 292n+ 224)
+ 122n2+ 346n+ 224,
which is equivalent to
ndn(n4)dn1
=(24n2+4n)(H2
n1H(2)
n1)Hn1(88n260n8)
+ 122n2142n+20.
Again as before, multiplying both sides by (n1)(n2)(n3)
24 , the recurrence tele-
scopes with solution
f
n(1) = 4(n+1)
2(H2
n+1 H(2)
n+1)4Hn+1 (n+ 1)(4n+3)+23n2+33n+12.
Using the well-known fact that
Var(Cn)=f
n(1) + f
n(1) (f
n(1))2,
the variance of the number of key comparisons of dual pivot Quicksort is
7n24(n+1)
2H(2)
n2(n+1)Hn+13n. (3.2)
The asymptotic figure is
72
3π2n22nln(n)+O(n).(3.3)
Note that the variance of dual pivot Quicksort is identical with the variance
of the ordinary algorithm — see Eq. (3.2) in [3]. Also, in this paper we showed
that the dual pivot Quicksort variant has the same expected number of key com-
parisons as the standard algorithm and as one might expect, the mean number of
stages is smaller than the respective figure of the ordinary algorithm. However, the
expected number of exchanges is notably large. An efficient partitioning procedure
isdescribedinapaperwrittenbyFrazerandMcKellar[1], where they present
and analyze the Samplesort algorithm. It is shown [1] that the expected number
of comparisons of Samplesort slowly approaches the Information — theoretic lower
bound.
1250041-12
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
July 27, 2012 10:38 WSPC/S1793-8309 257-DMAA 1250041
Dual Pivot Quicksort
References
[1] W. D. Frazer and A. C. McKellar, Samplesort: A sampling approach to minimal storage
tree sorting, J. ACM 17(3) (1970) 496–507.
[2] C. A. R. Hoare, Quicksort, Comput. J. 5(1) (1962) 10–16.
[3] C. Knessl and W. Szpankowski, Quicksort algorithm again revisited, Discrete Math.
Theor. Comput. Sci. 3(1999) 43–64.
[4] R. Sedgewick, Quicksort, Ph.D. thesis (Garland Publishing, 1980).
[5] J. Spieß, Some Identities involving Harmonic numbers, Math. Comput. 55 (1990) 192,
839–863.
[6] V. Yaroslavskiy, Replacement of Quicksort in java.util.Arrays with new Dual-Pivot
Quicksort (2009), web page: http://permalink.gmane.org/gmane.comp.java.openjdk.
core-libs.devel/2628.
1250041-13
Discrete Math. Algorithm. Appl. 2012.04. Downloaded from www.worldscientific.com
by UNIVERSITY OF ESSEX PERIODICALS SECTION on 11/07/12. For personal use only.
... It is known to be the unique fixed point of a certain distributional transformation T with zero mean and finite variance. Depending on the results of [1] and [9], we analyze the Multi-pivot Quicksort when we selected k pivots and we study the relationship with Striling numbers of the first kind. ...
Article
Full-text available
In this paper, we study a new version from Dual-pivot Quicksort algorithm when we have some other number of pivots. Hence, we discuss the idea of picking pivots by random way and splitting the list simultaneously according to these. The modified version generalizes these results for multi process. We show that the average number of swaps done by Multi-pivot Quicksort process and we present a special case. Moreover, we obtain a relationship between the average number of swaps of Multi-pivot Quicksort and Stirling numbers of the first kind.
... This finding has obviously been verified by Oracle as they replaced their implementation of Quicksort with Yaroslavskiy's new Dual Pivot Quicksort in the new Java 7. However, recent analytical studies suggest that this may not be the case [15] [20] mainly due to the high number of swaps that Yaroslavskiy's method exhibits. From our study we can confirm the following: ...
Article
Full-text available
An industrial grade Quicksort function along with its new algorithm is presented. Compared to 4 other well known implementations of Quicksort, the new algorithm reduces both the number of comparisons and swaps in most cases while staying close to the best of the 4 in worst cases. We trade space for performance, at the price of n/2 temporary extra spaces in the worst case. Run time tests reveal an overall improvement of at least 15.8% compared to the overall best of the other 4 functions. Furthermore, our function scores a 32.7% run time improvement against Yaroslavskiy's new Dual Pivot Quicksort. Our function is pointer based, which is meant as a replacement for the C/C++ library qsort(). But we also provide an array based function of the same algorithm for easy porting to different programming languages.
... The main contributions in this Chapter are in sections 4.1 and 4.2. The results in the former section were published in the paper [34], where the expected costs related to the time complexity and the second moment of the number of comparisons are computed. The latter section contains the analysis of the generalisation of the algorithm. ...
Thesis
Full-text available
Sorting algorithms have attracted a great deal of attention and study, as they have numerous applications to Mathematics, Computer Science and related fields. In this thesis, we first deal with the mathematical analysis of the Quicksort algorithm and its variants. Specifically, we study the time complexity of the algorithm and we provide a complete demonstration of the variance of the number of comparisons required, a known result but one whose detailed proof is not easy to read out of the literature. We also examine variants of Quicksort, where multiple pivots are chosen for the partitioning of the array. The rest of this work is dedicated to the analysis of finding the true order by further pairwise comparisons when a partial order compatible with the true order is given in advance. We discuss a number of cases where the partially ordered sets arise at random. To this end, we employ results from Graph and Information Theory. Finally, we obtain an alternative bound on the number of linear extensions when the partially ordered set arises from a random graph, and discuss the possible application of Shellsort in merging chains.
Article
Full-text available
Traditional non-virtualized Wireless Sensor Networks (WSNs) suffer from high deployment and maintenance costs, mainly because their applications are embedded in sensor nodes. Virtualization technologies address these challenges by allowing multiple sensing tasks to run over the same deployed WSN infrastructure. However, virtualization comes at an energy-delay cost, making it both essential and challenging to allocate physical and/or virtual resources efficiently to applications with different sensing tasks, especially for delay-sensitive applications. Our goal is to address the challenge of task assignment in virtu-alized WSNs while minimizing the overall energy consumption and meeting the given deadlines. After formulating the problem as an Integer Linear Programming (ILP), we propose a scalable heuristic. We evaluate the performance of our proposed heuristic in different scenarios and compare it with the optimal solution as well as a recent work from literature. The results indicate that our proposed heuristic leads close-to-optimal solutions with good performance in terms of execution time. It shows that the proposed DTA solution can not only achieve up to a 97% reduction of the execution time for small-scale scenarios, as compared to the optimal solution, but it also outperforms the existing benchmarks in terms of successful task execution rate by 100%.
Preprint
Experimental mathematics is an experimental approach to mathematics in which programming and symbolic computation are used to investigate mathematical objects, identify properties and patterns, discover facts and formulas and even automatically prove theorems. With an experimental mathematics approach, this dissertation deals with several combinatorial problems and demonstrates the methodology of experimental mathematics. We start with parking functions and their moments of certain statistics. Then we discuss about spanning trees and "almost diagonal" matrices to illustrate the methodology of experimental mathematics. We also apply experimental mathematics to Quicksort algorithms to study the running time. Finally we talk about the interesting peaceable queens problem.
Article
Using nonlinear difference equations, combined with symbolic computations, we make a detailed study of the running times of numerous variants of the celebrated Quicksort algorithms, where we consider the variants of single-pivot and multi-pivot Quicksort algorithms as discrete probability problems. With nonlinear difference equations, recurrence relations and experimental mathematics techniques, explicit expressions for expectations, variances and even higher moments of their numbers of comparisons and swaps can be obtained. For some variants, Monte Carlo experiments are performed, the numerical results are demonstrated and the scaled limiting distribution is also discussed.
Article
Full-text available
International audience We consider the standard Quicksort algorithm that sorts n distinct keys with all possible n! orderings of keys being equally likely. Equivalently, we analyze the total path length L(n) in a randomly built \emphbinary search tree. Obtaining the limiting distribution of L(n) is still an outstanding open problem. In this paper, we establish an integral equation for the probability density of the number of comparisons L(n). Then, we investigate the large deviations of L(n). We shall show that the left tail of the limiting distribution is much ''thinner'' (i.e., double exponential) than the right tail (which is only exponential). Our results contain some constants that must be determined numerically. We use formal asymptotic methods of applied mathematics such as the WKB method and matched asymptotics.
Article
Let {H_n} denote the nth harmonic number. Explicit formulas for sums of the form sum {a_k}{H_k} or sum {a_k}{H_k}{H_{n - k}} are derived, where the {a_k} are simple functions of k. These identities are generalized in a natural way by means of generating functions.
Article
The methods currently in use and previously proposed for the choice of a root in minimal storage tree sorting are in reality methods for making inefficient statistical estimates of the median of the sequence to be sorted. By making efficient use of the information in a random sample chosen during input of the sequence to be sorted, significant improvements over ordinary minimal storage tree sorting can be made. A procedure is proposed which is a generalization of minimal storage tree sorting and which has the following three properties: (a) There is a significant improvement (over ordinary minimal storage tree sorting) in the expected number of comparisons required to sort the input sequence. (b) The procedure is statistically insensitive to bias in the input sequence. (c) The expected number of comparisons required by the procedure approaches (slowly) the information-theoretic lower bound on the number of comparisons required. The procedure is, therefore, “asymptotically optimal.”
Replacement of Quicksort in java.util.Arrays with new Dual-Pivot Quicksort
  • V Yaroslavskiy
V. Yaroslavskiy, Replacement of Quicksort in java.util.Arrays with new Dual-Pivot Quicksort (2009), web page: http://permalink.gmane.org/gmane.comp.java.openjdk. core-libs.devel/2628. 1250041-13