Skip to content
Official PYQ · 1995

GATE CS 1995 Q1.16 — Searching, Sorting, Hashing

Explain with AI

For merging two sorted lists of sizes mm and nn into a sorted list of size m+nm+n, we require comparisons of

Choose one option
View worked solution

Answer: C

To merge two sorted lists of sizes mm and nn into a single sorted list of size m+nm+n, we use the standard two-pointer merging technique:

  1. Compare the elements at the current pointers of both lists.
  2. Append the smaller element to the merged list and advance its corresponding pointer.
  3. Repeat this process until one of the lists is completely traversed, then copy the remaining elements of the other list directly.

Complexity Analysis:

  • Best-case comparisons: min⁡(m,n)\min(m, n) (when all elements of one list are smaller than the smallest element of the other list).
  • Worst-case comparisons: m+n−1m + n - 1 (when the elements of the two lists are interleaved, requiring comparisons until only one element remains).

In the asymptotic sense, the number of comparisons required is O(m+n)O(m+n).

Therefore, the correct option is C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions