Data Structures & AlgorithmsVery hardICPC regional · selection

Problem: Which is the worst-case time complexity of the median-of-medians selection algorithm for finding the k-th smallest element of n numbers?

  1. A. O(n log n) on average only
  2. B. O(n^2) worst case
  3. C. O(n log k) worst case
  4. D. O(n) worst case

Correct answer: D. O(n) worst case

Choosing the pivot as the median of groups of five guarantees a constant fraction is discarded, giving a linear recurrence T(n) = T(n/5) + T(7n/10) + O(n).

More Coding Interview Problems questions

Exams that ask this topic