Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

How many comparisons does top-down merge sort (split in halves, stop comparing when one side runs out) make on [5, 1, 7, 3, 20, 15, 30, 25]?

  1. A. 24
  2. B. 17
  3. C. 13
  4. D. 16

Correct answer: C. 13

Four pair merges take 1 each (4). [1,5] with [3,7] takes 3; [15,20] with [25,30] takes 2 (the left side runs out). The final merge of [1,3,5,7] with [15,20,25,30] takes only 4, so 4 + 5 + 4 = 13. 17 is the worst case for 8 elements, not this input.

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

Exams that ask this topic