GATE CSE
First time here? Checkout the FAQ!
x
0 votes
50 views

asked in Algorithms by Boss (5.3k points)   | 50 views

1 Answer

+4 votes
Best answer

In worst case, number of comparisons to merge two sorted lists of size m and n is m+n-1.

We take two lists of size 8 each, and merge them into a list of size 16. Comparisons needed = 8+8-1 = 15.

Similarly, to merge the other two lists of 8 elements, comparisons needed = 15.

We have two lists of size 16 and 16 now.

To merge them to a list of size 32, number of comparisons needed = 16+16-1 = 31.

Total comparisons = 15 + 15 + 31 = 61.

NOTE: In best case, we need max(m,n) comparisons. It happens when the last element of the first list is smaller than the first element of the second list.

answered by Boss (7.3k points)  
edited by
so nicely explained..thanx a lot..:)
welcome!


Top Users Mar 2017
  1. rude

    5118 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2730 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1382 Points

  9. Bikram

    1350 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,531 questions
26,861 answers
61,191 comments
23,207 users