GATE Computer ScienceHardGATE CS (PYQ pattern)

For n = 5 distinct keys, let M be the worst-case comparisons of top-down merge sort (split ⌈n/2⌉ + ⌊n/2⌋, merge stops when one side is empty), B the worst-case comparisons of binary insertion sort, and O the minimum worst-case comparisons of any comparison sort. What is (M, B, O)?

  1. A. (8, 8, 7)
  2. B. (8, 7, 7)
  3. C. (7, 8, 7)
  4. D. (9, 8, 7)

Correct answer: A. (8, 8, 7)

M: sorting 3 costs 3 and 2 costs 1, plus a final merge of 4: 8. B: inserting the k-th key into k − 1 sorted keys costs ⌈log₂ k⌉: 1 + 2 + 2 + 3 = 8. O = 7 = ⌈log₂ 120⌉, achieved by a special merge-insertion scheme. Brute force over all 120 inputs confirms M = B = 8.

More Algorithms questions

Exams that ask this topic