Skip to content
Official PYQ · 2019

GATE CS 2019 Q37 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

There are nn unsorted arrays: A1,A2,…,AnA_1, A_2, \dots, A_n. Assume that nn is odd.Each of A1,A2,…,AnA_1, A_2, \dots, A_n contains nn 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,…,AnA_1, A_2, \dots , A_n is

Choose one option
View worked solution

Answer: C

To find the median of the medians of nn unsorted arrays A1,A2,…,AnA_1, A_2, \dots, A_n, each containing nn distinct elements, we can break the process down into two main steps:

  1. Find the median of each individual array:

    Each array AiA_i is unsorted and has nn elements. The median of an unsorted array of size nn can be found in O(n)O(n) worst-case time using a linear-time selection algorithm (such as the Median of Medians algorithm).

    Since there are nn such arrays, the total time required to find the medians of all nn arrays is:

    n×O(n)=O(n2)n \times O(n) = O(n^2)
  2. Find the median of the computed medians:

    Let the medians of the nn arrays be m1,m2,…,mnm_1, m_2, \dots, m_n. This is a set of nn elements. Finding the median of these nn elements takes:

    O(n) timeO(n) \text{ time}

Total Worst-Case Time Complexity:

Combining both steps, the overall worst-case time complexity is:

T(n)=O(n2)+O(n)=O(n2)T(n) = O(n^2) + O(n) = O(n^2)

Hence, the correct option is C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions