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
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
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