Question
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
Official answer and solution
- Official answer
- C
- From
- Official GATE 2019 answer key
Solution
Analyze the time required to find the median of each array and then the median of those medians.
We are given unsorted arrays , each of size with pairwise distinct elements.
Step 1: Compute the median of each array:
Using a linear-time selection algorithm (such as the Median-of-Medians / Quickselect algorithm), the median of an unsorted array of size can be found in worst-case time.
Since there are such arrays, computing the median for all arrays takes:
Step 2: Compute the median of the medians:
We now have a list of medians .
Finding the median of these numbers using the linear-time selection algorithm takes worst-case time.
Total Time:
C
Sorting each array in O(n log n) time to find its median, which gives O(n^2 log n), forgetting that linear-time selection exists.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2019 Computer Science and Information Technology (CS)
- Question
- 47 of 65, printed as CS Q.37
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.