For merging two sorted lists of sizes m and n into a sorted list of si...
Each comparison will append one item to the existing merge list. In the worst case one needs m + n -1 comparisons which is of order m+ n.
View all questions of this testFor merging two sorted lists of sizes m and n into a sorted list of si...
Explanation:
When merging two sorted lists of sizes m and n into a sorted list of size m+n, the time complexity is determined by the number of comparisons required to merge the two lists.
Merging process:
The merging process involves comparing the elements of the two lists and adding the smaller element to the new merged list. This process is repeated until all the elements of both lists have been added to the merged list.
Time Complexity:
The time complexity of merging two sorted lists of sizes m and n into a sorted list of size m+n is O(m+n), as each element of both lists is compared only once.
Explanation of other options:
Option A: O(m) - This is incorrect as the time complexity of merging two sorted lists is dependent on both m and n, not just m.
Option B: O(n) - This is incorrect for the same reason as Option A.
Option D: O(log(m) + log(n)) - This is incorrect as it assumes that the lists are binary search trees, which is not specified in the question.
Therefore, the correct answer is Option C: O(m+n).