For merging two sorted lists of sizes and into a sorted list of size , we require comparisons of
View worked solution
Answer: C
To merge two sorted lists of sizes and into a single sorted list of size , we use the standard two-pointer merging technique:
- Compare the elements at the current pointers of both lists.
- Append the smaller element to the merged list and advance its corresponding pointer.
- 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: (when all elements of one list are smaller than the smallest element of the other list).
- Worst-case comparisons: (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 .
Therefore, the correct option is C.
Free practice · Your answers on this page are not saved.
