Data Structures & AlgorithmsVery hardGATE CS · Product placement

Top-down merge sort (split at mid = n // 2, recurse, then merge, stopping comparisons when one side runs out) sorts [33, 53, 13, 42, 11, 36, 5]. How many key comparisons does it make?

  1. A. 20
  2. B. 21
  3. C. 12
  4. D. 14

Correct answer: D. 14

Merges: [53|13] 1, [33|13,53] 2, [42|11] 1, [36|5] 1, [11,42|5,36] 3, [13,33,53|5,11,36,42] 6: total 14. Counting the leftover copies as comparisons gives 20, splitting at ⌈n/2⌉ gives 12, and 21 is the loose n⌈log₂ n⌉ bound.

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

Exams that ask this topic