GATE Computer ScienceEasyGATE CS (PYQ pattern)

What is the minimum number of comparisons that guarantees finding the median (the third smallest) of 5 distinct elements in the worst case?

  1. A. 5
  2. B. 7
  3. C. 8
  4. D. 6

Correct answer: D. 6

An exhaustive minimax search over the 120 orderings shows 6 comparisons suffice and 5 do not; sorting first would cost 7. Finding the median needs fewer comparisons than a full sort because the relative order of the other four need not be known.

More Algorithms questions

Exams that ask this topic