There are unsorted arrays: . Assume that is odd.Each of contains distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of is
GATE CSE 2019Algorithms › Growth of Functions & Complexity AnalysisVerified
GATE CSE 2019 PYQ: There are n n n unsorted arrays: A 1 , A 2 , … , A n A_1, A_2, \dots, A_n A 1 , A 2 , … , A n . Assume…
- A
- B
- CCorrect answer
- D
Answer
(C) O ( n 2 ) O(n^2) O ( n 2 )
Approach
The task decomposes into: (1) find the median of each of the n unsorted arrays, each of size n; (2) collect these n medians into a new list; (3) find the median of that list. Since each array can be processed independently, use a linear-time deterministic selection algorithm for each array, and then for the final list.
The fastest known deterministic method finds each array's median in O(n) time, so n arrays take $O(n^2)$. The final median of the n medians costs only O(n), giving overall $O(n^2)$. Option C is correct.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.