Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Practical Potential
1. Dual-Pivot Quicksort and Beyond
Analysis of Multiway Partitioning and Its Practical Potential
Sebastian Wild
Vortrag zur wissenschaftlichen Aussprache
im Rahmen des Promotionsverfahrens
8. Juli 2016
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 1 / 17
2. Dual-P??? Q?????? and Beyond
Analysis of Multi??? P??????? and Its Practical Potential
Sebastian Wild
Vortrag zur wissenschaftlichen Aussprache
im Rahmen des Promotionsverfahrens
8. Juli 2016
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 1 / 17
3. Dual-Pivot Quicksort and Beyond
Analysis of Multiway Partitioning and Its Practical Potential
Sebastian Wild
Vortrag zur wissenschaftlichen Aussprache
im Rahmen des Promotionsverfahrens
8. Juli 2016
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 1 / 17
4. What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
5. What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
6. What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
7. What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
8. What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
9. What is sorting?
Two meanings of sorting
1
Separate different sorts
of things
2
Put items into order
(alphabetical, numerical, ...)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
10. What is sorting?
Two meanings of sorting
1
Separate different sorts
of things
2
Put items into order
(alphabetical, numerical, ...)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
11. What is sorting?
Two meanings of sorting
1
Separate different sorts
of things
2
Put items into order
(alphabetical, numerical, ...)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
12. What is sorting?
Two meanings of sorting
1
Separate different sorts
of things
2
Put items into order
(alphabetical, numerical, ...)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
13. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
Input given as array of n items
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
14. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
Input given as array of n items
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
15. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
16. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
17. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
A[5]
10
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
18. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
A[5]
10
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
19. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
A[5]
10
A[8]
72
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
20. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
A[5]
10
A[8]
72
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
21. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
22. Model of Computation
How do computers sort?
1 2 3 4 5 6 7 8 9
50 2 75 17 10 78 33 72 98
1 2 3 4 5 6 7 8 9
5 1 7 3 2 8 4 6 9
Input given as array of n items
e.g. Excel rows
index-based access (5th item A[5] is 10)
we can read and write cells
Only info about data: pairwise comparisons
Is A[5] < A[8]? Yes, 10 < 72
only relative ranking of elements important
may assume, e.g., numbers 1, . . . , n
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 3 / 17
23. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
24. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 915
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
25. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
?
1
min
5
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
26. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
?
71
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
27. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ?
31
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
28. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ?
21
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
29. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ?
81
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
30. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ? ?
41
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
31. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ? ? ?
61
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
32. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ? ? ? ?
91
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
33. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ? ? ? ? ?
1
min
5
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
34. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
5 1 7 3 2 8 4 6 9
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 95
min
1
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
35. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
36. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
to do (by same procedure)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
37. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91 75
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
38. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
?
35
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
39. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ?
5 3
min
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
40. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ?
23
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
41. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ?
2
min
3
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
42. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ?
82
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
43. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ? ?
42
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
44. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ? ? ?
62
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
45. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ? ? ? ?
92
min
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
46. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
5 7 3 2 8 4 6 91
? ? ? ? ? ? ?
2
min
5
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
47. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
7 3 5 8 4 6 952
min
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
48. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
7 3 5 8 4 6 92
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
49. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2 3 7 5 8 4 6 9
? ? ? ? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
50. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
3 4 5 8 7 6 9
? ? ? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
51. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
3 4 5 8 7 6 9
? ? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
52. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
53. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
54. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Each round puts one item in place.
Remaining list one smaller.
Can we do better?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
55. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Each round puts one item in place.
Remaining list one smaller.
Can we do better?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
56. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Each round puts one item in place.
Remaining list one smaller.
Can we do better?
Yes! Finding the minimum
costs the same as computing
the rank
number of elements
smaller than given element
of any element.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
57. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
58. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final place of some item (pivot),
put small items left, others right (partition).
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
59. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
60. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
5 1 7 3 2 8 4 6 9
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
61. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
5 1 7 3 2 8 4 6 9
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
62. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
5 1 7 3 2 8 4 6 9
k g
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
63. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
<
5 1 7 3 2 8 4 6 9
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
64. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
<
5 1 7 3 2 8 4 6 9
?
k g
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
65. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
<
5 1 7 3 2 8 4 6 9
?
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
66. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >
5 1 7 3 2 8 4 6 9
?
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
67. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< > >
5 1 7 3 2 8 4 6 9
?
k g
? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
68. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< > >>
5 1 7 3 2 8 4 6 9
? ? ?
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
69. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< > >><
5 1 7 3 2 8 4 6 9
? ? ??
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
70. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >
? ? ??
k g
?
5 1 3 2 8 6 94 7
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
71. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< ><
? ? ??
g
?
5 1 4 3 2 8 7 6 9
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
72. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< <
? ? ??
g
?
5 1 4 3 2 8 7 6 9
?
k g
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
73. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< < >
? ? ???
5 1 4 3 2 8 7 6 9
? ?
gk
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
74. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< < >
? ? ???
5 1 4 3 2 8 7 6 9
? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
75. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< ><
? ? ???? ? ?
1 4 3 8 7 6 92 5
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
76. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< ><
? ? ???? ? ?
2 1 4 3 8 7 6 95
reached final place!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
77. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< >>< >< ><
? ? ???? ? ?
2 1 4 3 8 7 6 95
to do to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
78. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
2 1 4 3 8 7 6 95
to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
79. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
2 1 4 3 8 7 6 95
to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
80. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< > >
? ? ???? ? ?
2 1 4 3 8 7 6 95
to do
? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
81. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< > >
? ? ???? ? ?
to do
? ? ?
1 2 4 3 5 8 7 6 9
to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
82. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
to do
? ? ?
1 2 4 3 5 8 7 6 9
to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
83. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
to do
? ? ?
1 2 3 4 5 8 7 6 9
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
84. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
to do
? ? ?
1 2 3 4 5 8 7 6 9
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
85. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< < >
? ? ???? ? ?
? ? ?
1 2 3 4 5 8 7 6 9
?
? ? ?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
86. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
< < >
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
87. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
to do
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
88. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
89. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
90. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
16 Comparisons
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
91. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
16 Comparisons
Much less comparisons in Quicksort
...unless pivots are max/min!
But average/expected behavior is good.
Quicksort is method of choice in practice.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
92. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
16 Comparisons
Much less comparisons in Quicksort
...unless pivots are max/min!
But average/expected behavior is good.
Quicksort is method of choice in practice.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
93. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
16 Comparisons
Much less comparisons in Quicksort
...unless pivots are max/min!
But average/expected
(actually: almost always good)
behavior is good.
Quicksort is method of choice in practice.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
94. What is Quicksort?
How to make a computer sort?
Selectionsort
Find smallest item and put it in place.
? ? ? ? ? ? ? ?
1
? ? ? ? ? ? ?
2
? ? ? ? ? ?
? ? ? ? ?
? ? ? ?
3 4 5 6 7 8 9
? ? ?
? ?
?
36 Comparisons
Quicksort
Find final
kth smallest A[k]
place of some item (pivot),
put small items left, others right (partition).
? ? ???? ? ?
? ? ?
?
? ? ?
1 2 3 4 5 6 7 8 9
?
16 Comparisons
Much less comparisons in Quicksort
...unless pivots are max/min!
But average/expected
(actually: almost always good)
behavior is good.
Quicksort is method of choice in practice.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 4 / 17
95. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
96. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
97. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
98. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
99. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
100. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
101. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
102. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
103. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
104. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
105. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
106. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
107. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
108. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
conventional
wisdom
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
109. Variants of Quicksort
It is tempting to try to develop ways to improve quicksort:
a faster sorting algorithm is computer science’s “better mousetrap,”
and quicksort is a venerable method that seems to invite tinkering.
R. Sedgewick and K. Wayne, Algorithms 4th ed.
Many variants tried ... many not helpful
Two important tuning options:
1 Choose pivots wisely (pivot sampling)
for example: middle element of three (median-of-three)
pivot never min or max!
2 Split into s 2 subproblems at once (multiway partitioning)
for example: 2 pivots 3 classes: small, medium and large
subproblems are smaller,
but partitioning is more expensive.
conventional
wisdom
till 2009!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
110. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
111. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
112. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
113. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
114. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
(121ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
115. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
(121ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
116. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
(121ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
117. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
Java 7 sorting method
(121ms to sort 106 items)
(93ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
118. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
Java 7 sorting method
(121ms to sort 106 items)
(93ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
No theoretical explanation for running time known in 2009!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
119. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
Java 7 sorting method
(121ms to sort 106 items)
(93ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
No theoretical explanation for running time known in 2009!
Only lucky experiments?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
120. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
Java 7 sorting method
(121ms to sort 106 items)
(93ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
No theoretical explanation for running time known in 2009!
Only lucky experiments?
Why did no-one come up with this earlier?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
121. Java 7’s Dual-Pivot Quicksort
What happened in 2009? Java
used e.g. for Android apps
7 sorting method was released!
till 2009, Java used classic
as in example before
+ median-of-three
+ Insertionsort
Quicksort
Java 7 uses new dual-pivot Quicksort
started as hobby project
by Vladimir Yaroslavskiy
20 % faster than
highly-tuned Java 6!
0 0.5 1 1.5 2
·106
7
8
9
n
time
10−6·nlnn
Java 6 sorting method
Java 7 sorting method
(121ms to sort 106 items)
(93ms to sort 106 items)
Normalized Java runtimes (in ms).
Average and standard deviation of
1000 random permutations per size.
No theoretical explanation for running time known in 2009!
Only lucky experiments?
Why did no-one come up with this earlier?
That was the starting point for my work!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 6 / 17
122. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
123. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
Mathematical Analysis
prove eternal truths
not experiments
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
124. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
125. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksort
costs on average for large inputs
parametric (algorithm and cost measure)
Unified Analysis of Quicksort
costs on average for large inputs
parametric (algorithm and cost measure)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
126. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksort
costs on average for large inputs
parametric (algorithm and cost measure)
Cost Measures
generalize models of cost
comparisons
write accesses / swaps
cache misses / scanned elements
branch mispredictions
element-wise charging schemes
Cost Measures
generalize models of cost
comparisons
write accesses / swaps
cache misses / scanned elements
branch mispredictions
element-wise charging schemes
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
127. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksort
costs on average for large inputs
parametric (algorithm and cost measure)
Cost Measures
generalize models of cost
comparisons
write accesses / swaps
cache misses / scanned elements
branch mispredictions
element-wise charging schemes
Discussion of Results
influence of
number of pivots
pivot sampling
organization of indices
Discussion of Results
influence of
number of pivots
pivot sampling
organization of indices
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
128. Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysis
prove eternal truths
not experiments
What is multiway partitioning?
generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksort
costs on average for large inputs
parametric (algorithm and cost measure)
Cost Measures
generalize models of cost
comparisons
write accesses / swaps
cache misses / scanned elements
branch mispredictions
element-wise charging schemes
Discussion of Results
influence of
number of pivots
pivot sampling
organization of indices
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
129. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
130. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
131. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
132. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
133. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
134. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
135. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
136. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
137. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
138. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
139. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
140. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
141. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
142. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
= 4 · 1
4
log2(4) = 2
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
143. Entropy
What is entropy?
1 Thermodynamics: unusable part of thermal energy (Physicists’ party? Next door, please.)
2 Mathematics: information content of a random variable
Definition (Entropy)
Let X be a random variable with P[X = i] = pi for i ∈ {1, . . . , u}.
Its entropy is defined as H(X) = u
i=1 pi log2(1/pi).
probability that X = i
...all clear?
Let’s see an application.
1 2
3
4 5
6
7 8 9
10
11 12
Urn with colored balls.
Alice draws ball X uniformly at random from urn.
Bob wants to guess its color C
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
P[C = ] = 3/12 = 0.25
by Yes/No-Questions.
Theorem (Shannon’s Source Coding Theorem)
On average, Bob can’t do with less than H(C) questions.
= 4 · 1
4
log2(4) = 2
We say: We must acquire H(C) bits of information to know C.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 8 / 17
144. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
145. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
146. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings
= colors
of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
147. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings
= colors
of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
148. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings
= colors
of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
149. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings
= colors
of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
150. Information Theory & Sorting
Where is the connection to sorting?
1 2
3
4 5
6
7 8 9
10
11 12
Now, Alice draws one of the n!
n(n − 1) · · · 2 · 1
possible orderings
= colors
of n items.
Bob guesses the order by asking comparisons.
Theorem (Information-Theoretic Lower Bound for Sorting)
We cannot sort with less than log2(n!) = n log2(n) ± O(n) comparisons.
Assumptions:
(1) All orderings equally likely.
(2) Only comparisons allowed.asymptotic error term for n → ∞
H(C)
To achieve this bound, every comparison must yield 1 bit of information!
We can reverse this idea to analyze Quicksort.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 9 / 17
151. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
152. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
153. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
154. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
155. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
156. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
157. Comparisons in Quicksort
How many comparisons does Quicksort use on average?
Entropy-based analysis:
1 Compute the average information yield: x bit
comparison . (0 < x 1)
What is x? ...stay tuned.
2 Need to learn log2(n!) bits
not mathematically rigorous ...
but correct result!
rigorous proof → dissertation
Use
log2(n!)
x
=
1
x
n log2(n) ± O(n) comparisons.
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 10 / 17
158. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
159. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
160. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
161. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
162. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
163. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
164. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
165. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
166. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
167. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
168. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
169. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
170. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
same average sorting costs
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
171. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
same average sorting costs
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
172. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
same average sorting costs
independent & identically distributed
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
173. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
same average sorting costs
independent & identically distributed
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
174. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ]
prob. of item to be < P
log2(P[ < ]) − P[ > ] log2(P[ > ])
Note: pivot value P is random.
What is its distribution?
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
0 1P0 1
P[ < ] P[ > ]
same average sorting costs
independent & identically distributed
Answer: P D
= Uniform(0, 1)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
175. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
0 1P0 1
P[ < ] P[ > ]
same average sorting costs
independent & identically distributed
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
176. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
0 1P0 1
P[ < ] P[ > ]
same average sorting costs
independent & identically distributed
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
177. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
0 1P0 1
P[ < ] P[ > ]
same average sorting costs
independent & identically distributed
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
178. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
Excursion: Input Models
Typical: Random Permutations
items: 1, . . . , n
all orderings equally likely
We use the equivalent
Uniform Model
n numbers drawn i.i.d. Uniform(0, 1)
i.i.d. random relative ranking
P[ < ] = P, P[ > ] = 1 − P
0 1P0 1
P[ < ] P[ > ]
same average sorting costs
independent & identically distributed
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
179. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
180. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
181. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
182. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
183. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
184. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
185. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
186. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 10 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
187. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
188. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
189. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2U3
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
190. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2U3 U4
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
191. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2U3 U4U5
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
192. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2U3 U4U5 U6
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17
193. Partitioning Entropy
What is x?
Classic Quicksort:
Always compare with the pivot P
< < < < > > > >
2 1 4 3 5 8 7 6 9
Outcome C is either small or large .
Information yield is H(C) =
−P[ < ] log2(P[ < ]) − P[ > ] log2(P[ > ])
E
Average over P
[H(C)] = E −P log2(P) − (1 − P) log2(1 − P)
= −2
1
0
z log2(z) dz
=
1
2
log2(e) ≈ 0.721348
s-way Quicksort with pivot sampling:
s − 1 pivots: P1, . . . , Ps−1
s classes c1, . . . , cs
Pivot Sampling: parameter t = (t1, . . . , ts) ∈ Ns
0
Example: s = 3, t = (1, 2, 3)
choose pivots from k = 8 sample items
0 1
U1 U2U3 U4U5 U6 U7
0 1
D D
= Dirichlet(t1 + 1, . . . , ts + 1)
E[H(C)] =
s
r=1
tr + 1
k + 1
Hk+1 − H
1
1 + 1
2 + 1
3 + · · · + 1
tr+1
tr+1 · log2(e)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 11 / 17