SlideShare a Scribd company logo
1 of 62
Download to read offline
Quickselect under
Yaroslavskiy’s Dual-Pivoting Algorithm
Sebastian Wild Markus E. Nebel Hosam Mahmoud
wild@cs.uni-kl.de
Computer Science Department
28 May 2013
AofA 2013
Menorca
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 1 / 17
Selection
Consider the following problem
The Selection Problem
Given an unsorted array A of n data elements,
find the m-th smallest element.
Applications
estimate distribution of data collection in statistics
world rankings in sports
Algorithms
trivial solution: sort(A); return A[m]; O(n log n)
linear worst case possible: Median-of-Medians (Blum et al.)
but rather slow in practice (compared to sorting!)
Hoare 1961: Quicksort idea usable for selection
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 2 / 17
From Quicksort to Quickselect
Sort whole array by Quicksort
Markus Nebel just showed:
Yaroslavskiy’s partitioning can speed up Quicksort
Does success of dual partitioning in sorting carry over to selection?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
From Quicksort to Quickselect
Can prune many branches
Markus Nebel just showed:
Yaroslavskiy’s partitioning can speed up Quicksort
Does success of dual partitioning in sorting carry over to selection?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
From Quicksort to Quickselect
Can prune many branches Dual Pivot Quicksort
Markus Nebel just showed:
Yaroslavskiy’s partitioning can speed up Quicksort
Does success of dual partitioning in sorting carry over to selection?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
From Quicksort to Quickselect
Can prune many branches Prune even more branches
Markus Nebel just showed:
Yaroslavskiy’s partitioning can speed up Quicksort
Does success of dual partitioning in sorting carry over to selection?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
From Quicksort to Quickselect
Can prune many branches Prune even more branches
Markus Nebel just showed:
Yaroslavskiy’s partitioning can speed up Quicksort
Does success of dual partitioning in sorting carry over to selection?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
Notation
Analyse (random) number of data comparisons C
(m)
n
to select from random permutation
P < Q: (random) ranks of the two pivots
subarray sizes determined by P and Q:
left P rightQmiddle
J1 := P − 1 J2 := Q − P − 1 J3 := n − Q
selection continues recursively in
left subarray, if m < P
middle subarray, if P < m < Q
right subarray, if Q < m
or terminates if m = P or m = Q
corresponding events
E1 := {m < P}
E2 := {P < m < Q}
E3 := {Q < m}
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
Notation
Analyse (random) number of data comparisons C
(m)
n
to select from random permutation
P < Q: (random) ranks of the two pivots
subarray sizes determined by P and Q:
left P rightQmiddle
J1 := P − 1 J2 := Q − P − 1 J3 := n − Q
selection continues recursively in
left subarray, if m < P
middle subarray, if P < m < Q
right subarray, if Q < m
or terminates if m = P or m = Q
corresponding events
E1 := {m < P}
E2 := {P < m < Q}
E3 := {Q < m}
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
Notation
Analyse (random) number of data comparisons C
(m)
n
to select from random permutation
P < Q: (random) ranks of the two pivots
subarray sizes determined by P and Q:
left P rightQmiddle
J1 := P − 1 J2 := Q − P − 1 J3 := n − Q
selection continues recursively in
left subarray, if m < P
middle subarray, if P < m < Q
right subarray, if Q < m
or terminates if m = P or m = Q
corresponding events
E1 := {m < P}
E2 := {P < m < Q}
E3 := {Q < m}
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
Quickselect Recurrence
Yaroslavskiy’s partitioning preserves randomness
can set up recurrence for the distribution of C
(m)
n :
C
(m)
n
D
= Tn +



C
(m)
J1
if m lies in left subarray
C
(m−P)
J2
if m lies in middle subarray
C
(m−Q)
J3
if m lies in right subarray
= Tn + 1E1
· C
(m)
J1
+ 1E2
· C
(m−P)
J2
+ 1E3
· C
(m−Q)
J3
Tn is the (random) number of comparisons during partitioning
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 5 / 17
Getting Rid of m
Complication: second parameter m in recurrence
C
(m)
n
D
= Tn + 1E1
· C
(m)
J1
+ 1E2
· C
(m−P)
J2
+ 1E3
· C
(m−Q)
J3
consider simpler quantities
1 Random Rank: m = Mn
D
= Uniform {1, . . . , n}
abbreviate ¯Cn := C
(Mn)
n
← focus in talk
¯Cn
D
= Tn+ 1E1
¯CJ1
+ 1E2
¯CJ2
+ 1E3
¯CJ3
2 Extreme Rank: m = 1
abbreviate ˆCn := C
(1)
n
ˆCn
D
= Tn + ˆCP−1
explicit solution for expectations possible (generating functions)
But: Requires tedious computations
More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
Getting Rid of m
Complication: second parameter m in recurrence
C
(m)
n
D
= Tn + 1E1
· C
(m)
J1
+ 1E2
· C
(m−P)
J2
+ 1E3
· C
(m−Q)
J3
consider simpler quantities
1 Random Rank: m = Mn
D
= Uniform {1, . . . , n}
abbreviate ¯Cn := C
(Mn)
n
← focus in talk
¯Cn
D
= Tn+ 1E1
¯CJ1
+ 1E2
¯CJ2
+ 1E3
¯CJ3
2 Extreme Rank: m = 1
abbreviate ˆCn := C
(1)
n
ˆCn
D
= Tn + ˆCP−1
explicit solution for expectations possible (generating functions)
But: Requires tedious computations
More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
Getting Rid of m
Complication: second parameter m in recurrence
C
(m)
n
D
= Tn + 1E1
· C
(m)
J1
+ 1E2
· C
(m−P)
J2
+ 1E3
· C
(m−Q)
J3
consider simpler quantities
1 Random Rank: m = Mn
D
= Uniform {1, . . . , n}
abbreviate ¯Cn := C
(Mn)
n
← focus in talk
¯Cn
D
= Tn+ 1E1
¯CJ1
+ 1E2
¯CJ2
+ 1E3
¯CJ3
2 Extreme Rank: m = 1
abbreviate ˆCn := C
(1)
n
ˆCn
D
= Tn + ˆCP−1
explicit solution for expectations possible (generating functions)
But: Requires tedious computations
More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]?
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
Convergence
Idea: Computation easy if we can drop index n
i. e. when recurrence “in equilibrium”
For that, we need stochastic convergence of ¯Cn
0 100 200 300 400 500 600
99.9% massn = 10
n = 20
n = 30
n = 40
¯Cn
But:
E[ ¯Cn] grows with n
high mass region moves with n
¯Cn does not converge
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 7 / 17
Convergence
Idea: Computation easy if we can drop index n
i. e. when recurrence “in equilibrium”
Try normalized variables ¯C∗
n :=
¯Cn
n
instead:
0 2 4 6 8 10 12 14 16 18
99.9% massn = 10
n = 20
n = 30
n = 40
¯Cn/n
E[ ¯C∗
n] seems constant
range of high mass looks bounded
¯C∗
n might converge
Works because of property of Quickselect: E[ ¯Cn] = O Var( ¯Cn)
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 7 / 17
The Contraction Method
Rewrite recurrence: (Write as sum)
¯Cn
D
= Tn + 1E1
¯CJ1
+ 1E2
¯CJ2
+ 1E3
¯CJ3
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Rewrite recurrence: (Divide by n)
¯Cn
D
= Tn +
3
i=1
1Ei
¯CJi
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Rewrite recurrence: (Rearrange)
¯Cn
n
D
=
Tn
n
+
3
i=1
1Ei
¯CJi
n
·
Ji
Ji
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Rewrite recurrence: (use normalized variables)
¯Cn
n
D
=
Tn
n
+
3
i=1
1Ei
Ji
n
·
¯CJi
Ji
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Recurrence for ¯C∗
n
¯C∗
n
D
= T∗
n +
3
i=1
1Ei
Ji
n
· ¯C∗
Ji
with T∗
n :=
Tn
n
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Recurrence for ¯C∗
n
¯C∗
n
D
= T∗
n +
3
i=1
1Ei
Ji
n
· ¯C∗
Ji
↓ ↓
T∗ A∗
i
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Recurrence for ¯C∗
n
¯C∗
n
D
= T∗
n +
3
i=1
1Ei
Ji
n
· ¯C∗
Ji
↓ ↓
3
i=1
E |A∗
i | < 1
T∗ A∗
i
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
Recurrence for ¯C∗
n
¯C∗
n
D
= T∗
n +
3
i=1
1Ei
Ji
n
· ¯C∗
Ji
↓ ↓ ↓ ↓
3
i=1
E |A∗
i | < 1
¯C∗ D
= T∗ +
3
i=1
A∗
i · ¯C∗
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
“Equilibrium” equation for ¯C∗
¯C∗ D
= T∗ +
3
i=1
A∗
i · ¯C∗
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
“Equilibrium” equation for ¯C∗
(Take expectation on both sides)
¯C∗ D
= T∗ +
3
i=1
A∗
i · ¯C∗
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
“Equilibrium” equation for ¯C∗
(and solve for E ¯C∗)
E ¯C∗ = E T∗+
3
i=1
E A∗
i · E ¯C∗
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
“Equilibrium” equation for ¯C∗
(and solve for E ¯C∗)
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
The Contraction Method
“Equilibrium” equation for ¯C∗
(and solve for E ¯C∗)
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i
Contraction Method:
Convergence of coefficients + contraction condition
implies convergence to fixpoint solution.
have to show: (all convergences in L1-norm)
1 T∗
n → T∗
2 1Ei
Ji
n → A∗
i . . . upcoming
3
3
i=1 E |A∗
i | < 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
induces pivot values: U1 = S1, U2 = S1 + S2
0
0.5
1 0 0.5 1
0
0.5
1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
U1 U2
induces pivot values: U1 = S1, U2 = S1 + S2
0
0.5
1 0 0.5 1
0
0.5
1
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
U1 U2
J1 J2 J3
S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large)
n − 2 elements to draw conditional on S
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
U1 U2
J1 J2 J3
S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large)
n − 2 elements to draw conditional on S
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
U1 U2
J1 J2 J3
S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large)
n − 2 elements to draw conditional on S
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1
S1 S2 S3
U1 U2
J1 J2 J3
S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large)
n − 2 elements to draw conditional on S
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1U1U1 U2 U2
Continue of sub-interval with smaller n
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Probabilistic Model
Need “convenient” probabilistic model:
same probability space for finite n and limit case
Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1)
0 1U1 U2
first two = pivots values
Our equivalent model:
1 Draw spacings S1, S2, S3 on (0, 1) with S
D
= Dirichlet(1, 1, 1)
2 Draw subarray sizes J1, J2, J3 with J
D
= Multinomial(n − 2; S1, S2,S3)
3 Continue recursively
0 1U1U1 U2 U2
Continue of sub-interval with smaller n
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
Distribution of Tn — Repetition
1 T∗
n → T∗
Invariant: < p
→
> qg
←
p ◦ q k
→
k’s range K G
Tn = number of comparisons in first partitioning step
∼ n one for every element
+ J2 second for all medium elements
+ l @ K second for large elements at Ck
+ s@ G second for small elements at Cg
Markus Nebel just showed:
l @ K
D
= Hypergeometric(n − 2; J3 , J1 + J2 )
conditional on J
s@ G
D
= Hypergeometric(n − 2; J1 , J3 )
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
Distribution of Tn — Repetition
1 T∗
n → T∗
Invariant: < p
→
> qg
←
p ◦ q k
→
k’s range K G
Tn = number of comparisons in first partitioning step
∼ n one for every element
+ J2 second for all medium elements
+ l @ K second for large elements at Ck
+ s@ G second for small elements at Cg
Markus Nebel just showed:
l @ K
D
= Hypergeometric(n − 2; J3 , J1 + J2 )
conditional on J
s@ G
D
= Hypergeometric(n − 2; J1 , J3 )
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
Distribution of Tn — Repetition
1 T∗
n → T∗
Invariant: < p
→
> qg
←
p ◦ q k
→
k’s range K G
Tn = number of comparisons in first partitioning step
∼ n one for every element
+ J2 second for all medium elements
+ l @ K second for large elements at Ck
+ s@ G second for small elements at Cg
Markus Nebel just showed:
l @ K
D
= Hypergeometric(n − 2; J3 , J1 + J2 )
conditional on J
s@ G
D
= Hypergeometric(n − 2; J1 , J3 )
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
Convergence of T∗
n
1 T∗
n → T∗
T∗
n =
Tn
n
= 1 +
J2
n
+
l @ K
n
+
s@ G
n
J2
n
→ S2 by law of large numbers, since E[Ji | S] = n · Si
Multinomial and Hypergeometric concentrated around mean
l @ K
n
→ E
l @ K
n
S by Chernoff bound arguments
= E
E l @ K | J
n
S = E
J3 ( J1 + J2 )
n(n − 2)
S
∼ S3 · (S1 + S2)
s@ G
n
→ S1 · S3 similar
T∗
n → T∗ = 1 + S2 + S3(2S1 + S2)
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
Convergence of T∗
n
1 T∗
n → T∗
T∗
n =
Tn
n
= 1 +
J2
n
+
l @ K
n
+
s@ G
n
J2
n
→ S2 by law of large numbers, since E[Ji | S] = n · Si
Multinomial and Hypergeometric concentrated around mean
l @ K
n
→ E
l @ K
n
S by Chernoff bound arguments
= E
E l @ K | J
n
S = E
J3 ( J1 + J2 )
n(n − 2)
S
∼ S3 · (S1 + S2)
s@ G
n
→ S1 · S3 similar
T∗
n → T∗ = 1 + S2 + S3(2S1 + S2)
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
Convergence of T∗
n
1 T∗
n → T∗
T∗
n =
Tn
n
= 1 +
J2
n
+
l @ K
n
+
s@ G
n
J2
n
→ S2 by law of large numbers, since E[Ji | S] = n · Si
Multinomial and Hypergeometric concentrated around mean
l @ K
n
→ E
l @ K
n
S by Chernoff bound arguments
= E
E l @ K | J
n
S = E
J3 ( J1 + J2 )
n(n − 2)
S
∼ S3 · (S1 + S2)
s@ G
n
→ S1 · S3 similar
T∗
n → T∗ = 1 + S2 + S3(2S1 + S2)
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
Convergence of Coefficients & Contraction Condition
2 1Ei
Ji
n → A∗
i
standard computation:
1E1
J1
n
→ 1F1
· S1 with F1 = {V < S1}
i = 2, 3 similar
3
3
i=1 E |A∗
i | < 1
E 1F1
S1 = 1
6
by symmetry:
3
i=1
E |A∗
i | = 1
2 < 1
We (finally) proved convergence ¯C∗
n → ¯C∗.
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
Convergence of Coefficients & Contraction Condition
2 1Ei
Ji
n → A∗
i
standard computation:
1E1
J1
n
→ 1F1
· S1 with F1 = {V < S1}
i = 2, 3 similar
3
3
i=1 E |A∗
i | < 1
E 1F1
S1 = 1
6
by symmetry:
3
i=1
E |A∗
i | = 1
2 < 1
We (finally) proved convergence ¯C∗
n → ¯C∗.
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
Convergence of Coefficients & Contraction Condition
2 1Ei
Ji
n → A∗
i
standard computation:
1E1
J1
n
→ 1F1
· S1 with F1 = {V < S1}
i = 2, 3 similar
3
3
i=1 E |A∗
i | < 1
E 1F1
S1 = 1
6
by symmetry:
3
i=1
E |A∗
i | = 1
2 < 1
We (finally) proved convergence ¯C∗
n → ¯C∗.
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
Results — Expectations
Computing expectations and plugging in . . .
E T∗ = 19
12
Recall:
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i3
i=1 E A∗
i = 1
2
E ¯C∗ = 19
6 = 3.16
L1 convergence E ¯Cn ∼ 3.16n
similarly: E ˆCn ∼ 2.375n
Comparisons Swaps
0
1
2
3
+5.55%
+100%
random rank
Classic Quickselect
Yaroslavskiy Select
Comparisons Swaps
0
1
2
+18.8%
+125%
extreme rank
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
Results — Expectations
Computing expectations and plugging in . . .
E T∗ = 19
12
Recall:
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i3
i=1 E A∗
i = 1
2
E ¯C∗ = 19
6 = 3.16
L1 convergence E ¯Cn ∼ 3.16n
similarly: E ˆCn ∼ 2.375n
Comparisons Swaps
0
1
2
3
+5.55%
+100%
random rank
Classic Quickselect
Yaroslavskiy Select
Comparisons Swaps
0
1
2
+18.8%
+125%
extreme rank
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
Results — Expectations
Computing expectations and plugging in . . .
E T∗ = 19
12
Recall:
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i3
i=1 E A∗
i = 1
2
E ¯C∗ = 19
6 = 3.16
L1 convergence E ¯Cn ∼ 3.16n
similarly: E ˆCn ∼ 2.375n
Comparisons Swaps
0
1
2
3
+5.55%
+100%
random rank
Classic Quickselect
Yaroslavskiy Select
Comparisons Swaps
0
1
2
+18.8%
+125%
extreme rank
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
Results — Expectations
Computing expectations and plugging in . . .
E T∗ = 19
12
Recall:
E ¯C∗ =
E T∗
1 − 3
i=1 E A∗
i3
i=1 E A∗
i = 1
2
E ¯C∗ = 19
6 = 3.16
L1 convergence E ¯Cn ∼ 3.16n
similarly: E ˆCn ∼ 2.375n
Comparisons Swaps
0
1
2
3
+5.55%
+100%
random rank
Classic Quickselect
Yaroslavskiy Select
Comparisons Swaps
0
1
2
+18.8%
+125%
extreme rank
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
Pivot Sampling
successful optimization of Quicksort/-select: median of three
Here: generalized pivot selection scheme
1 Choose random sample of k elements
2 Sort the sample
3 Select pivots s. t. in sorted sample
t1 smaller ,
t2 between and
t3 larger than pivots
Example with
k = 8 and t = (3, 2, 1):
U1 U2
t1 t2 t3
Our stochastic model nicely generalizes to pivot sampling:
only the distribution of spacings S changes!
S
D
= Dirichlet(t1 + 1, t2 + 1, t3 + 1) density: f(s) =
s
t1
1 s
t2
2 s
t3
3
B
contraction conditions remain valid
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 14 / 17
Pivot Sampling
successful optimization of Quicksort/-select: median of three
Here: generalized pivot selection scheme
1 Choose random sample of k elements
2 Sort the sample
3 Select pivots s. t. in sorted sample
t1 smaller ,
t2 between and
t3 larger than pivots
Example with
k = 8 and t = (3, 2, 1):
U1 U2
t1 t2 t3
Our stochastic model nicely generalizes to pivot sampling:
only the distribution of spacings S changes!
S
D
= Dirichlet(t1 + 1, t2 + 1, t3 + 1) density: f(s) =
s
t1
1 s
t2
2 s
t3
3
B
contraction conditions remain valid
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 14 / 17
Results — Pivot Sampling
General result: ¯Cn ∼
1 + t2+1
k+1 +
(2(t1+1)+(t2+1))(t3+1)
(k+1)2
1 − 3
i=1
(ti+1)2
(k+1)2
· n
inconvenient for interpretation . . .
Limiting case for large sample:
ti
k
→ αi as k → ∞
= take exact quantiles as pivots
¯Cn ∼
1 + α2 + (2α1 + α2)α3
1 − 3
i=1α2
i
· n
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
α1
α2
optimal choice is not symmetric
classic Quickselect with median of 2t + 1:
2.5n for t = 1 and 2.3n for t = 2
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
Results — Pivot Sampling
General result: ¯Cn ∼
1 + t2+1
k+1 +
(2(t1+1)+(t2+1))(t3+1)
(k+1)2
1 − 3
i=1
(ti+1)2
(k+1)2
· n
inconvenient for interpretation . . .
Limiting case for large sample:
ti
k
→ αi as k → ∞
= take exact quantiles as pivots
¯Cn ∼
1 + α2 + (2α1 + α2)α3
1 − 3
i=1α2
i
· n
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
α1
α2
optimal choice is not symmetric
classic Quickselect with median of 2t + 1:
2.5n for t = 1 and 2.3n for t = 2
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
Results — Pivot Sampling
General result: ¯Cn ∼
1 + t2+1
k+1 +
(2(t1+1)+(t2+1))(t3+1)
(k+1)2
1 − 3
i=1
(ti+1)2
(k+1)2
· n
inconvenient for interpretation . . .
Limiting case for large sample:
ti
k
→ αi as k → ∞
= take exact quantiles as pivots
¯Cn ∼
1 + α2 + (2α1 + α2)α3
1 − 3
i=1α2
i
· n
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
α1
α2
optimal choice is not symmetric
classic Quickselect with median of 2t + 1:
2.5n for t = 1 and 2.3n for t = 2
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
Results — Pivot Sampling
General result: ¯Cn ∼
1 + t2+1
k+1 +
(2(t1+1)+(t2+1))(t3+1)
(k+1)2
1 − 3
i=1
(ti+1)2
(k+1)2
· n
inconvenient for interpretation . . .
Limiting case for large sample:
ti
k
→ αi as k → ∞
= take exact quantiles as pivots
¯Cn ∼
1 + α2 + (2α1 + α2)α3
1 − 3
i=1α2
i
· n
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
2.4654
2.5
α1
α2
optimal choice is not symmetric
classic Quickselect with median of 2t + 1:
2.5n for t = 1 and 2.3n for t = 2
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
Conclusion
Practitioners’ Lesson:
Yaroslavskiy’s dual-pivoting not helpful for selection
Analyzers’ Lesson:
expected costs of Quickselect derivable by contraction method
pivot sampling included naturally
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 16 / 17
References & Further Reading
M. Blum, R. W. Floyd, V. Pratt, R. L. Rivest and R. E. Tarjan.
Time bounds for selection.
J. of Comp. and System Sc., 7(4):448–461, 1973.
C. A. R. Hoare.
Algorithm 65: Find.
Communications of the ACM, 4(7):321–322, July 1961.
H.-K. Hwang and T.-H. Tsai.
Quickselect and Dickman function.
Combinatorics, Probability and Computing, 11, 2000.
Hosam M. Mahmoud.
Sorting: A distribution theory.
John Wiley & Sons, Hoboken, NJ, USA, 2000.
H. M. Mahmoud, R. Modarres and R. T. Smythe.
Analysis of quickselect : an algorithm for order statistics.
Informatique théorique et appl., 29(4):255–276, 1995.
C. Martínez, D. Panario and A. Viola.
Adaptive sampling strategies for quickselects.
ACM Transactions on Algorithms, 6(3):1–45, June 2010.
C. Martínez and S. Roura.
Optimal Sampling Strategies in Quicksort and Quickselect.
SIAM Journal on Computing, 31(3):683, 2001.
R. Neininger.
On a multivariate contraction method for random
recursive structures with applications to Quicksort.
Random Structures & Alg., 19(3-4):498–524, 2001.
R. Neininger and L. Rüschendorf.
A General Limit Theorem for Recursive Algorithms and
Combinatorial Structures.
The Annals of Applied Probability, 14(1):378–418, 2004.
A. Panholzer and H. Prodinger.
A generating functions approach for the analysis of
grand averages for multiple QUICKSELECT.
Random Structures & Alg., 13(3-4):189–209, 1998.
U. Rösler and L. Rüschendorf.
The contraction method for recursive algorithms.
Algorithmica, 29(1):3–33, 2001.
S. Wild.
Java 7’s Dual Pivot Quicksort.
Master thesis, University of Kaiserslautern, 2012.
S. Wild, M. E. Nebel and H. Mahmoud.
Analysis of Quickselect under
Yaroslavskiy’s Dual-Pivoting Algorithm.
Algorithmica, in preparation.
S. Wild, M. E. Nebel and R. Neininger.
Average Case and Distributional Analysis of
Java 7’s Dual Pivot Quicksort.
ACM Transactions on Algorithms, submitted.
V. Yaroslavskiy.
Dual-Pivot Quicksort.
2009.
Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 17 / 17

More Related Content

What's hot

Large variance and fat tail of damage by natural disaster
Large variance and fat tail of damage by natural disasterLarge variance and fat tail of damage by natural disaster
Large variance and fat tail of damage by natural disasterHang-Hyun Jo
 
2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machinenozomuhamada
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landauangely alcendra
 
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...Abimbola Ashaju
 
FDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABFDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABAya Zaki
 
2012 mdsp pr08 nonparametric approach
2012 mdsp pr08 nonparametric approach2012 mdsp pr08 nonparametric approach
2012 mdsp pr08 nonparametric approachnozomuhamada
 
2012 mdsp pr04 monte carlo
2012 mdsp pr04 monte carlo2012 mdsp pr04 monte carlo
2012 mdsp pr04 monte carlonozomuhamada
 
PosterPresentations.com-3 6x48-Template-V5 - 副本
PosterPresentations.com-3 6x48-Template-V5 - 副本PosterPresentations.com-3 6x48-Template-V5 - 副本
PosterPresentations.com-3 6x48-Template-V5 - 副本Yijun Zhou
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical EngineeringDebarun Banerjee
 
Application of Numerical Methods (Finite Difference) in Heat Transfer
Application of Numerical Methods (Finite Difference) in Heat TransferApplication of Numerical Methods (Finite Difference) in Heat Transfer
Application of Numerical Methods (Finite Difference) in Heat TransferShivshambhu Kumar
 
Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Nagesh NARASIMHA PRASAD
 

What's hot (20)

Large variance and fat tail of damage by natural disaster
Large variance and fat tail of damage by natural disasterLarge variance and fat tail of damage by natural disaster
Large variance and fat tail of damage by natural disaster
 
2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine2012 mdsp pr13 support vector machine
2012 mdsp pr13 support vector machine
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
 
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...
Alternating direction-implicit-finite-difference-method-for-transient-2 d-hea...
 
Fortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESVFortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESV
 
FDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABFDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLAB
 
2012 mdsp pr08 nonparametric approach
2012 mdsp pr08 nonparametric approach2012 mdsp pr08 nonparametric approach
2012 mdsp pr08 nonparametric approach
 
CLIM Fall 2017 Course: Statistics for Climate Research, Nonstationary Covaria...
CLIM Fall 2017 Course: Statistics for Climate Research, Nonstationary Covaria...CLIM Fall 2017 Course: Statistics for Climate Research, Nonstationary Covaria...
CLIM Fall 2017 Course: Statistics for Climate Research, Nonstationary Covaria...
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Fdtd
FdtdFdtd
Fdtd
 
2012 mdsp pr04 monte carlo
2012 mdsp pr04 monte carlo2012 mdsp pr04 monte carlo
2012 mdsp pr04 monte carlo
 
PosterPresentations.com-3 6x48-Template-V5 - 副本
PosterPresentations.com-3 6x48-Template-V5 - 副本PosterPresentations.com-3 6x48-Template-V5 - 副本
PosterPresentations.com-3 6x48-Template-V5 - 副本
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Implicit schemes for wave models
Implicit schemes for wave modelsImplicit schemes for wave models
Implicit schemes for wave models
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
 
4017
40174017
4017
 
CMB Likelihood Part 1
CMB Likelihood Part 1CMB Likelihood Part 1
CMB Likelihood Part 1
 
Application of Numerical Methods (Finite Difference) in Heat Transfer
Application of Numerical Methods (Finite Difference) in Heat TransferApplication of Numerical Methods (Finite Difference) in Heat Transfer
Application of Numerical Methods (Finite Difference) in Heat Transfer
 
Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.
 

Viewers also liked

Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAnEngineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAnSebastian Wild
 
Quicksort with Equal Keys
Quicksort with Equal KeysQuicksort with Equal Keys
Quicksort with Equal KeysSebastian Wild
 
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Sebastian Wild
 
Analysis of branch misses in Quicksort
Analysis of branch misses in QuicksortAnalysis of branch misses in Quicksort
Analysis of branch misses in QuicksortSebastian Wild
 
Average Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot QuicksortAverage Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot QuicksortSebastian Wild
 
Dual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in SortingDual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in SortingSebastian Wild
 
Pivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot QuicksortPivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot QuicksortSebastian Wild
 

Viewers also liked (7)

Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAnEngineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
 
Quicksort with Equal Keys
Quicksort with Equal KeysQuicksort with Equal Keys
Quicksort with Equal Keys
 
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
 
Analysis of branch misses in Quicksort
Analysis of branch misses in QuicksortAnalysis of branch misses in Quicksort
Analysis of branch misses in Quicksort
 
Average Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot QuicksortAverage Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot Quicksort
 
Dual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in SortingDual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in Sorting
 
Pivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot QuicksortPivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot Quicksort
 

Similar to Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm

Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...
Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...
Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...Shizuoka Inst. Science and Tech.
 
International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1IJEMM
 
Linear models for classification
Linear models for classificationLinear models for classification
Linear models for classificationSung Yub Kim
 
Top school in noida
Top school in noidaTop school in noida
Top school in noidaEdhole.com
 
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...Rafael Nogueras
 
Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Fabian Pedregosa
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
How to design a linear control system
How to design a linear control systemHow to design a linear control system
How to design a linear control systemAlireza Mirzaei
 
lecture 15
lecture 15lecture 15
lecture 15sajinsc
 
On Optimization of Network-coded Scalable Multimedia Service Multicasting
On Optimization of Network-coded Scalable Multimedia Service MulticastingOn Optimization of Network-coded Scalable Multimedia Service Multicasting
On Optimization of Network-coded Scalable Multimedia Service MulticastingAndrea Tassi
 
Divergence clustering
Divergence clusteringDivergence clustering
Divergence clusteringFrank Nielsen
 
Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1luisescobedo38
 
determinants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdfdeterminants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdfTGBSmile
 
Syde770a presentation
Syde770a presentationSyde770a presentation
Syde770a presentationSai Kumar
 

Similar to Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm (20)

10 slides
10 slides10 slides
10 slides
 
Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...
Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...
Talk at SciCADE2013 about "Accelerated Multiple Precision ODE solver base on ...
 
International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1International journal of engineering and mathematical modelling vol2 no1_2015_1
International journal of engineering and mathematical modelling vol2 no1_2015_1
 
Linear models for classification
Linear models for classificationLinear models for classification
Linear models for classification
 
Determinants
DeterminantsDeterminants
Determinants
 
Top school in noida
Top school in noidaTop school in noida
Top school in noida
 
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
 
Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3
 
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
How to design a linear control system
How to design a linear control systemHow to design a linear control system
How to design a linear control system
 
Talk iccf 19_ben_hammouda
Talk iccf 19_ben_hammoudaTalk iccf 19_ben_hammouda
Talk iccf 19_ben_hammouda
 
lecture 15
lecture 15lecture 15
lecture 15
 
On Optimization of Network-coded Scalable Multimedia Service Multicasting
On Optimization of Network-coded Scalable Multimedia Service MulticastingOn Optimization of Network-coded Scalable Multimedia Service Multicasting
On Optimization of Network-coded Scalable Multimedia Service Multicasting
 
Divergence clustering
Divergence clusteringDivergence clustering
Divergence clustering
 
Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1
 
determinants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdfdeterminants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdf
 
determinants-160504230830.pdf
determinants-160504230830.pdfdeterminants-160504230830.pdf
determinants-160504230830.pdf
 
Syde770a presentation
Syde770a presentationSyde770a presentation
Syde770a presentation
 
Automatic bayesian cubature
Automatic bayesian cubatureAutomatic bayesian cubature
Automatic bayesian cubature
 

More from Sebastian Wild

Succint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum ProblemsSuccint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum ProblemsSebastian Wild
 
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case SpaceEntropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case SpaceSebastian Wild
 
Sesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selectionSesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selectionSebastian Wild
 
Average cost of QuickXsort with pivot sampling
Average cost of QuickXsort with pivot samplingAverage cost of QuickXsort with pivot sampling
Average cost of QuickXsort with pivot samplingSebastian Wild
 
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...Sebastian Wild
 
Median-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keysMedian-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keysSebastian Wild
 
Quicksort and Binary Search Trees
Quicksort and Binary Search TreesQuicksort and Binary Search Trees
Quicksort and Binary Search TreesSebastian Wild
 

More from Sebastian Wild (7)

Succint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum ProblemsSuccint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum Problems
 
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case SpaceEntropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
 
Sesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selectionSesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selection
 
Average cost of QuickXsort with pivot sampling
Average cost of QuickXsort with pivot samplingAverage cost of QuickXsort with pivot sampling
Average cost of QuickXsort with pivot sampling
 
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
 
Median-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keysMedian-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keys
 
Quicksort and Binary Search Trees
Quicksort and Binary Search TreesQuicksort and Binary Search Trees
Quicksort and Binary Search Trees
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm

  • 1. Quickselect under Yaroslavskiy’s Dual-Pivoting Algorithm Sebastian Wild Markus E. Nebel Hosam Mahmoud wild@cs.uni-kl.de Computer Science Department 28 May 2013 AofA 2013 Menorca Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 1 / 17
  • 2. Selection Consider the following problem The Selection Problem Given an unsorted array A of n data elements, find the m-th smallest element. Applications estimate distribution of data collection in statistics world rankings in sports Algorithms trivial solution: sort(A); return A[m]; O(n log n) linear worst case possible: Median-of-Medians (Blum et al.) but rather slow in practice (compared to sorting!) Hoare 1961: Quicksort idea usable for selection Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 2 / 17
  • 3. From Quicksort to Quickselect Sort whole array by Quicksort Markus Nebel just showed: Yaroslavskiy’s partitioning can speed up Quicksort Does success of dual partitioning in sorting carry over to selection? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
  • 4. From Quicksort to Quickselect Can prune many branches Markus Nebel just showed: Yaroslavskiy’s partitioning can speed up Quicksort Does success of dual partitioning in sorting carry over to selection? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
  • 5. From Quicksort to Quickselect Can prune many branches Dual Pivot Quicksort Markus Nebel just showed: Yaroslavskiy’s partitioning can speed up Quicksort Does success of dual partitioning in sorting carry over to selection? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
  • 6. From Quicksort to Quickselect Can prune many branches Prune even more branches Markus Nebel just showed: Yaroslavskiy’s partitioning can speed up Quicksort Does success of dual partitioning in sorting carry over to selection? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
  • 7. From Quicksort to Quickselect Can prune many branches Prune even more branches Markus Nebel just showed: Yaroslavskiy’s partitioning can speed up Quicksort Does success of dual partitioning in sorting carry over to selection? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 3 / 17
  • 8. Notation Analyse (random) number of data comparisons C (m) n to select from random permutation P < Q: (random) ranks of the two pivots subarray sizes determined by P and Q: left P rightQmiddle J1 := P − 1 J2 := Q − P − 1 J3 := n − Q selection continues recursively in left subarray, if m < P middle subarray, if P < m < Q right subarray, if Q < m or terminates if m = P or m = Q corresponding events E1 := {m < P} E2 := {P < m < Q} E3 := {Q < m} Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
  • 9. Notation Analyse (random) number of data comparisons C (m) n to select from random permutation P < Q: (random) ranks of the two pivots subarray sizes determined by P and Q: left P rightQmiddle J1 := P − 1 J2 := Q − P − 1 J3 := n − Q selection continues recursively in left subarray, if m < P middle subarray, if P < m < Q right subarray, if Q < m or terminates if m = P or m = Q corresponding events E1 := {m < P} E2 := {P < m < Q} E3 := {Q < m} Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
  • 10. Notation Analyse (random) number of data comparisons C (m) n to select from random permutation P < Q: (random) ranks of the two pivots subarray sizes determined by P and Q: left P rightQmiddle J1 := P − 1 J2 := Q − P − 1 J3 := n − Q selection continues recursively in left subarray, if m < P middle subarray, if P < m < Q right subarray, if Q < m or terminates if m = P or m = Q corresponding events E1 := {m < P} E2 := {P < m < Q} E3 := {Q < m} Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 4 / 17
  • 11. Quickselect Recurrence Yaroslavskiy’s partitioning preserves randomness can set up recurrence for the distribution of C (m) n : C (m) n D = Tn +    C (m) J1 if m lies in left subarray C (m−P) J2 if m lies in middle subarray C (m−Q) J3 if m lies in right subarray = Tn + 1E1 · C (m) J1 + 1E2 · C (m−P) J2 + 1E3 · C (m−Q) J3 Tn is the (random) number of comparisons during partitioning Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 5 / 17
  • 12. Getting Rid of m Complication: second parameter m in recurrence C (m) n D = Tn + 1E1 · C (m) J1 + 1E2 · C (m−P) J2 + 1E3 · C (m−Q) J3 consider simpler quantities 1 Random Rank: m = Mn D = Uniform {1, . . . , n} abbreviate ¯Cn := C (Mn) n ← focus in talk ¯Cn D = Tn+ 1E1 ¯CJ1 + 1E2 ¯CJ2 + 1E3 ¯CJ3 2 Extreme Rank: m = 1 abbreviate ˆCn := C (1) n ˆCn D = Tn + ˆCP−1 explicit solution for expectations possible (generating functions) But: Requires tedious computations More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
  • 13. Getting Rid of m Complication: second parameter m in recurrence C (m) n D = Tn + 1E1 · C (m) J1 + 1E2 · C (m−P) J2 + 1E3 · C (m−Q) J3 consider simpler quantities 1 Random Rank: m = Mn D = Uniform {1, . . . , n} abbreviate ¯Cn := C (Mn) n ← focus in talk ¯Cn D = Tn+ 1E1 ¯CJ1 + 1E2 ¯CJ2 + 1E3 ¯CJ3 2 Extreme Rank: m = 1 abbreviate ˆCn := C (1) n ˆCn D = Tn + ˆCP−1 explicit solution for expectations possible (generating functions) But: Requires tedious computations More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
  • 14. Getting Rid of m Complication: second parameter m in recurrence C (m) n D = Tn + 1E1 · C (m) J1 + 1E2 · C (m−P) J2 + 1E3 · C (m−Q) J3 consider simpler quantities 1 Random Rank: m = Mn D = Uniform {1, . . . , n} abbreviate ¯Cn := C (Mn) n ← focus in talk ¯Cn D = Tn+ 1E1 ¯CJ1 + 1E2 ¯CJ2 + 1E3 ¯CJ3 2 Extreme Rank: m = 1 abbreviate ˆCn := C (1) n ˆCn D = Tn + ˆCP−1 explicit solution for expectations possible (generating functions) But: Requires tedious computations More elegant shortcut to asymptotics of E[ ¯Cn] and E[ ˆCn]? Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 6 / 17
  • 15. Convergence Idea: Computation easy if we can drop index n i. e. when recurrence “in equilibrium” For that, we need stochastic convergence of ¯Cn 0 100 200 300 400 500 600 99.9% massn = 10 n = 20 n = 30 n = 40 ¯Cn But: E[ ¯Cn] grows with n high mass region moves with n ¯Cn does not converge Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 7 / 17
  • 16. Convergence Idea: Computation easy if we can drop index n i. e. when recurrence “in equilibrium” Try normalized variables ¯C∗ n := ¯Cn n instead: 0 2 4 6 8 10 12 14 16 18 99.9% massn = 10 n = 20 n = 30 n = 40 ¯Cn/n E[ ¯C∗ n] seems constant range of high mass looks bounded ¯C∗ n might converge Works because of property of Quickselect: E[ ¯Cn] = O Var( ¯Cn) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 7 / 17
  • 17. The Contraction Method Rewrite recurrence: (Write as sum) ¯Cn D = Tn + 1E1 ¯CJ1 + 1E2 ¯CJ2 + 1E3 ¯CJ3 Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 18. The Contraction Method Rewrite recurrence: (Divide by n) ¯Cn D = Tn + 3 i=1 1Ei ¯CJi Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 19. The Contraction Method Rewrite recurrence: (Rearrange) ¯Cn n D = Tn n + 3 i=1 1Ei ¯CJi n · Ji Ji Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 20. The Contraction Method Rewrite recurrence: (use normalized variables) ¯Cn n D = Tn n + 3 i=1 1Ei Ji n · ¯CJi Ji Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 21. The Contraction Method Recurrence for ¯C∗ n ¯C∗ n D = T∗ n + 3 i=1 1Ei Ji n · ¯C∗ Ji with T∗ n := Tn n Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 22. The Contraction Method Recurrence for ¯C∗ n ¯C∗ n D = T∗ n + 3 i=1 1Ei Ji n · ¯C∗ Ji ↓ ↓ T∗ A∗ i Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 23. The Contraction Method Recurrence for ¯C∗ n ¯C∗ n D = T∗ n + 3 i=1 1Ei Ji n · ¯C∗ Ji ↓ ↓ 3 i=1 E |A∗ i | < 1 T∗ A∗ i Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 24. The Contraction Method Recurrence for ¯C∗ n ¯C∗ n D = T∗ n + 3 i=1 1Ei Ji n · ¯C∗ Ji ↓ ↓ ↓ ↓ 3 i=1 E |A∗ i | < 1 ¯C∗ D = T∗ + 3 i=1 A∗ i · ¯C∗ Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 25. The Contraction Method “Equilibrium” equation for ¯C∗ ¯C∗ D = T∗ + 3 i=1 A∗ i · ¯C∗ Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 26. The Contraction Method “Equilibrium” equation for ¯C∗ (Take expectation on both sides) ¯C∗ D = T∗ + 3 i=1 A∗ i · ¯C∗ Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 27. The Contraction Method “Equilibrium” equation for ¯C∗ (and solve for E ¯C∗) E ¯C∗ = E T∗+ 3 i=1 E A∗ i · E ¯C∗ Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 28. The Contraction Method “Equilibrium” equation for ¯C∗ (and solve for E ¯C∗) E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 29. The Contraction Method “Equilibrium” equation for ¯C∗ (and solve for E ¯C∗) E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i Contraction Method: Convergence of coefficients + contraction condition implies convergence to fixpoint solution. have to show: (all convergences in L1-norm) 1 T∗ n → T∗ 2 1Ei Ji n → A∗ i . . . upcoming 3 3 i=1 E |A∗ i | < 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 8 / 17
  • 30. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 31. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 32. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 33. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 34. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 induces pivot values: U1 = S1, U2 = S1 + S2 0 0.5 1 0 0.5 1 0 0.5 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 35. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 U1 U2 induces pivot values: U1 = S1, U2 = S1 + S2 0 0.5 1 0 0.5 1 0 0.5 1 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 36. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 U1 U2 J1 J2 J3 S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large) n − 2 elements to draw conditional on S Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 37. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 U1 U2 J1 J2 J3 S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large) n − 2 elements to draw conditional on S Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 38. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 U1 U2 J1 J2 J3 S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large) n − 2 elements to draw conditional on S Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 39. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1 S1 S2 S3 U1 U2 J1 J2 J3 S1 = Pr(small) , S2 = Pr(medium) , S3 = Pr(large) n − 2 elements to draw conditional on S Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 40. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1U1U1 U2 U2 Continue of sub-interval with smaller n Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 41. Probabilistic Model Need “convenient” probabilistic model: same probability space for finite n and limit case Natural model: input elements U1, . . . , Un i. i. d. Uniform(0, 1) 0 1U1 U2 first two = pivots values Our equivalent model: 1 Draw spacings S1, S2, S3 on (0, 1) with S D = Dirichlet(1, 1, 1) 2 Draw subarray sizes J1, J2, J3 with J D = Multinomial(n − 2; S1, S2,S3) 3 Continue recursively 0 1U1U1 U2 U2 Continue of sub-interval with smaller n Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 9 / 17
  • 42. Distribution of Tn — Repetition 1 T∗ n → T∗ Invariant: < p → > qg ← p ◦ q k → k’s range K G Tn = number of comparisons in first partitioning step ∼ n one for every element + J2 second for all medium elements + l @ K second for large elements at Ck + s@ G second for small elements at Cg Markus Nebel just showed: l @ K D = Hypergeometric(n − 2; J3 , J1 + J2 ) conditional on J s@ G D = Hypergeometric(n − 2; J1 , J3 ) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
  • 43. Distribution of Tn — Repetition 1 T∗ n → T∗ Invariant: < p → > qg ← p ◦ q k → k’s range K G Tn = number of comparisons in first partitioning step ∼ n one for every element + J2 second for all medium elements + l @ K second for large elements at Ck + s@ G second for small elements at Cg Markus Nebel just showed: l @ K D = Hypergeometric(n − 2; J3 , J1 + J2 ) conditional on J s@ G D = Hypergeometric(n − 2; J1 , J3 ) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
  • 44. Distribution of Tn — Repetition 1 T∗ n → T∗ Invariant: < p → > qg ← p ◦ q k → k’s range K G Tn = number of comparisons in first partitioning step ∼ n one for every element + J2 second for all medium elements + l @ K second for large elements at Ck + s@ G second for small elements at Cg Markus Nebel just showed: l @ K D = Hypergeometric(n − 2; J3 , J1 + J2 ) conditional on J s@ G D = Hypergeometric(n − 2; J1 , J3 ) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 10 / 17
  • 45. Convergence of T∗ n 1 T∗ n → T∗ T∗ n = Tn n = 1 + J2 n + l @ K n + s@ G n J2 n → S2 by law of large numbers, since E[Ji | S] = n · Si Multinomial and Hypergeometric concentrated around mean l @ K n → E l @ K n S by Chernoff bound arguments = E E l @ K | J n S = E J3 ( J1 + J2 ) n(n − 2) S ∼ S3 · (S1 + S2) s@ G n → S1 · S3 similar T∗ n → T∗ = 1 + S2 + S3(2S1 + S2) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
  • 46. Convergence of T∗ n 1 T∗ n → T∗ T∗ n = Tn n = 1 + J2 n + l @ K n + s@ G n J2 n → S2 by law of large numbers, since E[Ji | S] = n · Si Multinomial and Hypergeometric concentrated around mean l @ K n → E l @ K n S by Chernoff bound arguments = E E l @ K | J n S = E J3 ( J1 + J2 ) n(n − 2) S ∼ S3 · (S1 + S2) s@ G n → S1 · S3 similar T∗ n → T∗ = 1 + S2 + S3(2S1 + S2) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
  • 47. Convergence of T∗ n 1 T∗ n → T∗ T∗ n = Tn n = 1 + J2 n + l @ K n + s@ G n J2 n → S2 by law of large numbers, since E[Ji | S] = n · Si Multinomial and Hypergeometric concentrated around mean l @ K n → E l @ K n S by Chernoff bound arguments = E E l @ K | J n S = E J3 ( J1 + J2 ) n(n − 2) S ∼ S3 · (S1 + S2) s@ G n → S1 · S3 similar T∗ n → T∗ = 1 + S2 + S3(2S1 + S2) Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 11 / 17
  • 48. Convergence of Coefficients & Contraction Condition 2 1Ei Ji n → A∗ i standard computation: 1E1 J1 n → 1F1 · S1 with F1 = {V < S1} i = 2, 3 similar 3 3 i=1 E |A∗ i | < 1 E 1F1 S1 = 1 6 by symmetry: 3 i=1 E |A∗ i | = 1 2 < 1 We (finally) proved convergence ¯C∗ n → ¯C∗. Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
  • 49. Convergence of Coefficients & Contraction Condition 2 1Ei Ji n → A∗ i standard computation: 1E1 J1 n → 1F1 · S1 with F1 = {V < S1} i = 2, 3 similar 3 3 i=1 E |A∗ i | < 1 E 1F1 S1 = 1 6 by symmetry: 3 i=1 E |A∗ i | = 1 2 < 1 We (finally) proved convergence ¯C∗ n → ¯C∗. Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
  • 50. Convergence of Coefficients & Contraction Condition 2 1Ei Ji n → A∗ i standard computation: 1E1 J1 n → 1F1 · S1 with F1 = {V < S1} i = 2, 3 similar 3 3 i=1 E |A∗ i | < 1 E 1F1 S1 = 1 6 by symmetry: 3 i=1 E |A∗ i | = 1 2 < 1 We (finally) proved convergence ¯C∗ n → ¯C∗. Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 12 / 17
  • 51. Results — Expectations Computing expectations and plugging in . . . E T∗ = 19 12 Recall: E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i3 i=1 E A∗ i = 1 2 E ¯C∗ = 19 6 = 3.16 L1 convergence E ¯Cn ∼ 3.16n similarly: E ˆCn ∼ 2.375n Comparisons Swaps 0 1 2 3 +5.55% +100% random rank Classic Quickselect Yaroslavskiy Select Comparisons Swaps 0 1 2 +18.8% +125% extreme rank Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
  • 52. Results — Expectations Computing expectations and plugging in . . . E T∗ = 19 12 Recall: E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i3 i=1 E A∗ i = 1 2 E ¯C∗ = 19 6 = 3.16 L1 convergence E ¯Cn ∼ 3.16n similarly: E ˆCn ∼ 2.375n Comparisons Swaps 0 1 2 3 +5.55% +100% random rank Classic Quickselect Yaroslavskiy Select Comparisons Swaps 0 1 2 +18.8% +125% extreme rank Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
  • 53. Results — Expectations Computing expectations and plugging in . . . E T∗ = 19 12 Recall: E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i3 i=1 E A∗ i = 1 2 E ¯C∗ = 19 6 = 3.16 L1 convergence E ¯Cn ∼ 3.16n similarly: E ˆCn ∼ 2.375n Comparisons Swaps 0 1 2 3 +5.55% +100% random rank Classic Quickselect Yaroslavskiy Select Comparisons Swaps 0 1 2 +18.8% +125% extreme rank Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
  • 54. Results — Expectations Computing expectations and plugging in . . . E T∗ = 19 12 Recall: E ¯C∗ = E T∗ 1 − 3 i=1 E A∗ i3 i=1 E A∗ i = 1 2 E ¯C∗ = 19 6 = 3.16 L1 convergence E ¯Cn ∼ 3.16n similarly: E ˆCn ∼ 2.375n Comparisons Swaps 0 1 2 3 +5.55% +100% random rank Classic Quickselect Yaroslavskiy Select Comparisons Swaps 0 1 2 +18.8% +125% extreme rank Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 13 / 17
  • 55. Pivot Sampling successful optimization of Quicksort/-select: median of three Here: generalized pivot selection scheme 1 Choose random sample of k elements 2 Sort the sample 3 Select pivots s. t. in sorted sample t1 smaller , t2 between and t3 larger than pivots Example with k = 8 and t = (3, 2, 1): U1 U2 t1 t2 t3 Our stochastic model nicely generalizes to pivot sampling: only the distribution of spacings S changes! S D = Dirichlet(t1 + 1, t2 + 1, t3 + 1) density: f(s) = s t1 1 s t2 2 s t3 3 B contraction conditions remain valid Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 14 / 17
  • 56. Pivot Sampling successful optimization of Quicksort/-select: median of three Here: generalized pivot selection scheme 1 Choose random sample of k elements 2 Sort the sample 3 Select pivots s. t. in sorted sample t1 smaller , t2 between and t3 larger than pivots Example with k = 8 and t = (3, 2, 1): U1 U2 t1 t2 t3 Our stochastic model nicely generalizes to pivot sampling: only the distribution of spacings S changes! S D = Dirichlet(t1 + 1, t2 + 1, t3 + 1) density: f(s) = s t1 1 s t2 2 s t3 3 B contraction conditions remain valid Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 14 / 17
  • 57. Results — Pivot Sampling General result: ¯Cn ∼ 1 + t2+1 k+1 + (2(t1+1)+(t2+1))(t3+1) (k+1)2 1 − 3 i=1 (ti+1)2 (k+1)2 · n inconvenient for interpretation . . . Limiting case for large sample: ti k → αi as k → ∞ = take exact quantiles as pivots ¯Cn ∼ 1 + α2 + (2α1 + α2)α3 1 − 3 i=1α2 i · n 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 α1 α2 optimal choice is not symmetric classic Quickselect with median of 2t + 1: 2.5n for t = 1 and 2.3n for t = 2 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
  • 58. Results — Pivot Sampling General result: ¯Cn ∼ 1 + t2+1 k+1 + (2(t1+1)+(t2+1))(t3+1) (k+1)2 1 − 3 i=1 (ti+1)2 (k+1)2 · n inconvenient for interpretation . . . Limiting case for large sample: ti k → αi as k → ∞ = take exact quantiles as pivots ¯Cn ∼ 1 + α2 + (2α1 + α2)α3 1 − 3 i=1α2 i · n 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 α1 α2 optimal choice is not symmetric classic Quickselect with median of 2t + 1: 2.5n for t = 1 and 2.3n for t = 2 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
  • 59. Results — Pivot Sampling General result: ¯Cn ∼ 1 + t2+1 k+1 + (2(t1+1)+(t2+1))(t3+1) (k+1)2 1 − 3 i=1 (ti+1)2 (k+1)2 · n inconvenient for interpretation . . . Limiting case for large sample: ti k → αi as k → ∞ = take exact quantiles as pivots ¯Cn ∼ 1 + α2 + (2α1 + α2)α3 1 − 3 i=1α2 i · n 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 α1 α2 optimal choice is not symmetric classic Quickselect with median of 2t + 1: 2.5n for t = 1 and 2.3n for t = 2 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
  • 60. Results — Pivot Sampling General result: ¯Cn ∼ 1 + t2+1 k+1 + (2(t1+1)+(t2+1))(t3+1) (k+1)2 1 − 3 i=1 (ti+1)2 (k+1)2 · n inconvenient for interpretation . . . Limiting case for large sample: ti k → αi as k → ∞ = take exact quantiles as pivots ¯Cn ∼ 1 + α2 + (2α1 + α2)α3 1 − 3 i=1α2 i · n 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 2.4654 2.5 α1 α2 optimal choice is not symmetric classic Quickselect with median of 2t + 1: 2.5n for t = 1 and 2.3n for t = 2 Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 15 / 17
  • 61. Conclusion Practitioners’ Lesson: Yaroslavskiy’s dual-pivoting not helpful for selection Analyzers’ Lesson: expected costs of Quickselect derivable by contraction method pivot sampling included naturally Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 16 / 17
  • 62. References & Further Reading M. Blum, R. W. Floyd, V. Pratt, R. L. Rivest and R. E. Tarjan. Time bounds for selection. J. of Comp. and System Sc., 7(4):448–461, 1973. C. A. R. Hoare. Algorithm 65: Find. Communications of the ACM, 4(7):321–322, July 1961. H.-K. Hwang and T.-H. Tsai. Quickselect and Dickman function. Combinatorics, Probability and Computing, 11, 2000. Hosam M. Mahmoud. Sorting: A distribution theory. John Wiley & Sons, Hoboken, NJ, USA, 2000. H. M. Mahmoud, R. Modarres and R. T. Smythe. Analysis of quickselect : an algorithm for order statistics. Informatique théorique et appl., 29(4):255–276, 1995. C. Martínez, D. Panario and A. Viola. Adaptive sampling strategies for quickselects. ACM Transactions on Algorithms, 6(3):1–45, June 2010. C. Martínez and S. Roura. Optimal Sampling Strategies in Quicksort and Quickselect. SIAM Journal on Computing, 31(3):683, 2001. R. Neininger. On a multivariate contraction method for random recursive structures with applications to Quicksort. Random Structures & Alg., 19(3-4):498–524, 2001. R. Neininger and L. Rüschendorf. A General Limit Theorem for Recursive Algorithms and Combinatorial Structures. The Annals of Applied Probability, 14(1):378–418, 2004. A. Panholzer and H. Prodinger. A generating functions approach for the analysis of grand averages for multiple QUICKSELECT. Random Structures & Alg., 13(3-4):189–209, 1998. U. Rösler and L. Rüschendorf. The contraction method for recursive algorithms. Algorithmica, 29(1):3–33, 2001. S. Wild. Java 7’s Dual Pivot Quicksort. Master thesis, University of Kaiserslautern, 2012. S. Wild, M. E. Nebel and H. Mahmoud. Analysis of Quickselect under Yaroslavskiy’s Dual-Pivoting Algorithm. Algorithmica, in preparation. S. Wild, M. E. Nebel and R. Neininger. Average Case and Distributional Analysis of Java 7’s Dual Pivot Quicksort. ACM Transactions on Algorithms, submitted. V. Yaroslavskiy. Dual-Pivot Quicksort. 2009. Sebastian Wild Java 7’s Dual Pivot Quicksort 2013/05/28 17 / 17