Content uploaded by Vasileios Iliopoulos
Author content
All content in this area was uploaded by Vasileios Iliopoulos on Jun 16, 2014
Content may be subject to copyright.
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 ILIOPOULOS∗and 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 (j−1) and (n−j)
elements, respectively. Letting Cnbeing the number of comparisons for sorting n
keys, its average value is given by the following recursive relation
E(Cn)=n−1+ 1
n
n
j=1
(E(Cj−1)+E(Cn−j))
=n−1+ 2
n
n
j=1
E(Cj−1),
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 (n−1)E(Cn−1)fromnE(Cn)andtele-
scoping, the average number of comparisons is
E(Cn)=2(n+1)Hn−4n∼2nln(n).(1.1)
Similarly, it is a routine matter to compute that the average number of exchanges
performed is
2(n+1)Hn−3n
6∼1
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”
+Ci−1+Cj−i−1+Cn−j,
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 (i−1) keys smaller than i, a subarray of (j−i−1) keys between
two pivots and the part of (n−j) 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+((i−1) + 2(j−i−1) + 2(n−j)),i=1,...,n−1and
j=i+1,...,n.
because if an element is lower than i, then it is less than jautomatically, so i−1
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
n−1
i=1
n
j=i+1
(1 + (i−1) + 2(j−i−1) + 2(n−j))
=1
n
2
n−1
i=1
n
j=i+1
(2n−i−2)
=2
n(n−1) 5
6n3−2n2+7
6n=5n−7
3.
Hence, the recurrence for the expected number of comparisons is
E(Cn)= 5n−7
3+2
n(n−1)
×
n−1
i=1
n
j=i+1
E(Ci−1)+
n−1
i=1
n
j=i+1
E(Cj−i−1)+
n−1
i=1
n
j=i+1
E(Cn−j)
.
Note that the three double sums above are equal. Therefore, the recurrence becomes
E(Cn)=5n−7
3+6
n(n−1)
n−1
i=1
(n−i)E(Ci−1).
Letting an=E(Cn), we have
an=5n−7
3+6
n(n−1)
n−1
i=1
(n−i)ai−1,n≥2.
Trivially, it holds that a0=a1= 0. Multiplying both sides by n
2,weobtain
n
2an=n
25n−7
3+6
n(n−1)
n−1
i=1
(n−i)ai−1
=n(n−1)(5n−7)
6+3
n−1
i=1
(n−i)ai−1.
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):=∆
k−1F(n+1)−∆k−1F(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=5n2−3n
2+3
n−1
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(n−1)an
=2(5n+1+3an)⇒(n+ 1)((n+2)an+2 −(n−2)an+1 )
−(n+ 2)((n+1)an+1 −(n−3)an)=2(5n+1).
Dividing by (n+1)(n+ 2), we obtain the telescoping recurrence
(n+2)an+2 −(n−2)an+1
n+2 =(n+1)an+1 −(n−3)an
n+1 +2(5n+1)
(n+1)(n+2),
which yields
(n+2)an+2 −(n−2)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−(n−4)an−1=18+10nHn−1−18n.
Multiplying by (n−1)(n−2)(n−3)
24 , this recurrence is transformed to a telescoping
one [4],
n
4an=n−1
4an−1+18(n−1)(n−2)(n−3)
24 +10
n
4Hn−1−18n
4.
Unwinding, we have
n
4an=18
n
j=1
(j−1)(j−2)(j−3)
24 +10
n
j=1 j
4Hj−1−18
n
j=1 j
4.(2.1)
Using Maple, we found that
n
j=1
(j−1)(j−2)(j−3) = 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
5Hn+1 −1
5.
Therefore
n
j=1 j
4Hj−1=
n
j=1 j
4Hj−1
j=
n
j=1 j
4Hj−
n
j=1 j
41
j
=n+1
5Hn+1 −1
5−1
24
n
j=1
(j−1)(j−2)(j−3)
=n+1
5Hn+1 −1
5−n
41
4.
Now Eq. (2.1) becomes
n
4an=9
2n
4+10n+1
5Hn+1 −1
5−1
4n
4−18n+1
5.
⇒an=9
2+10n+1
5Hn+1 −1
5−1
4−18(n+1)
5.
Finally, the expected number of comparisons, when two pivots are chosen is
an=2(n+1)Hn−4n∼2nln(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”
+Si−1+Sj−i−1+Sn−j.
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, (i−1) elements are less than
pivot i. Thus, the contribution to the number of exchanges is [4],
1
n
2
n−1
i=1
n
j=i+1
(i−1) = 1
n
2
n−1
i=1
(n−i)(i−1) = 1
n
2n−1
i=1
(n−i)i−
n−1
i=1
(n−i).
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
n−1
i=1
(n−i)i=n3−n
6
and the second is just n(n−1)/2. The average contribution is
2
n(n−1) n3−n
6−n(n−1)
2=n−2
3.
Similarly, the average number of exchanges for the (n−j) elements greater than
the second pivot is ( n−2
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(n−1)
×
n−1
i=1
n
j=i+1
E(Si−1)+
n−1
i=1
n
j=i+1
E(Sj−i−1)+
n−1
i=1
n
j=i+1
E(Sn−j)
=2(n+1)
3+6
n(n−1)
n−1
i=1
n
j=i+1
E(Si−1)
=2(n+1)
3+6
n(n−1)
n−1
i=1
(n−i)E(Si−1).
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(n−1)
n
i=1
(n−i)bi−1.
Multiplying by n
2to clear fractions, we have
n
2bn=n
22(n+1)
3+6
n(n−1)
n
i=1
(n−i)bi−1
=n(n−1)(n+1)
3+3
n
i=1
(n−i)bi−1.
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(n−1)(n+1)zn+3
∞
n=1
n
i=1
(n−i)bi−1zn,
⇒z2
2
∞
n=0
n(n−1)bnzn−2=z2
3
∞
n=0
n(n−1)(n+1)zn−2+3
∞
n=1
n
i=1
(n−i)bi−1zn,
⇒z2
2
d2g(z)
dz2=z2
3
d3
dz3∞
n=0
zn+1+3
∞
n=1
n
i=1
(n−i)bi−1zn.
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
1−zand d3
dz3z
1−z=6
(1 −z)4,|z|<1.
The double sum is equal to
∞
n=1
n
i=1
(n−i)bi−1zn=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
1−z2
.
Therefore, our recurrence is transformed to the following differential equation
z2
2
d2g(z)
dz2=2z2
(1 −z)4+3g(z)z
1−z2
.
Changing variables v=1−z,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)1−v
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
v2−20 ln(v)+4
25v2,c
1,c
2∈R.
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
25v3−20 ln(v)+4
25v2.
But, since
(1 −z)−2=
∞
n=0
(n+1)znand ln(v)
v2=−1
(1 −z)2ln1
1−z,
this can be written as a product of the following two series;
1
(1 −z)2ln1
1−z
=∞
n=1
nzn−1∞
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)Hn−n)zn.
Extracting the coefficients and discarding terms for n≤3, the exact mean number
of exchanges of dual pivot Quicksort is equal to,
bn=4
5((n+1)Hn−n)−4
25(n+1)
=4
5(n+1)Hn−24n+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+Pi−1+Pj−i−1+Pn−j.
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(n−1)
n−1
i=1
n
j=i+1
E(Pi−1)
=1+ 6
n(n−1)
n−1
i=1
(n−i)E(Pi−1),
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
1−z2
.
Changing variables x=1−zwe have h(x)=f(1 −x) and the general solution is
h(x)= c2
x2+x3c1−1
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=2n−i−2andE(An)=5n−7
3.
By the recurrence relation for the number of comparisons, we have
P(Cn=t)= 1
n
2
n−1
i=1
n
j=i+1
P(Cn=t)
=1
n
2
n−1
i=1
n
j=i+1
P(An+Ci−1+Cj−i−1+Cn−j=t),
noting that the resulting subarrays are independently sorted, the above is
1
n
2
n−1
i=1
n
j=i+1
l,m
(P(Ci−1=l)P(Cj−i−1=m)P(Cn−j=t−m−l−2n+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
n−1
i=1
n
j=i+1
z2n−i−2fi−1(z)fj−i−1(z)fn−j(z).(3.1)
It holds that fn(1) = 1 and f
n(1) = 2(n+1)Hn−4n. Moreover, the second order
derivative of Eq. (3.1) evaluated at z= 1 is recursively given by
f
n(1) = 2
n(n−1)
n−1
i=1
n
j=i+1
(2n−i−2)2−
n−1
i=1
n
j=i+1
(2n−i−2)
+2
n−1
i=1
n
j=i+1
(2n−i−2)E(Ci−1)+2
n−1
i=1
n
j=i+1
(2n−i−2)E(Cj−i−1)
+2
n−1
i=1
n
j=i+1
(2n−i−2)E(Cn−j)+2
n−1
i=1
n
j=i+1
E(Ci−1)E(Cj−i−1)
+2
n−1
i=1
n
j=i+1
E(Ci−1)E(Cn−j)+2
n−1
i=1
n
j=i+1
E(Cj−i−1)E(Cn−j)
+
n−1
i=1
n
j=i+1
f
i−1(1) +
n−1
i=1
n
j=i+1
f
j−i−1(1) +
n−1
i=1
n
j=i+1
f
n−j(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:
n−1
i=1
n
j=i+1
E(Ci−1)E(Cn−j)
=
n−1
i=1
E(Ci−1)
n−i−1
j=0
E(Cj)
=
n−1
i=1 (2iHi−1−4(i−1)) 2n−i+1
2Hn−i+n−i−5(n−i)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.
n−1
i=1
in−i+1
2Hi−1Hn−i
=
n−1
i=1
((i−1) + 1)n−i+1
2Hi−1Hn−i
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
=
n−1
i=1
(i−1)n−i
2Hi−1Hn−i+
n−1
i=1 n−i
2Hi−1Hn−i
+
n−1
i=1
(i−1)(n−i)Hi−1Hn−i+
n−1
i=1
(n−i)Hi−1Hn−i.
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
n−H(2)
n)−Hn17
3n2+47
3n+6
+209
36 n2+731
36 n+13
6+6
n(n−1)
n−1
i=1
(n−i)f
i−1(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
n−H(2)
n)−nHn
9(84n2+ 198n+ 42)
+3
n
i=1
di−1+n
9(79n2+ 231n+ 14),
using the identity [4]
H2
n+1 −H(2)
n+1 =H2
n−H(2)
n+2Hn
n+1.
Further, it holds that
∆2n
2dn= 12(n+1)(n+2)(H2
n−H(2)
n)
−Hn(20n2+32n−12) + 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(n−1)dn
= 2(12(n+1)(n+2)(H2
n−H(2)
n)−Hn(20n2+32n−12) + 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 −(n−2)dn+1
n+2
=(n+1)dn+1 −(n−3)dn
n+1
+2
12(H2
n−H(2)
n)−Hn(20n2+32n−12)
(n+1)(n+2) +17n2+37n
(n+1)(n+2)
with solution
(n+2)dn+2 −(n−2)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−(n−4)dn−1
=(24n2+4n)(H2
n−1−H(2)
n−1)−Hn−1(88n2−60n−8)
+ 122n2−142n+20.
Again as before, multiplying both sides by (n−1)(n−2)(n−3)
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
7n2−4(n+1)
2H(2)
n−2(n+1)Hn+13n. (3.2)
The asymptotic figure is
7−2
3π2n2−2nln(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.