Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

Two sorted lists of 5 and 7 elements are merged by the standard merge procedure. What is the maximum number of comparisons it can make?

  1. A. 12
  2. B. 35
  3. C. 11
  4. D. 7

Correct answer: C. 11

Every comparison outputs one element, and once one list runs out the rest is copied without comparing, so at most m + n − 1 = 11 comparisons are made (when the lists interleave to the end). The minimum is min(m, n) = 5.

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

Exams that ask this topic