partition after the first round
Quick Sort
Quicksort: partitioning, the Java implementation, best/worst/average case, why we shuffle, duplicate keys, and how it compares with the other sorts.
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 39 slides
- 1 A l g o r i t h m s
- 2 Two classic sorting algorithms: mergesort and quicksort
- 3 Quicksort t-shirt
- 4 Slide 4
- 5 ocntime
- 6 join
- 7 3 7 2 4 1 5 9
- 8 Tony Hoare
- 9 Tony Hoare
- 10 Bob Sedgewick
- 11 Quicksort partitioning demo
- 12 ABCDEFGHijklmnoparstuvwxyz.pivf.iq too
- 13 Quicksort partitioning demo
- 14 Quicksort: Java code for partitioning
- 15 Quicksort: Java implementation
- 16 Quicksort trace
- 17 Quicksort animation
- 18 Quicksort: implementation details
- 19 Quicksort: empirical analysis (1961)
- 20 Quicksort: empirical analysis
- 21 perfectly geg
- 22 sorted
- 23 Quicksort: average-case analysis
- 24 Quicksort: average-case analysis
- 25 Quicksort: average-case analysis
- 26 Quicksort: average-case analysis
- 27 Quicksort: average-case analysis
- 28 Quicksort: summary of performance characteristics
- 29 Quicksort properties
- 30 Slide 30
- 31 Duplicate keys
- 32 Duplicate keys
- 33 What is the result of partitioning the following array?
- 34 Partitioning an array with all equal keys
- 35 Duplicate keys: the problem
- 36 Sorting summary
- 37 System sort in Java 7
- 38 Slide 38
- 39 swap
Quicksort partitioning demo
Notes
Partition around a pivot: smaller items left, larger right; the pivot lands in its final place.
Exam angle
Quicksort: Java implementation
Notes
Shuffle first, partition, then sort each part recursively.
perfectly geg
Notes
Best case: ~N lg N compares. Worst case (already sorted, no shuffle): ~N²/2.
Exam angle
which sequence makes quicksort O(n²)
Without shuffling, quicksort (first element as pivot) is slowest on:
- Quiz 2.
Quicksort: summary of performance characteristics
Notes
Average ~1.39 N lg N compares; in place; not stable.
Exam angle
Quicksort’s average running time is:
Sorting summary
Notes
Summary: selection n²/2, insertion n²/4 average, merge N lg N (stable, extra space), quick 1.39 N lg N (in place, fastest in practice).