SlideShare a Scribd company logo
Average Cost of QuickXsort with Pivot Sampling
Sebastian Wild
wild@uwaterloo.ca
AofA 2018
29th International Conference on Probabilistic,
Combinatorial and Asymptotic Methods for the
Analysis of Algorithms
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 0 / 12
Outline
1 What is QuickXsort?
1 What is QuickXsort?
2 Recurrence
2 Recurrence
3 Toll function3 Toll function
4 Result4 Result
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 0 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
sort by X
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one
Which one?
subproblem with X.
4 Sort the other subproblem with QUICKXSORT.
sort by X
sort recursively
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one
Which one?
subproblem with X
And why should that help?!
.
4 Sort the other subproblem with QUICKXSORT.
sort by X
sort recursively
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one
Which one?
subproblem with X
And why should that help?!
,
using the other subproblem as scratch space.
4 Sort the other subproblem with QUICKXSORT.
sort by X
sort recursively
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one
Which one?
subproblem with X
And why should that help?!
,
using the other subproblem as scratch space.
4 Sort the other subproblem with QUICKXSORT.
sort by X
sort recursively
QuickXsort can turn X into an in-place sorting method!
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
What is QuickXsort?
QuickXsort = Quicksort + X
QUICKXSORT(A[l..r])
1 Choose pivot P
median of k = 2t + 1
.
2 i = PARTITION(A[l..r], P)
// subproblems: A[l..i − 1] and A[i + 1..r]
3 Sort one subproblem with X,
using the other subproblem as scratch space.
4 Sort the other subproblem with QUICKXSORT.
sort by X
sort recursively
QuickXsort can turn X into an in-place sorting method!
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
For this talk: X = Mergesort
Goal: inherit good comparison count,
but in-place!
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
QuickMergesort
Good candidate for X: Mergesort
#comparisons almost optimal
but: merging uses extra space as buffer
merging possible without extra space
but not really practical!
For this talk: X = Mergesort
Goal: inherit good comparison count,
but in-place! (and without collisions ...)
“Worst merge lanes in the D.C. area”
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Merging with swaps
Important: Buffer elements must stay intact.
run1 run2 buffer
1 Swap run1 and buffer
2 Merge back (swap min)
3 runs merged,
buffer restored (but
permuted)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
5 if ...
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
5 if ...
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if ...
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if largerWithX ∧ J2 J1
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sort recursively iff relative size fulfills
J1
n − 1
∈
1
3
,
1
2
∪
2
3
, 1
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sort recursively iff relative size fulfills
J1
n − 1
∈
1
3
,
1
2
∪
2
3
, 1
J1
n − 1
∈
1
3
1
2
2
3 10
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Which side with Mergesort?
QUICKMERGESORT(A[l..r])
1 Choose pivot P.
2 i = PARTITION(A[l..r], P)
3 J1 := i − l; J2 := r − i
4 largerWithX := min{J1, J2} 1
2 max{J1, J2}
5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1
6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1]
Mergesort
QuickMergesort
7 QUICKMERGESORT(A[l..i − 1]).
8 else
9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r]
Mergesort
QuickMergesort
10 QUICKMERGESORT(A[i..r]).
11 end if
Sort recursively iff relative size fulfills
J1
n − 1
∈
1
3
,
1
2
∪
2
3
, 1
J1
n − 1
∈
1
3
1
2
2
3 10
Similarly: mergesort iff
J1
n − 1
∈
0
1
3
1
2
2
3 1
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Outline
1 What is QuickXsort?
1 What is QuickXsort?
2 Recurrence
2 Recurrence
3 Toll function3 Toll function
4 Result4 Result
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1
2 n buffer space
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1
2 n buffer space
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1
2 n buffer space
211 212 213 214 215 216
−1.26
−1.25
−1.24
x(n) − n lg n
n
(log-plot)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J2) + c(J1)
+ E J2
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J1) + c(J2) (n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k)
partition
+ b(k) + E J1
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J2) + c(J1)
+ E J2
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J1) + c(J2) (n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k)
pivot sampling
+ E J1
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J2) + c(J1)
+ E J2
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J1) + c(J2) (n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J2)
Mergesort right
+ c(J1)
recurse left
+ E J2
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J1) + c(J2) (n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J2) + c(J1)
+ E J2
n−1 ∈ 1
3 , 1
2 ∪ 2
3 , 1 · x(J1)
Mergesort left
+ c(J2)
recurse right
(n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
+ base cases
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n ( )
• wn,j “smooth”: wn,zn ≈ w(z)
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
t(n) = (n − k) + b(k) + E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2)
wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n ( )
• wn,j “smooth”: wn,zn ≈ w(z) ( )
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
t(n) = (n − k) + b(k) + E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2)
wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Costs of QuickXsort
Assumptions:
average costs
#comparisons
for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space
X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1
2 n buffer space
c(n) = (n − k) + b(k) + E J1
n−1 ∈ · x(J2) + c(J1)
+ E J2
n−1 ∈ · x(J1) + c(J2) (n > k)
= t(n) +
n−1
j=0
wn,j · c(j)
shape for Roura’s continuous master theorem:
• c(n) not dominated by “leaves” of recursion
• t(n) “standard scale”: t(n) ∼ Knα
logβ
n ( )
• wn,j “smooth”: wn,zn ≈ w(z) ( )
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz
(which is known explicitly)
t(n) = (n − k) + b(k) + E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2)
wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise 0 10 20 30 40 50
w51,j for median-of-3 QuickMergesort
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
Shape Function
wn,j “smooth”
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1) (n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
0 0.2 0.4 0.6 0.8 1
0
1
2
3
n · wn,zn vs. w(z) (n = 51, k = 3)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
0 0.2 0.4 0.6 0.8 1
0
1
2
3
n · wn,zn vs. w(z) (n = 51, k = 3)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Shape Function
wn,j “smooth” wn,j =



1 · P[J1 = j] if j
n−1 = 1
2
2 · P[J1 = j] if j
n−1 ∈
0 otherwise
precise criterion:
∃w
the “shape function”
: [0, 1] → R 0 :
n−1
j=0
wn,j −
(j+1)/n
j/n
w(z) ≈ nwn,zn
w(z) dz = O(n−1)
...with guaranteed convergence rate
(n→∞).
subproblem size distribution: J1
D
= J2
D
= Binomial
beta-binomial distribution
(n, Beta(t + 1, t + 1)) ± O(1)
binomial distribution highly concen
Chernoff etc.
trated J1
n
D
≈ P D
= Beta
median of 2t+1 i.i.d. Uniform(0, 1) r.v.
(t + 1, t + 1)
formally: nP J1 = zn = fBeta(z)
= zt
(1−z)t
/B(t+1, t+1)
± O(n−1)
w(z) = 2 z ∈ · fBeta(z) valid shape function
0 0.2 0.4 0.6 0.8 1
0
1
2
3
n · wn,zn vs. w(z) (n = 51, k = 3)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
median of 3 39.1% mergesort 60.9% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
median of 3 39.1% mergesort 60.9% recursive
median of 5 43.7% mergesort 56.3% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
median of 3 39.1% mergesort 60.9% recursive
median of 5 43.7% mergesort 56.3% recursive
median of 7 46.6% mergesort 53.4% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
median of 3 39.1% mergesort 60.9% recursive
median of 5 43.7% mergesort 56.3% recursive
median of 7 46.6% mergesort 53.4% recursive
median of 41 55.1% mergesort 44.9% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Expected Subproblem Size
Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z)
w(z) is limiting density of relative subproblem size of recursive call (
1
0 w(z)dz = 1)
expected fraction of elements in recursive call:
r :=
1
0
z · w(z)dz = 2
z∈
incomplete beta integral
z ·
zt(1 − z)t
B(t + 1, t + 1)
dz = 2E P ∈ · P
sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z)
none 30.6% mergesort 69.4% recursive
median of 3 39.1% mergesort 60.9% recursive
median of 5 43.7% mergesort 56.3% recursive
median of 7 46.6% mergesort 53.4% recursive
median of 41 55.1% mergesort 44.9% recursive
exact median 50% mergesort 50% recursive
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
Outline
1 What is QuickXsort?
1 What is QuickXsort?
2 Recurrence
2 Recurrence
3 Toll function3 Toll function
4 Result4 Result
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse
recurse
recurse
recursesize of mergesort parts sum to n
x(αn) ∼ α · x(n)
c(n) ∼ x(n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse recurserecurserecurse
size of mergesort parts sum to n
x(αn) ∼ α · x(n)
c(n) ∼ x(n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse recurserecurserecurse
size of mergesort parts sum to n
x(αn) ∼ α · x(n) (leading term behaves linear)
c(n) ∼ x(n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse recurserecurserecurse
size of mergesort parts sum to n
x(αn) ∼ α · x(n) (leading term behaves linear)
c(n) ∼ x(n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse recurserecurserecurse
size of mergesort parts sum to n
x(αn) ∼ α · x(n) (leading term behaves linear)
c(n) ∼
that was known previously
x(n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The leading term
t(n) ∼ Knα logβ
n t(n) = E J1
n−1 ∈ x(J1) + E J2
n−1 ∈ x(J2) +(n−k)+b(k)
E J1
n−1 ∈ x(J1)
Recall: x(n) = n lg n − 1.24n ± O(1)
J1
D
≈ Pn where P D
= Beta(t + 1, t + 1)
∼ E P ∈ Pn lg(Pn)
∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n
= E P ∈ · (1 − P) · n lg n
Recall: r = 2E P ∈ · P = 1
2 (1 − r) · n lg n
c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n
γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)!
QuickMergesort is optimal w.r.t. leading term!
Is that surprising?
recurse recurserecurserecurse
size of mergesort parts sum to n
x(αn) ∼ α · x(n) (leading term behaves linear)
c(n) ∼
that was known previously
x(n) ... algorithm details do not matter!
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n)
= c(n) − an lg n
=
2
r=1
E Ar(Jr)c(Jr) − an lg n + t(n)
=
2
r=1
E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n
+ (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2)
=
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1]
+ a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε
)
Since J1
D
= J2 we can simplify
E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2
= E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1
= E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2)
= 2E[J lg J]
= 2 E[ J
n ] · n lg n + 2 · 1
ln 2 E[ J
n ln J
n ] · n
= n lg n − 1
ln 2 Hk+1 − Ht+1 n ± O(n1−ε
).
Plugging this back into our equation for c (n), we find
c (n) =
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a n lg n − 1
ln 2 Hk+1 − Ht+1 n
+ b I0, 1
3
(t + 2, t + 1) + I1
2 , 2
3
(t + 2, t + 1) · n ± O(n1−ε
)
=
2
r=1
E Ar(Jr)c (Jr) + t (n)
where
t (n) = b n ± O(n1−ε
)
b = 1 − a
ln 2 Hk+1 − Ht+1 + b · H
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n)
= c(n) − an lg n
=
2
r=1
E Ar(Jr)c(Jr) − an lg n + t(n)
=
2
r=1
E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n
+ (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2)
=
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1]
+ a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε
)
Since J1
D
= J2 we can simplify
E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2
= E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1
= E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2)
= 2E[J lg J]
= 2 E[ J
n ] · n lg n + 2 · 1
ln 2 E[ J
n ln J
n ] · n
= n lg n − 1
ln 2 Hk+1 − Ht+1 n ± O(n1−ε
).
Plugging this back into our equation for c (n), we find
c (n) =
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a n lg n − 1
ln 2 Hk+1 − Ht+1 n
+ b I0, 1
3
(t + 2, t + 1) + I1
2 , 2
3
(t + 2, t + 1) · n ± O(n1−ε
)
=
2
r=1
E Ar(Jr)c (Jr) + t (n)
where
t (n) = b n ± O(n1−ε
)
b = 1 − a
ln 2 Hk+1 − Ht+1 + b · H
c (n) = t (n) +
n−1
j=0
wn,j · c (j)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n)
= c(n) − an lg n
=
2
r=1
E Ar(Jr)c(Jr) − an lg n + t(n)
=
2
r=1
E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n
+ (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2)
=
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1]
+ a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε
)
Since J1
D
= J2 we can simplify
E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2
= E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1
= E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2)
= 2E[J lg J]
= 2 E[ J
n ] · n lg n + 2 · 1
ln 2 E[ J
n ln J
n ] · n
= n lg n − 1
ln 2 Hk+1 − Ht+1 n ± O(n1−ε
).
Plugging this back into our equation for c (n), we find
c (n) =
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a n lg n − 1
ln 2 Hk+1 − Ht+1 n
+ b I0, 1
3
(t + 2, t + 1) + I1
2 , 2
3
(t + 2, t + 1) · n ± O(n1−ε
)
=
2
r=1
E Ar(Jr)c (Jr) + t (n)
where
t (n) = b n ± O(n1−ε
)
b = 1 − a
ln 2 Hk+1 − Ht+1 + b · H
c (n) = t (n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n)
= c(n) − an lg n
=
2
r=1
E Ar(Jr)c(Jr) − an lg n + t(n)
=
2
r=1
E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n
+ (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2)
=
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1]
+ a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε
)
Since J1
D
= J2 we can simplify
E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2
= E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1
= E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2)
= 2E[J lg J]
= 2 E[ J
n ] · n lg n + 2 · 1
ln 2 E[ J
n ln J
n ] · n
= n lg n − 1
ln 2 Hk+1 − Ht+1 n ± O(n1−ε
).
Plugging this back into our equation for c (n), we find
c (n) =
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a n lg n − 1
ln 2 Hk+1 − Ht+1 n
+ b I0, 1
3
(t + 2, t + 1) + I1
2 , 2
3
(t + 2, t + 1) · n ± O(n1−ε
)
=
2
r=1
E Ar(Jr)c (Jr) + t (n)
where
t (n) = b n ± O(n1−ε
)
b = 1 − a
ln 2 Hk+1 − Ht+1 + b · H
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n)
= c(n) − an lg n
=
2
r=1
E Ar(Jr)c(Jr) − an lg n + t(n)
=
2
r=1
E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n
+ (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2)
=
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1]
+ a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε
)
Since J1
D
= J2 we can simplify
E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2
= E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1
= E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2)
= 2E[J lg J]
= 2 E[ J
n ] · n lg n + 2 · 1
ln 2 E[ J
n ln J
n ] · n
= n lg n − 1
ln 2 Hk+1 − Ht+1 n ± O(n1−ε
).
Plugging this back into our equation for c (n), we find
c (n) =
2
r=1
E Ar(Jr)c (Jr) + (n − 1) − an lg n
+ a n lg n − 1
ln 2 Hk+1 − Ht+1 n
+ b I0, 1
3
(t + 2, t + 1) + I1
2 , 2
3
(t + 2, t + 1) · n ± O(n1−ε
)
=
2
r=1
E Ar(Jr)c (Jr) + t (n)
where
t (n) = b n ± O(n1−ε
)
b = 1 − a
ln 2 Hk+1 − Ht+1 + b · H
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
The linear term
Linear term depends on
pivot sampling
partitioning method
linear term of mergesort
but not on how sma
unlike for Quicksort!
ll subproblems solved!
Consider c (n) = c(n) − n lg n
Can show:
c (n) = t
different toll function
(n) +
n−1
j=0
w
same shape as c(n)
n,j · c (j)
t (n) ∼ 1 − 1
ln 2 H
=1+ 1
2 + 1
3 +···+ 1
k+1
k+1 − Ht+1 + b
linear coeff.
of mergesort
≈ −1.24
(1 − r) · n
Use continuous master theorem for c (n):
wn,j smooth
t(n) ∼ Knα
logβ
n
c (n) not dominated by leaves of recursion
c (n) ∼
t (n)
1 − r
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
Outline
1 What is QuickXsort?
1 What is QuickXsort?
2 Recurrence
2 Recurrence
3 Toll function3 Toll function
4 Result4 Result
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n) + qt · n ± O(log n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n) + qt · n ± O(log n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt · n ± O(log n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
0.41
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1 t = 2
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
0.41
0.25
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1 t = 2 t = 3
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
0.41
0.25
0.18
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1 t = 2 t = 3 t = 10
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
0.41
0.25
0.18
0.06
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1 t = 2 t = 3 t = 10 t → ∞
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
0.91
0.41
0.25
0.18
0.06
0
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Result
Comparisons in QuickMergesort:
c(n) = x(n)
same as X ...
+ qt
... + “QuickXsort penalty”
· n ± O(log n)
t = 0 t = 1 t = 2 t = 3 t = 10 t → ∞
0
0.2
0.4
0.6
0.8
1
1.2
α = 1
2 (our QuickMergesort)
α = 1 (always recurse on larger half)
0.91
0.41
0.25
0.18
0.06
0
1.11
0.51
0.32
0.23
0.08
0
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Conclusion
Findings
QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort)
QuickXsort penalty rapidly decreases with sample size
Skewed pivots not helpful (worse despite sorting a larger part by X!)
Extensions
variance
influence of fluctuations in Mergesort?
limit distributions?
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 12 / 12
Icons made by Freepik and Gregor Cresnar from www.flaticon.com.
Title background by Phil’s 1stPix (CC BY-BC-SA 2.0)
Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 13 / 12

More Related Content

PDF
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
PDF
IRJET- Fuel Cost Reduction for Thermal Power Generator by using G.A, PSO, QPS...
PDF
PDF
Linear sorting
PDF
쉽게 설명하는 GAN (What is this? Gum? It's GAN.)
PPT
PPTX
Spark algorithms
PDF
Sequential Pattern Mining and GSP
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
IRJET- Fuel Cost Reduction for Thermal Power Generator by using G.A, PSO, QPS...
Linear sorting
쉽게 설명하는 GAN (What is this? Gum? It's GAN.)
Spark algorithms
Sequential Pattern Mining and GSP

What's hot (20)

PDF
PyTorch 튜토리얼 (Touch to PyTorch)
PDF
Deep Convolutional GANs - meaning of latent space
PDF
PPTX
Algorithms - "quicksort"
PDF
Generalized Linear Models with H2O
PDF
Bin packing problem two approximation
PDF
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
PDF
Uwe Friedrichsen – Extreme availability and self-healing data with CRDTs - No...
PPTX
Algorithms - "heap sort"
PDF
2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...
PPTX
Distributed GLM with H2O - Atlanta Meetup
PPT
Heap sort
PDF
2014-10-20 Large-Scale Machine Learning with Apache Spark at Internet of Thin...
PDF
Stochastic Order Level Inventory Model with Inventory Returns and Special Sales
PDF
Dynamic Economic Dispatch Assessment Using Particle Swarm Optimization Technique
PDF
A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...
PDF
GraphX and Pregel - Apache Spark
PDF
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
PyTorch 튜토리얼 (Touch to PyTorch)
Deep Convolutional GANs - meaning of latent space
Algorithms - "quicksort"
Generalized Linear Models with H2O
Bin packing problem two approximation
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
Uwe Friedrichsen – Extreme availability and self-healing data with CRDTs - No...
Algorithms - "heap sort"
2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...
Distributed GLM with H2O - Atlanta Meetup
Heap sort
2014-10-20 Large-Scale Machine Learning with Apache Spark at Internet of Thin...
Stochastic Order Level Inventory Model with Inventory Returns and Special Sales
Dynamic Economic Dispatch Assessment Using Particle Swarm Optimization Technique
A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...
GraphX and Pregel - Apache Spark
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Ad

Similar to Average cost of QuickXsort with pivot sampling (20)

PPTX
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
PDF
Sesquickselect: One and a half pivot for cache efficient selection
PDF
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
PDF
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
PDF
Enhancing Partition Crossover with Articulation Points Analysis
PDF
Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...
PDF
Matrix Factorizations for Recommender Systems
PPT
Dynamic pgmming
PDF
Spark Summit EU talk by Herman van Hovell
PPT
Cis435 week02
PPT
association(BahanAR-4) data mining apriori.ppt
PDF
ML+Hadoop at NYC Predictive Analytics
PDF
Machine learning cheat sheet
PDF
module2_dIVIDEncONQUER_2022.pdf
PPT
Exploring Algorithms
PPT
DAA-Divide and Conquer methodology, DAA 2024
PPT
Ch04n
PDF
Pivot Sampling in Dual-Pivot Quicksort
PPT
Quick Sort
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
Sesquickselect: One and a half pivot for cache efficient selection
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Enhancing Partition Crossover with Articulation Points Analysis
Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...
Matrix Factorizations for Recommender Systems
Dynamic pgmming
Spark Summit EU talk by Herman van Hovell
Cis435 week02
association(BahanAR-4) data mining apriori.ppt
ML+Hadoop at NYC Predictive Analytics
Machine learning cheat sheet
module2_dIVIDEncONQUER_2022.pdf
Exploring Algorithms
DAA-Divide and Conquer methodology, DAA 2024
Ch04n
Pivot Sampling in Dual-Pivot Quicksort
Quick Sort
Ad

More from Sebastian Wild (12)

PDF
Succint Data Structures for Range Minimum Problems
PDF
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
PDF
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
PDF
Median-of-k Quicksort is optimal for many equal keys
PDF
Quicksort and Binary Search Trees
PDF
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
PDF
Quicksort with Equal Keys
PDF
Dual-Pivot Quicksort - Asymmetries in Sorting
PDF
Analysis of branch misses in Quicksort
PDF
Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm
PDF
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
PDF
Average Case Analysis of Java 7’s Dual Pivot Quicksort
Succint Data Structures for Range Minimum Problems
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Median-of-k Quicksort is optimal for many equal keys
Quicksort and Binary Search Trees
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Quicksort with Equal Keys
Dual-Pivot Quicksort - Asymmetries in Sorting
Analysis of branch misses in Quicksort
Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Average Case Analysis of Java 7’s Dual Pivot Quicksort

Recently uploaded (20)

PPTX
2. Earth - The Living Planet earth and life
PPTX
Comparative Structure of Integument in Vertebrates.pptx
PDF
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
PDF
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
PPTX
Microbiology with diagram medical studies .pptx
PDF
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
PDF
Sciences of Europe No 170 (2025)
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PDF
Phytochemical Investigation of Miliusa longipes.pdf
DOCX
Viruses (History, structure and composition, classification, Bacteriophage Re...
PPTX
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PDF
HPLC-PPT.docx high performance liquid chromatography
PPTX
Derivatives of integument scales, beaks, horns,.pptx
PPTX
neck nodes and dissection types and lymph nodes levels
PPT
protein biochemistry.ppt for university classes
PPTX
Taita Taveta Laboratory Technician Workshop Presentation.pptx
PPT
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
PDF
Biophysics 2.pdffffffffffffffffffffffffff
PPTX
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx
2. Earth - The Living Planet earth and life
Comparative Structure of Integument in Vertebrates.pptx
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
Microbiology with diagram medical studies .pptx
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
Sciences of Europe No 170 (2025)
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
Phytochemical Investigation of Miliusa longipes.pdf
Viruses (History, structure and composition, classification, Bacteriophage Re...
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.
AlphaEarth Foundations and the Satellite Embedding dataset
HPLC-PPT.docx high performance liquid chromatography
Derivatives of integument scales, beaks, horns,.pptx
neck nodes and dissection types and lymph nodes levels
protein biochemistry.ppt for university classes
Taita Taveta Laboratory Technician Workshop Presentation.pptx
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
Biophysics 2.pdffffffffffffffffffffffffff
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx

Average cost of QuickXsort with pivot sampling

  • 1. Average Cost of QuickXsort with Pivot Sampling Sebastian Wild wild@uwaterloo.ca AofA 2018 29th International Conference on Probabilistic, Combinatorial and Asymptotic Methods for the Analysis of Algorithms Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 0 / 12
  • 2. Outline 1 What is QuickXsort? 1 What is QuickXsort? 2 Recurrence 2 Recurrence 3 Toll function3 Toll function 4 Result4 Result Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 0 / 12
  • 3. What is QuickXsort? QuickXsort = Quicksort + X Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 4. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 5. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 6. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 7. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 8. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 9. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 10. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X. 4 Sort the other subproblem with QUICKXSORT. sort by X Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 11. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one Which one? subproblem with X. 4 Sort the other subproblem with QUICKXSORT. sort by X sort recursively Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 12. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one Which one? subproblem with X And why should that help?! . 4 Sort the other subproblem with QUICKXSORT. sort by X sort recursively Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 13. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one Which one? subproblem with X And why should that help?! , using the other subproblem as scratch space. 4 Sort the other subproblem with QUICKXSORT. sort by X sort recursively Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 14. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one Which one? subproblem with X And why should that help?! , using the other subproblem as scratch space. 4 Sort the other subproblem with QUICKXSORT. sort by X sort recursively QuickXsort can turn X into an in-place sorting method! Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 15. What is QuickXsort? QuickXsort = Quicksort + X QUICKXSORT(A[l..r]) 1 Choose pivot P median of k = 2t + 1 . 2 i = PARTITION(A[l..r], P) // subproblems: A[l..i − 1] and A[i + 1..r] 3 Sort one subproblem with X, using the other subproblem as scratch space. 4 Sort the other subproblem with QUICKXSORT. sort by X sort recursively QuickXsort can turn X into an in-place sorting method! Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 1 / 12
  • 16. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 17. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 18. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 19. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 20. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! For this talk: X = Mergesort Goal: inherit good comparison count, but in-place! “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 21. QuickMergesort Good candidate for X: Mergesort #comparisons almost optimal but: merging uses extra space as buffer merging possible without extra space but not really practical! For this talk: X = Mergesort Goal: inherit good comparison count, but in-place! (and without collisions ...) “Worst merge lanes in the D.C. area” Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 2 / 12
  • 22. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 23. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 24. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 25. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 26. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 27. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 28. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 29. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 30. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 31. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 32. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 33. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 34. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 35. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 36. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 37. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 38. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 39. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 40. Merging with swaps Important: Buffer elements must stay intact. run1 run2 buffer 1 Swap run1 and buffer 2 Merge back (swap min) 3 runs merged, buffer restored (but permuted) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 3 / 12
  • 41. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 5 if ... 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 42. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 5 if ... 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 43. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if ... 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 44. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if largerWithX ∧ J2 J1 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 45. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 46. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sort recursively iff relative size fulfills J1 n − 1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 47. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sort recursively iff relative size fulfills J1 n − 1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 J1 n − 1 ∈ 1 3 1 2 2 3 10 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 48. Which side with Mergesort? QUICKMERGESORT(A[l..r]) 1 Choose pivot P. 2 i = PARTITION(A[l..r], P) 3 J1 := i − l; J2 := r − i 4 largerWithX := min{J1, J2} 1 2 max{J1, J2} 5 if largerWithX ∧ J2 J1 ∨ ¬largerWithX ∧ J2 < J1 6 MERGESORT(A[i + 1..r]) with buffer A[l..i − 1] Mergesort QuickMergesort 7 QUICKMERGESORT(A[l..i − 1]). 8 else 9 MERGESORT(A[l..i − 1]) with buffer A[i + 1..r] Mergesort QuickMergesort 10 QUICKMERGESORT(A[i..r]). 11 end if Sort recursively iff relative size fulfills J1 n − 1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 J1 n − 1 ∈ 1 3 1 2 2 3 10 Similarly: mergesort iff J1 n − 1 ∈ 0 1 3 1 2 2 3 1 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 49. Outline 1 What is QuickXsort? 1 What is QuickXsort? 2 Recurrence 2 Recurrence 3 Toll function3 Toll function 4 Result4 Result Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 4 / 12
  • 50. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1 2 n buffer space Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 51. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1 2 n buffer space Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 52. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24 ]n ± O(1) 1 2 n buffer space 211 212 213 214 215 216 −1.26 −1.25 −1.24 x(n) − n lg n n (log-plot) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 53. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 54. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J2) + c(J1) + E J2 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J1) + c(J2) (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 55. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) partition + b(k) + E J1 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J2) + c(J1) + E J2 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J1) + c(J2) (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 56. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) pivot sampling + E J1 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J2) + c(J1) + E J2 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J1) + c(J2) (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 57. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J2) Mergesort right + c(J1) recurse left + E J2 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J1) + c(J2) (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 58. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J2) + c(J1) + E J2 n−1 ∈ 1 3 , 1 2 ∪ 2 3 , 1 · x(J1) Mergesort left + c(J2) recurse right (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 59. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 60. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) + base cases Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 61. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 62. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 63. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 64. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 65. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 66. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 67. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 68. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n ( ) • wn,j “smooth”: wn,zn ≈ w(z) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) t(n) = (n − k) + b(k) + E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 69. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n ( ) • wn,j “smooth”: wn,zn ≈ w(z) ( ) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) t(n) = (n − k) + b(k) + E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 70. Costs of QuickXsort Assumptions: average costs #comparisons for X: x(n) = an lg n + bn ± O(n1−ε) αn buffer space X = Mergesort: x(n) = n lg n + [−1.26, −1.24]n ± O(1) 1 2 n buffer space c(n) = (n − k) + b(k) + E J1 n−1 ∈ · x(J2) + c(J1) + E J2 n−1 ∈ · x(J1) + c(J2) (n > k) = t(n) + n−1 j=0 wn,j · c(j) shape for Roura’s continuous master theorem: • c(n) not dominated by “leaves” of recursion • t(n) “standard scale”: t(n) ∼ Knα logβ n ( ) • wn,j “smooth”: wn,zn ≈ w(z) ( ) c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz (which is known explicitly) t(n) = (n − k) + b(k) + E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise 0 10 20 30 40 50 w51,j for median-of-3 QuickMergesort Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 5 / 12
  • 71. Shape Function wn,j “smooth” precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 72. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 73. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 74. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 75. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 76. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 77. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 78. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 79. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 80. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 81. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 82. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 83. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function 0 0.2 0.4 0.6 0.8 1 0 1 2 3 n · wn,zn vs. w(z) (n = 51, k = 3) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 84. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function 0 0.2 0.4 0.6 0.8 1 0 1 2 3 n · wn,zn vs. w(z) (n = 51, k = 3) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 85. Shape Function wn,j “smooth” wn,j =    1 · P[J1 = j] if j n−1 = 1 2 2 · P[J1 = j] if j n−1 ∈ 0 otherwise precise criterion: ∃w the “shape function” : [0, 1] → R 0 : n−1 j=0 wn,j − (j+1)/n j/n w(z) ≈ nwn,zn w(z) dz = O(n−1) ...with guaranteed convergence rate (n→∞). subproblem size distribution: J1 D = J2 D = Binomial beta-binomial distribution (n, Beta(t + 1, t + 1)) ± O(1) binomial distribution highly concen Chernoff etc. trated J1 n D ≈ P D = Beta median of 2t+1 i.i.d. Uniform(0, 1) r.v. (t + 1, t + 1) formally: nP J1 = zn = fBeta(z) = zt (1−z)t /B(t+1, t+1) ± O(n−1) w(z) = 2 z ∈ · fBeta(z) valid shape function 0 0.2 0.4 0.6 0.8 1 0 1 2 3 n · wn,zn vs. w(z) (n = 51, k = 3) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 6 / 12
  • 86. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 87. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 88. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 89. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 90. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 91. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive median of 3 39.1% mergesort 60.9% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 92. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive median of 3 39.1% mergesort 60.9% recursive median of 5 43.7% mergesort 56.3% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 93. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive median of 3 39.1% mergesort 60.9% recursive median of 5 43.7% mergesort 56.3% recursive median of 7 46.6% mergesort 53.4% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 94. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive median of 3 39.1% mergesort 60.9% recursive median of 5 43.7% mergesort 56.3% recursive median of 7 46.6% mergesort 53.4% recursive median of 41 55.1% mergesort 44.9% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 95. Expected Subproblem Size Intuition behind shape function? w(z) = 2 z ∈ · fBeta(t+1,t+1)(z) w(z) is limiting density of relative subproblem size of recursive call ( 1 0 w(z)dz = 1) expected fraction of elements in recursive call: r := 1 0 z · w(z)dz = 2 z∈ incomplete beta integral z · zt(1 − z)t B(t + 1, t + 1) dz = 2E P ∈ · P sample size fraction of elements in mergesort / recursive call fBeta(t+1,t+1) w(z) none 30.6% mergesort 69.4% recursive median of 3 39.1% mergesort 60.9% recursive median of 5 43.7% mergesort 56.3% recursive median of 7 46.6% mergesort 53.4% recursive median of 41 55.1% mergesort 44.9% recursive exact median 50% mergesort 50% recursive Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 96. Outline 1 What is QuickXsort? 1 What is QuickXsort? 2 Recurrence 2 Recurrence 3 Toll function3 Toll function 4 Result4 Result Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 7 / 12
  • 97. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 98. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 99. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 100. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 101. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 102. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 103. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 104. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 105. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 106. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 107. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 108. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 109. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 110. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 111. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 112. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurse recurse recursesize of mergesort parts sum to n x(αn) ∼ α · x(n) c(n) ∼ x(n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 113. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurserecurserecurse size of mergesort parts sum to n x(αn) ∼ α · x(n) c(n) ∼ x(n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 114. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurserecurserecurse size of mergesort parts sum to n x(αn) ∼ α · x(n) (leading term behaves linear) c(n) ∼ x(n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 115. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurserecurserecurse size of mergesort parts sum to n x(αn) ∼ α · x(n) (leading term behaves linear) c(n) ∼ x(n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 116. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurserecurserecurse size of mergesort parts sum to n x(αn) ∼ α · x(n) (leading term behaves linear) c(n) ∼ that was known previously x(n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 117. The leading term t(n) ∼ Knα logβ n t(n) = E J1 n−1 ∈ x(J1) + E J2 n−1 ∈ x(J2) +(n−k)+b(k) E J1 n−1 ∈ x(J1) Recall: x(n) = n lg n − 1.24n ± O(1) J1 D ≈ Pn where P D = Beta(t + 1, t + 1) ∼ E P ∈ Pn lg(Pn) ∼ E P ∈ Pn lg( n ) = E P ∈ · P · n lg n = E P ∈ · (1 − P) · n lg n Recall: r = 2E P ∈ · P = 1 2 (1 − r) · n lg n c(n) ∼ solution of c(n) = t(n) + w(z)c(zn)dz Ansatz: c(n) ∼ γ · n lg n γ · n lg n = (1 − r) · n lg n + γr · n lg n γ = 1 c(n) ∼ x(n)! QuickMergesort is optimal w.r.t. leading term! Is that surprising? recurse recurserecurserecurse size of mergesort parts sum to n x(αn) ∼ α · x(n) (leading term behaves linear) c(n) ∼ that was known previously x(n) ... algorithm details do not matter! Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 8 / 12
  • 118. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 119. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 120. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 121. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 122. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 123. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 124. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = c(n) − an lg n = 2 r=1 E Ar(Jr)c(Jr) − an lg n + t(n) = 2 r=1 E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n + (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1] + a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε ) Since J1 D = J2 we can simplify E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2 = E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1 = E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2) = 2E[J lg J] = 2 E[ J n ] · n lg n + 2 · 1 ln 2 E[ J n ln J n ] · n = n lg n − 1 ln 2 Hk+1 − Ht+1 n ± O(n1−ε ). Plugging this back into our equation for c (n), we find c (n) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a n lg n − 1 ln 2 Hk+1 − Ht+1 n + b I0, 1 3 (t + 2, t + 1) + I1 2 , 2 3 (t + 2, t + 1) · n ± O(n1−ε ) = 2 r=1 E Ar(Jr)c (Jr) + t (n) where t (n) = b n ± O(n1−ε ) b = 1 − a ln 2 Hk+1 − Ht+1 + b · H Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 125. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = c(n) − an lg n = 2 r=1 E Ar(Jr)c(Jr) − an lg n + t(n) = 2 r=1 E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n + (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1] + a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε ) Since J1 D = J2 we can simplify E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2 = E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1 = E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2) = 2E[J lg J] = 2 E[ J n ] · n lg n + 2 · 1 ln 2 E[ J n ln J n ] · n = n lg n − 1 ln 2 Hk+1 − Ht+1 n ± O(n1−ε ). Plugging this back into our equation for c (n), we find c (n) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a n lg n − 1 ln 2 Hk+1 − Ht+1 n + b I0, 1 3 (t + 2, t + 1) + I1 2 , 2 3 (t + 2, t + 1) · n ± O(n1−ε ) = 2 r=1 E Ar(Jr)c (Jr) + t (n) where t (n) = b n ± O(n1−ε ) b = 1 − a ln 2 Hk+1 − Ht+1 + b · H c (n) = t (n) + n−1 j=0 wn,j · c (j) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 126. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = c(n) − an lg n = 2 r=1 E Ar(Jr)c(Jr) − an lg n + t(n) = 2 r=1 E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n + (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1] + a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε ) Since J1 D = J2 we can simplify E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2 = E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1 = E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2) = 2E[J lg J] = 2 E[ J n ] · n lg n + 2 · 1 ln 2 E[ J n ln J n ] · n = n lg n − 1 ln 2 Hk+1 − Ht+1 n ± O(n1−ε ). Plugging this back into our equation for c (n), we find c (n) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a n lg n − 1 ln 2 Hk+1 − Ht+1 n + b I0, 1 3 (t + 2, t + 1) + I1 2 , 2 3 (t + 2, t + 1) · n ± O(n1−ε ) = 2 r=1 E Ar(Jr)c (Jr) + t (n) where t (n) = b n ± O(n1−ε ) b = 1 − a ln 2 Hk+1 − Ht+1 + b · H c (n) = t (n) + n−1 j=0 w same shape as c(n) n,j · c (j) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 127. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = c(n) − an lg n = 2 r=1 E Ar(Jr)c(Jr) − an lg n + t(n) = 2 r=1 E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n + (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1] + a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε ) Since J1 D = J2 we can simplify E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2 = E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1 = E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2) = 2E[J lg J] = 2 E[ J n ] · n lg n + 2 · 1 ln 2 E[ J n ln J n ] · n = n lg n − 1 ln 2 Hk+1 − Ht+1 n ± O(n1−ε ). Plugging this back into our equation for c (n), we find c (n) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a n lg n − 1 ln 2 Hk+1 − Ht+1 n + b I0, 1 3 (t + 2, t + 1) + I1 2 , 2 3 (t + 2, t + 1) · n ± O(n1−ε ) = 2 r=1 E Ar(Jr)c (Jr) + t (n) where t (n) = b n ± O(n1−ε ) b = 1 − a ln 2 Hk+1 − Ht+1 + b · H c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 128. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = c(n) − an lg n = 2 r=1 E Ar(Jr)c(Jr) − an lg n + t(n) = 2 r=1 E Ar(Jr) c(Jr) − aJr lg Jr + a E Ar(Jr)Jr lg Jr − an lg n + (n − 1) + E A2(J2) · x(J1) + E A1(J1) · x(J2) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a E A1(J1) + A2(J2) J1 lg J1 + b E[A2(J2)J1] + a E A2(J2) + A1(J1) J2 lg J2 + b E[A1(J1)J2] ± O(n1−ε ) Since J1 D = J2 we can simplify E A1(J1) + A2(J2) J1 lg J1 + E A2(J2) + A1(J1) J2 lg J2 = E A1(J1) + A2(J2) J1 lg J1 + E A2(J1) + A1(J2) J1 lg J1 = E J1 lg J1 · A1(J1) + A1(J2) + A2(J1) + A2(J2) = 2E[J lg J] = 2 E[ J n ] · n lg n + 2 · 1 ln 2 E[ J n ln J n ] · n = n lg n − 1 ln 2 Hk+1 − Ht+1 n ± O(n1−ε ). Plugging this back into our equation for c (n), we find c (n) = 2 r=1 E Ar(Jr)c (Jr) + (n − 1) − an lg n + a n lg n − 1 ln 2 Hk+1 − Ht+1 n + b I0, 1 3 (t + 2, t + 1) + I1 2 , 2 3 (t + 2, t + 1) · n ± O(n1−ε ) = 2 r=1 E Ar(Jr)c (Jr) + t (n) where t (n) = b n ± O(n1−ε ) b = 1 − a ln 2 Hk+1 − Ht+1 + b · H c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 129. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 130. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 131. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 132. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 133. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 134. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 135. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 136. The linear term Linear term depends on pivot sampling partitioning method linear term of mergesort but not on how sma unlike for Quicksort! ll subproblems solved! Consider c (n) = c(n) − n lg n Can show: c (n) = t different toll function (n) + n−1 j=0 w same shape as c(n) n,j · c (j) t (n) ∼ 1 − 1 ln 2 H =1+ 1 2 + 1 3 +···+ 1 k+1 k+1 − Ht+1 + b linear coeff. of mergesort ≈ −1.24 (1 − r) · n Use continuous master theorem for c (n): wn,j smooth t(n) ∼ Knα logβ n c (n) not dominated by leaves of recursion c (n) ∼ t (n) 1 − r Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 137. Outline 1 What is QuickXsort? 1 What is QuickXsort? 2 Recurrence 2 Recurrence 3 Toll function3 Toll function 4 Result4 Result Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 9 / 12
  • 138. Result Comparisons in QuickMergesort: c(n) = x(n) + qt · n ± O(log n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 139. Result Comparisons in QuickMergesort: c(n) = x(n) + qt · n ± O(log n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 140. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt · n ± O(log n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 141. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 142. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 143. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 0.41 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 144. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 t = 2 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 0.41 0.25 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 145. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 t = 2 t = 3 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 0.41 0.25 0.18 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 146. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 t = 2 t = 3 t = 10 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 0.41 0.25 0.18 0.06 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 147. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 t = 2 t = 3 t = 10 t → ∞ 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) 0.91 0.41 0.25 0.18 0.06 0 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 148. Result Comparisons in QuickMergesort: c(n) = x(n) same as X ... + qt ... + “QuickXsort penalty” · n ± O(log n) t = 0 t = 1 t = 2 t = 3 t = 10 t → ∞ 0 0.2 0.4 0.6 0.8 1 1.2 α = 1 2 (our QuickMergesort) α = 1 (always recurse on larger half) 0.91 0.41 0.25 0.18 0.06 0 1.11 0.51 0.32 0.23 0.08 0 Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 10 / 12
  • 149. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 150. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 151. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 152. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 153. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 154. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 155. Conclusion Findings QuickMergesort sorts in-place with close-to-optimal #comparisons (but not a stable sort) QuickXsort penalty rapidly decreases with sample size Skewed pivots not helpful (worse despite sorting a larger part by X!) Extensions variance influence of fluctuations in Mergesort? limit distributions? Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 11 / 12
  • 156. Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 12 / 12
  • 157. Icons made by Freepik and Gregor Cresnar from www.flaticon.com. Title background by Phil’s 1stPix (CC BY-BC-SA 2.0) Sebastian Wild Average Cost of QuickXsort with Pivot Sampling 2018-06-28 13 / 12