Given two sorted list of size m and n respectively. The number of comparisons needed the worst case by the merge sort algorithm will be
(A) m x n
(B) maximum of m and n
(C) minimum of m and n
(D) m + n – 1
Explanation: To merge two lists of size m and n, we need to do m+n-1 comparisons in worst case. Since we need to merge 2 at a time, the optimal strategy would be to take smallest size lists first. The reason for picking smallest two items is to carry minimum items for repetition in merging.
So, option (D) is correct.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.