GATE Computer ScienceHardGATE CS (PYQ pattern)

In the median-of-medians selection algorithm the input is split into groups of g elements (g odd), giving the standard recurrence T(n) ≤ T(n/g) + T((3g − 1)n/(4g)) + cn (ignoring floors). For which g in {3, 5, 7, 9} does this recurrence give T(n) = O(n)?

  1. A. 5 only
  2. B. 3, 5, 7 and 9
  3. C. 7 and 9 only
  4. D. 5, 7 and 9 only

Correct answer: D. 5, 7 and 9 only

Linear time needs the fractions to sum below 1: 1/g + (3g − 1)/(4g) = (3g + 3)/(4g) < 1 ⇔ g > 3. For g = 3 the sum is exactly 1 (T(n/3) + T(2n/3) + cn = Θ(n log n)); g = 5, 7, 9 give 9/10, 6/7, 5/6, all linear.

More Algorithms questions

Exams that ask this topic