GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 37

Selecting a median of medians

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2019 paper

GATE 2019, Q37 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 37, GATE 2019: There are n unsorted arrays, n odd, each containing n distinct elements; different arrays have no common elements. Find the worst-case complexity of computing the median of the n array medians. Choices A O(n), B O(n log n), C O(n²), D Ω(n² log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. The median of n distinct values for odd n is their order statistic of rank (n+1)/2. Finding that one rank does not require sorting every value.
2. Apply deterministic worst-case linear-time selection to each array. The median-of-medians selection algorithm, for example, finds an exact order statistic in O(n) time per array.
3. There are n arrays, so obtaining all their medians costs n×O(n)=O(n²). Store the n resulting medians in a separate array.
4. Apply linear-time selection once more to those n medians. This adds O(n), so the total remains O(n²), identifying C. The desired statistic is the median of array medians, which is not in general the median of all n² input values.
5. Sorting each original array would cost O(n² log n) and is unnecessary. Worst-case exact selection on arbitrary unsorted rows requires inspecting linearly many entries in potentially decisive rows; the general problem has quadratic worst-case scale, not O(n) or O(n log n) in the row count n. Randomized quickselect offers expected linear selection, but deterministic selection is what directly justifies the worst-case bound here.

Original paper, page 12 · Answer key