GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 1.16

Merging sorted lists

Algorithms · Searching, Sorting & Selection · Full GATE CSE 1995 paper

GATE 1995, Q1.16 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 1.16, GATE 1995: How many comparisons asymptotically suffice to merge sorted lists of sizes m and n into one sorted list?
Question 1.16, GATE 1995: How many comparisons asymptotically suffice to merge sorted lists of sizes m and n into one sorted list?
Tap to enlarge
Your answer
Answer & solution

Answer: C: O(m+n) (no official key was published)

Compare the two current front items, emit the smaller and advance that list. Every comparison emits one item, and once one list is exhausted the remaining items can be copied without further comparisons. At most m+n−1 comparisons are therefore needed when both lists are nonempty. Balanced interleavings can attain this bound, giving linear worst-case work. Merely searching in logarithmic time would not output the entire merged list; the standard merge exploits the existing order of both inputs.

Original paper, page 2