Data Structures & AlgorithmsHardGoogle · Flipkart interview

Which statement about selecting the k-th smallest of n unsorted numbers is correct?

  1. A. Quickselect is O(n log n) expected, the same as sorting
  2. B. A min-heap of size k gives O(n) worst case for any k
  3. C. Quickselect is O(n) expected but O(n²) worst case; median-of-medians pivoting makes it O(n) worst case
  4. D. Median-of-medians is O(n log n) worst case but faster in practice than quickselect

Correct answer: C. Quickselect is O(n) expected but O(n²) worst case; median-of-medians pivoting makes it O(n) worst case

Quickselect recurses into one side only, so expected work is n + n/2 + … = O(n); bad pivots give O(n²). Grouping into 5s and taking the median of medians guarantees a 30–70 split, so T(n) ≤ T(n/5) + T(7n/10) + O(n) = O(n). A size-k heap costs O(n log k).

More Coding Interview Problems questions

Exams that ask this topic