Data Structures & AlgorithmsHardGATE CS · Product placement

The median-of-medians (groups of 5) selection algorithm is used to choose a pivot. What does it guarantee?

  1. A. Worst-case O(n) time for finding the k-th smallest element
  2. B. A perfectly balanced 50/50 split every time
  3. C. Worst-case O(log n) time
  4. D. Expected O(n log n) time

Correct answer: A. Worst-case O(n) time for finding the k-th smallest element

The pivot is guaranteed to have at least about 3n/10 elements on each side, giving T(n) ≤ T(n/5) + T(7n/10) + O(n) = O(n) in the worst case.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic