GATE Computer ScienceModerateGATE CS (PYQ pattern)

What is the minimum number of comparisons that guarantees finding the second largest of 1025 distinct numbers in the worst case?

  1. A. 1033
  2. B. 1034
  3. C. 1035
  4. D. 2047

Correct answer: B. 1034

The optimal bound is n + ⌈log₂ n⌉ − 2. Since 1024 < 1025, ⌈log₂ 1025⌉ = 11, giving 1025 + 11 − 2 = 1034: a knockout tournament (1024 comparisons) whose winner played up to 11 matches, then 10 comparisons among those 11 losers. Using log₂ ≈ 10 gives the trap 1033.

More Algorithms questions

Exams that ask this topic