Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft

Top-down merge sort (split at mid = n // 2, recurse, then merge, stopping comparisons when one side runs out) sorts [10, 29, 19, 28, 32, 42, 4, 44]. How many key comparisons does it make?

  1. A. 15
  2. B. 24
  3. C. 17
  4. D. 28

Correct answer: A. 15

Adding the comparisons of the seven merges gives 15; a merge stops as soon as one side runs out, so early exhaustion saves comparisons. 17 is the worst case for n = 8, 24 also counts the leftover copies, and 28 = n(n − 1)/2 is a quadratic sort.

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

Exams that ask this topic