Skip to content
GATEiit

GATE CSE 2019 Q47: Worst-case time to find the median of medians of n arrays of size n

Syllabus topics: Algorithm design techniques: greedy, dynamic programming and divide-and-conquer; Asymptotic worst-case time and space complexity

Question

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

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: C (official GATE 2019 final answer key)

Concept used: The median (any order statistic) of m unsorted elements can be found in worst-case O(m) time with the linear-time selection algorithm.

Concept notes

Loading notes…

First step: Count the cost of finding each array's median with linear-time selection, add up over the n arrays, then add the cost of one more selection on the n medians.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Algorithm design techniques: greedy, dynamic programming and divide-and-conquer

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key