I knew quickselect going in so the core answer came out fine.
Use Quickselect (randomized partition) to find the k-th smallest element in expected O(n) time. Explain the algorithm, analyze average vs worst-case complexity, and discuss pivot selection strategies. For the deterministic alternative, describe the Median of Medians algorithm.
Pro tip: Emphasize that randomization makes worst-case unlikely and that Median of Medians guarantees O(n) but with higher constants; in practice, randomized Quickselect is often preferred.
Confirm that the array is unsorted, elements are integers, and k is 1-indexed. Ask about duplicates and whether the array can be modified.
Describe partitioning around a pivot, then recursively selecting the side containing the k-th element. Mention that it's in-place and expected O(n).
Compare random pivot vs first/last pivot. Explain average O(n) and worst-case O(n^2) for random pivot, and how Median of Medians gives worst-case O(n).
Talk about deterministic alternative (Median of Medians), its overhead, and when to use each. Mention that sorting would be O(n log n) and is unnecessary.
Reiterate the expected O(n) solution, acknowledge worst-case, and state that randomized Quickselect is practical while Median of Medians is theoretically robust.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.