Open In App

GATE | GATE CS 2019 | Question 46

Like Article
Like
Save
Share
Report

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 algorithm n time to find all medians and again once to find the 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
Please comment below if you find anything wrong in the above post


Last Updated : 02 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads