Quicksort and selection
1.[2p] Lomuto partitioning of an array of 8 elements makes how many comparisons?
Lomuto partitioning of an array of 8 elements makes how many comparisons?
2.[3p] A textbook quicksort that always takes the last element as pivot is quadratic on
A textbook quicksort that always takes the last element as pivot is quadratic on
The answer is: already sorted input, because the pivot is the maximum every time
The answer is: already sorted input, because the pivot is the maximum every time
The answer is: already sorted input, because the pivot is the maximum every time
3.[3p] Using with , how many comparisons does quicksort average on 1000 elements?
Using with , how many comparisons does quicksort average on 1000 elements?
4.[3p] Quicksort averages about 39 per cent more comparisons than mergesort's worst case and is still usually faster because
Quicksort averages about 39 per cent more comparisons than mergesort's worst case and is still usually faster because
The answer is: it moves far less data, allocates nothing, and scans memory sequentially
The answer is: it moves far less data, allocates nothing, and scans memory sequentially
The answer is: it moves far less data, allocates nothing, and scans memory sequentially
5.[3p] Choosing the pivot uniformly at random changes the analysis because
Choosing the pivot uniformly at random changes the analysis because
The answer is: the expected cost no longer depends on the arrangement of the input at all
The answer is: the expected cost no longer depends on the arrangement of the input at all
The answer is: the expected cost no longer depends on the arrangement of the input at all
6.[2p] Median-of-three pivot selection guarantees that quicksort avoids its quadratic case.
Median-of-three pivot selection guarantees that quicksort avoids its quadratic case.
The answer is: False
7.[2p] Introsort achieves a worst-case bound by
Introsort achieves a worst-case bound by
The answer is: switching to heapsort once the recursion depth exceeds about
The answer is: switching to heapsort once the recursion depth exceeds about
The answer is: switching to heapsort once the recursion depth exceeds about
8.[3p] Quickselect is on average rather than because
Quickselect is on average rather than because
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under
9.[3p] Match each algorithm to its worst-case cost.
Match each algorithm to its worst-case cost.
Mergesort
Randomised quicksort
Introsort
Median-of-medians selection
Show the answer
Mergesort: Randomised quicksort: Introsort: Median-of-medians selection: