GATE | GATE CS 2019 | Question 46

There are n unsorted arrays: A1, A2, ….,An. Assume that n is odd. Each of A1, A2, …., An contains n distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of A1, A2, ….,An is ________ .

(A) Ο(n log n)
(B) Ο(n2)
(C) Ο(n)
(D) Ω(n2log n)

Answer: (B)

Explanation: Since given arrays are not sorted, so the time complexity to find median is O(n) in an unsorted array. You need to apply this apgorithm n time to find all medians and again once to find median of all these medians, so total time complexity is,

= O(n)*O(n) + O(n)
= O(n2) + O(n)
≈ O(n2) 

So, option (B) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :


Please write to us at to report any issue with the above content.