Questions: Selection Algorithms: Finding the kth Smallest Element

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

To find the median of 1 million unsorted numbers, a programmer sorts the array and returns the middle element. A colleague claims there is a faster approach for this specific task. Which statement best explains the improvement?

ASorting integers can be done in O(n) time, so the sort-based approach is already optimal
BQuickselect can find the kth element in O(n) average time by recursing into only the relevant partition after each pivot step, avoiding the work of sorting both halves
CBinary search on the unsorted array finds the median in O(log n) time
DMerge sort is faster than quicksort for median-finding because it has no worst-case degradation
Question 2 Multiple Choice

A software engineer needs the 90th percentile value in a large dataset where worst-case latency guarantees are not required. She chooses Median-of-Medians over randomized quickselect. Is this a good practical choice?

AYes — Median-of-Medians always outperforms quickselect because its worst case is O(n)
BYes — Median-of-Medians is the standard implementation in C++ std::nth_element and NumPy
CNo — Median-of-Medians has a significantly larger constant factor (roughly 5-10x) making randomized quickselect faster in practice, despite quickselect's theoretical O(n²) worst case
DNo — Median-of-Medians does not guarantee finding the correct kth element
Question 3 True / False

Quickselect finds the kth smallest element in O(n log n) time on average — the same as sorting — but uses less memory.

TTrue
FFalse
Question 4 True / False

Randomized pivot selection makes quickselect's worst-case behavior astronomically unlikely in practice, even though the theoretical worst case remains O(n²).

TTrue
FFalse
Question 5 Short Answer

What is the key algorithmic difference between quickselect and quicksort that allows quickselect to run in O(n) average time while quicksort requires O(n log n)?

Think about your answer, then reveal below.