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
294
Embed
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Practical Potential
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Dual-Pivot Quicksort and BeyondAnalysis 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
Dual-P??? Q?????? and BeyondAnalysis 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
Dual-Pivot Quicksort and BeyondAnalysis 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
What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
What do you think when you hear sorting?
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
Two meanings of sorting
1Separate different sorts
of things
2Put items into order
(alphabetical, numerical, . . . )
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
Two meanings of sorting
1Separate different sorts
of things
2Put items into order
(alphabetical, numerical, . . . )
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
Two meanings of sorting
1Separate different sorts
of things
2Put items into order
(alphabetical, numerical, . . . )
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 17
What is sorting?
Two meanings of sorting
1Separate different sorts
of things
2Put items into order
(alphabetical, numerical, . . . )
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 2 / 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
conventionalwisdom
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
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.
conventionalwisdom
till 2009!
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 5 / 17
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
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
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
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
tim
e
10−6·n
lnn
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
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
Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysisprove eternal truths
not experiments
Mathematical Analysisprove eternal truths
not experiments
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysisprove 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
Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysisprove eternal truths
not experiments
What is multiway partitioning?generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksortcosts on average for large inputs
parametric (algorithm and cost measure)
Unified Analysis of Quicksortcosts on average for large inputs
parametric (algorithm and cost measure)
Sebastian Wild Dual-Pivot Quicksort and Beyond 2016-07-08 7 / 17
Overview of my work
My Thesis
Multiway partitioning has genuine
potential to speed up Quicksort.
Mathematical Analysisprove eternal truths
not experiments
What is multiway partitioning?generalize existing Quicksort variants
generic s-way one-pass partitioning
with pivot sampling
Unified Analysis of Quicksortcosts on average for large inputs