Professional Documents
Culture Documents
Quick-Sort: Presentation For Use With The Textbook,, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Quick-Sort: Presentation For Use With The Textbook,, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Quick-Sort
7 4 9 6 2 → 2 4 6 7 9
4 2 → 2 4 7 9 → 7 9
2→2 9→9
7 4 9 6 2 → 2 4 6 7 9
4 2 → 2 4 7 9 → 7 9
2→2 9→9
© 2015 Goodrich and Tamassia Quick-Sort 4
Execution Example
Pivot selection
7 2 9 43 7 6 1 → 1 2 3 4 6 7 8 9
7 2 9 4 → 2 4 7 9 3 8 6 1 → 1 3 8 6
9→9 4→4
2 4 3 1→ 2 4 7 9 3 8 6 1 → 1 3 8 6
9→9 4→4
2 4 3 1 →→ 2 4 7 3 8 6 1 → 1 3 8 6
9→9 4→4
2 4 3 1 → 1 2 3 4 3 8 6 1 → 1 3 8 6
9→9 4→4
2 4 3 1 → 1 2 3 4 7 9 7 1 → 1 3 8 6
9→9 4→4
2 4 3 1 → 1 2 3 4 7 9 7 1 → 1 3 8 6
9→9 4→4
2 4 3 1 → 1 2 3 4 7 9 7 → 17 7 9
9→9 4→4
1 n-1
… …
n-1 1
© 2015 Goodrich and Tamassia Quick-Sort 12
Expected Running Time
Consider a recursive call of quick-sort on a sequence of size s
n Good call: the sizes of L and G are each less than 3s/4
n Bad call: one of L and G has size greater than 3s/4
7 2 9 43 7 6 19 7 2 9 43 7 6 1
2 4 3 1 7 9 7 1 → 1 1 7294376