214 views

1 Answer

1 votes
1 votes
option A.

Best case is when all the elements of the subarray with lesser number of elements are lesser than the subarray with greater number of elements. Hence the first element of the bigger subarray is compared with all the elements of the smaller subarray. And the rest of the elements are just copied from the bigger subarray to the temporary array without comparison. Thus number of comparison = min(m, n)

Worst case happens when all the elements except the last element of the smaller subarray is lesser than the first element of the bigger subarray. Without loss of generality let us take the length of the bigger subarray as m and the smaller one as n. Thus the first element of bigger subarray is compared with n – 1 elements. Now if the last element of the smaller subarray is greater than all the elements of the bigger subarray then it will be compared with all the m elements. Thus total number of comparisons = m + n – 1

Related questions

0 votes
0 votes
0 answers
1
rsansiya111 asked Dec 26, 2021
316 views
0 votes
0 votes
1 answer
2
rsansiya111 asked Dec 26, 2021
212 views
0 votes
0 votes
0 answers
3
rsansiya111 asked Dec 26, 2021
209 views
0 votes
0 votes
1 answer
4