Data Structures & AlgorithmsModerateTCS NQT · comparisons

Problem: Which concept describes the minimum number of comparisons to find the maximum of n numbers?

  1. A. n log n comparisons
  2. B. n^2 comparisons
  3. C. n - 1 comparisons, which is optimal
  4. D. log n comparisons

Correct answer: C. n - 1 comparisons, which is optimal

Each comparison eliminates at most one candidate, so n - 1 comparisons are necessary and sufficient.

More Coding Interview Problems questions

Exams that ask this topic