Data Structures & AlgorithmsVery hardProduct-company MCQ pattern

What is the minimum number of comparisons needed, in the worst case, to find BOTH the maximum and the minimum of 100 distinct numbers?

  1. A. 150
  2. B. 100
  3. C. 198
  4. D. 148

Correct answer: D. 148

Compare elements in pairs (50 comparisons), then find the max among the 50 winners (49) and the min among the 50 losers (49): 50 + 49 + 49 = 148 = ⌈3n/2⌉ − 2. Separate scans for max and min need 2(n − 1) = 198.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic