Data Structures & AlgorithmsVery hardICPC regional · algorithm theory

Problem: What is the minimum number of comparisons in the worst case to find both the maximum and the minimum of n = 10 distinct elements using pairwise comparisons?

  1. A. 15
  2. B. 18
  3. C. 13
  4. D. 10

Correct answer: C. 13

Pairing elements costs 3n/2 - 2 = 13 comparisons for even n, which is better than 2n - 2 = 18 from scanning twice.

More Coding Interview Problems questions

Exams that ask this topic