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)?
- A. 5 only
- B. 3, 5, 7 and 9
- C. 7 and 9 only
- 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
- n keys, each an n-bit unsigned integer, are sorted by LSD radix sort that treats each key as digits of r = ⌊log₂ n⌋ bits (radix 2^r) and…
- Two sorted lists of 5 and 7 distinct keys are to be merged into one sorted list by comparisons. What does the decision-tree…
- Cocktail-shaker sort is applied to [5, 1, 4, 2, 8, 0, 3]: sweeps alternate left-to-right and right-to-left over the unsorted part (each…
- In randomised quicksort on n = 10 distinct keys (pivot chosen uniformly, so two keys with ranks i < j are compared with probability 2/(j −…
- Multiplying two n × n matrices classically costs n³ multiplications and n²(n − 1) additions. One level of Strassen (7 products of n/2 ×…
- Karatsuba multiplies two n-digit numbers (n = 2^k) with 3 half-size products, recursing down to 1-digit numbers; the classical method uses…