Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Quicksort and selection

1.[2p]

Lomuto partitioning of an array of 8 elements makes how many comparisons?

CorrectNot quite: 7

2.[3p]

A textbook quicksort that always takes the last element as pivot is quadratic on

Correct
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 C(n)=2(n+1)Hn-4n with H1000=7.485, how many comparisons does quicksort average on 1000 elements?

CorrectNot quite: 10986

4.[3p]

Quicksort averages about 39 per cent more comparisons than mergesort's worst case and is still usually faster because

Correct
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

Correct
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.

The answer is: False
Correct

7.[2p]

Introsort achieves a worst-case Θ(nlogn) bound by

Correct
The answer is: switching to heapsort once the recursion depth exceeds about $2\log_2 n$
The answer is: switching to heapsort once the recursion depth exceeds about $2\log_2 n$
The answer is: switching to heapsort once the recursion depth exceeds about $2\log_2 n$

8.[3p]

Quickselect is Θ(n) on average rather than Θ(nlogn) because

Correct
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under $2n$
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under $2n$
The answer is: it recurses into one side only, so the level costs form a geometric series summing to under $2n$

9.[3p]

Match each algorithm to its worst-case cost.

  • Mergesort

  • Randomised quicksort

  • Introsort

  • Median-of-medians selection

  • Θ(nlogn)

  • Θ(nlogn)

  • Θ(n)

  • Θ(n2)

Show the answer

Mergesort: Θ(nlogn) Randomised quicksort: Θ(n2) Introsort: Θ(nlogn) Median-of-medians selection: Θ(n)