I knew quick select right away but the whole point was that they wanted something better for worst-case.
Acknowledge that QuickSelect has average O(n) but worst-case O(n^2), then propose the Median of Medians algorithm to guarantee O(n) worst-case. Explain the algorithm's steps and analyze its time complexity, noting the trade-off of higher constant factors.
Pro tip: Mention that while Median of Medians guarantees O(n) worst-case, it's rarely used in practice due to high constants; instead, randomized QuickSelect with a fallback or introselect is often preferred. This shows awareness of practical engineering trade-offs.
Clarify that the goal is to find the k-th smallest element in an array with the best worst-case time complexity, and that QuickSelect's worst-case is O(n^2).
Explain the algorithm: divide the array into groups of 5, find the median of each group, recursively find the median of medians to use as a pivot, then partition the array around this pivot.
Show that the recurrence T(n) <= T(n/5) + T(7n/10) + O(n) solves to O(n) worst-case, using the fact that at least 30% of elements are eliminated each partition.
Compare with randomized QuickSelect: Median of Medians has higher constant factors and is slower in practice, but guarantees worst-case linear time. Mention that introselect (used in C++ STL) combines both.
Summarize that for theoretical worst-case guarantees, Median of Medians is the answer; for practical use, randomized QuickSelect with fallback is often preferred.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.