GATE Computer ScienceHardGATE CS (PYQ pattern)

The maximum and the minimum of n numbers are found by divide and conquer: a list of 1 element needs 0 comparisons, 2 elements need 1; a larger list is split into ⌈n/2⌉ and ⌊n/2⌋ elements, solved recursively, and combined with 2 comparisons. How many comparisons does this make for n = 100?

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

Correct answer: B. 162

C(3) = C(2) + C(1) + 2 = 3, C(4) = 4, C(6) = 8, C(7) = 9, C(12) = 18, C(13) = 19, C(25) = 39, C(50) = 80, C(100) = 162. The pairing method needs only 3n/2 − 2 = 148: divide and conquer reaches that only when n is a power of 2, and splits producing odd parts (25, 13, 7, 3) waste comparisons.

More Algorithms questions

Exams that ask this topic