SlideShare una empresa de Scribd logo
1 de 157
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...
2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...
2015-06-15 Large-Scale Elastic-Net Regularized Generalized Linear Models at S...
DB Tsai
 

La actualidad más candente (20)

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

Similar a Average cost of QuickXsort with pivot sampling

Exploring Algorithms
Exploring AlgorithmsExploring Algorithms
Exploring Algorithms
Sri Prasanna
 

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

Sesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selectionSesquickselect: One and a half pivot for cache efficient selection
Sesquickselect: One and a half pivot for cache efficient selection
 
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
Nearly-optimal mergesort: Fast, practical sorting methods that optimally adap...
 
SAT based planning for multiagent systems
SAT based planning for multiagent systemsSAT based planning for multiagent systems
SAT based planning for multiagent systems
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...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
Enhancing Partition Crossover with Articulation Points AnalysisEnhancing Partition Crossover with Articulation Points Analysis
Enhancing Partition Crossover with Articulation Points Analysis
 
Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...
Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...
Effective and Unsupervised Fractal-based Feature Selection for Very Large Dat...
 
Matrix Factorizations for Recommender Systems
Matrix Factorizations for Recommender SystemsMatrix Factorizations for Recommender Systems
Matrix Factorizations for Recommender Systems
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 
Spark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van HovellSpark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van Hovell
 
Cis435 week02
Cis435 week02Cis435 week02
Cis435 week02
 
Sorting
SortingSorting
Sorting
 
ML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive AnalyticsML+Hadoop at NYC Predictive Analytics
ML+Hadoop at NYC Predictive Analytics
 
Machine learning cheat sheet
Machine learning cheat sheetMachine learning cheat sheet
Machine learning cheat sheet
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Exploring Algorithms
Exploring AlgorithmsExploring Algorithms
Exploring Algorithms
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
 
Ch04n
Ch04nCh04n
Ch04n
 
Pivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot QuicksortPivot Sampling in Dual-Pivot Quicksort
Pivot Sampling in Dual-Pivot Quicksort
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 

Más de Sebastian Wild

Más de Sebastian Wild (11)

Succint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum ProblemsSuccint Data Structures for Range Minimum Problems
Succint Data Structures for Range Minimum Problems
 
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case SpaceEntropy Trees & Range-Minimum Queries in Optimal Average-Case Space
Entropy Trees & Range-Minimum Queries in Optimal Average-Case Space
 
Median-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keysMedian-of-k Quicksort is optimal for many equal keys
Median-of-k Quicksort is optimal for many equal keys
 
Quicksort and Binary Search Trees
Quicksort and Binary Search TreesQuicksort and Binary Search Trees
Quicksort and Binary Search Trees
 
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
 
Quicksort with Equal Keys
Quicksort with Equal KeysQuicksort with Equal Keys
Quicksort with Equal Keys
 
Dual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in SortingDual-Pivot Quicksort - Asymmetries in Sorting
Dual-Pivot Quicksort - Asymmetries in Sorting
 
Analysis of branch misses in Quicksort
Analysis of branch misses in QuicksortAnalysis of branch misses in Quicksort
Analysis of branch misses in Quicksort
 
Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm
Quickselect Under Yaroslavskiy's Dual Pivoting AlgorithmQuickselect Under Yaroslavskiy's Dual Pivoting Algorithm
Quickselect Under Yaroslavskiy's Dual Pivoting Algorithm
 
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAnEngineering Java 7's Dual Pivot Quicksort Using MaLiJAn
Engineering Java 7's Dual Pivot Quicksort Using MaLiJAn
 
Average Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot QuicksortAverage Case Analysis of Java 7’s Dual Pivot Quicksort
Average Case Analysis of Java 7’s Dual Pivot Quicksort
 

Último

The importance of continents, oceans and plate tectonics for the evolution of...
The importance of continents, oceans and plate tectonics for the evolution of...The importance of continents, oceans and plate tectonics for the evolution of...
The importance of continents, oceans and plate tectonics for the evolution of...
Sérgio Sacani
 
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
Sérgio Sacani
 
The solar dynamo begins near the surface
The solar dynamo begins near the surfaceThe solar dynamo begins near the surface
The solar dynamo begins near the surface
Sérgio Sacani
 
Mitosis...............................pptx
Mitosis...............................pptxMitosis...............................pptx
Mitosis...............................pptx
Cherry
 
Quantifying Artificial Intelligence and What Comes Next!
Quantifying Artificial Intelligence and What Comes Next!Quantifying Artificial Intelligence and What Comes Next!
Quantifying Artificial Intelligence and What Comes Next!
University of Hertfordshire
 

Último (20)

mixotrophy in cyanobacteria: a dual nutritional strategy
mixotrophy in cyanobacteria: a dual nutritional strategymixotrophy in cyanobacteria: a dual nutritional strategy
mixotrophy in cyanobacteria: a dual nutritional strategy
 
word2vec, node2vec, graph2vec, X2vec: Towards a Theory of Vector Embeddings o...
word2vec, node2vec, graph2vec, X2vec: Towards a Theory of Vector Embeddings o...word2vec, node2vec, graph2vec, X2vec: Towards a Theory of Vector Embeddings o...
word2vec, node2vec, graph2vec, X2vec: Towards a Theory of Vector Embeddings o...
 
NuGOweek 2024 full programme - hosted by Ghent University
NuGOweek 2024 full programme - hosted by Ghent UniversityNuGOweek 2024 full programme - hosted by Ghent University
NuGOweek 2024 full programme - hosted by Ghent University
 
METHODS OF TRANSCRIPTOME ANALYSIS....pptx
METHODS OF TRANSCRIPTOME ANALYSIS....pptxMETHODS OF TRANSCRIPTOME ANALYSIS....pptx
METHODS OF TRANSCRIPTOME ANALYSIS....pptx
 
Topography and sediments of the floor of the Bay of Bengal
Topography and sediments of the floor of the Bay of BengalTopography and sediments of the floor of the Bay of Bengal
Topography and sediments of the floor of the Bay of Bengal
 
WASP-69b’s Escaping Envelope Is Confined to a Tail Extending at Least 7 Rp
WASP-69b’s Escaping Envelope Is Confined to a Tail Extending at Least 7 RpWASP-69b’s Escaping Envelope Is Confined to a Tail Extending at Least 7 Rp
WASP-69b’s Escaping Envelope Is Confined to a Tail Extending at Least 7 Rp
 
GBSN - Microbiology (Unit 6) Human and Microbial interaction
GBSN - Microbiology (Unit 6) Human and Microbial interactionGBSN - Microbiology (Unit 6) Human and Microbial interaction
GBSN - Microbiology (Unit 6) Human and Microbial interaction
 
The importance of continents, oceans and plate tectonics for the evolution of...
The importance of continents, oceans and plate tectonics for the evolution of...The importance of continents, oceans and plate tectonics for the evolution of...
The importance of continents, oceans and plate tectonics for the evolution of...
 
B lymphocytes, Receptors, Maturation and Activation
B lymphocytes, Receptors, Maturation and ActivationB lymphocytes, Receptors, Maturation and Activation
B lymphocytes, Receptors, Maturation and Activation
 
The Scientific names of some important families of Industrial plants .pdf
The Scientific names of some important families of Industrial plants .pdfThe Scientific names of some important families of Industrial plants .pdf
The Scientific names of some important families of Industrial plants .pdf
 
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
Gliese 12 b: A Temperate Earth-sized Planet at 12 pc Ideal for Atmospheric Tr...
 
Cell Immobilization Methods and Applications.pptx
Cell Immobilization Methods and Applications.pptxCell Immobilization Methods and Applications.pptx
Cell Immobilization Methods and Applications.pptx
 
Virulence Analysis of Citrus canker caused by Xanthomonas axonopodis pv. citr...
Virulence Analysis of Citrus canker caused by Xanthomonas axonopodis pv. citr...Virulence Analysis of Citrus canker caused by Xanthomonas axonopodis pv. citr...
Virulence Analysis of Citrus canker caused by Xanthomonas axonopodis pv. citr...
 
Application of Mass Spectrometry In Biotechnology
Application of Mass Spectrometry In BiotechnologyApplication of Mass Spectrometry In Biotechnology
Application of Mass Spectrometry In Biotechnology
 
A Giant Impact Origin for the First Subduction on Earth
A Giant Impact Origin for the First Subduction on EarthA Giant Impact Origin for the First Subduction on Earth
A Giant Impact Origin for the First Subduction on Earth
 
The solar dynamo begins near the surface
The solar dynamo begins near the surfaceThe solar dynamo begins near the surface
The solar dynamo begins near the surface
 
Structural annotation................pptx
Structural annotation................pptxStructural annotation................pptx
Structural annotation................pptx
 
Mitosis...............................pptx
Mitosis...............................pptxMitosis...............................pptx
Mitosis...............................pptx
 
Hemoglobin metabolism: C Kalyan & E. Muralinath
Hemoglobin metabolism: C Kalyan & E. MuralinathHemoglobin metabolism: C Kalyan & E. Muralinath
Hemoglobin metabolism: C Kalyan & E. Muralinath
 
Quantifying Artificial Intelligence and What Comes Next!
Quantifying Artificial Intelligence and What Comes Next!Quantifying Artificial Intelligence and What Comes Next!
Quantifying Artificial Intelligence and What Comes Next!
 

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