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

asked in Algorithms by Boss (5.9k points)   | 52 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.9k points)  
edited by
so nicely explained..thanx a lot..:)
welcome!


Top Users May 2017
  1. akash.dinkar12

    3146 Points

  2. pawan kumarln

    1608 Points

  3. sh!va

    1580 Points

  4. Arjun

    1326 Points

  5. Devshree Dubey

    1230 Points

  6. Angkit

    1028 Points

  7. Debashish Deka

    1012 Points

  8. Bikram

    970 Points

  9. LeenSharma

    810 Points

  10. srestha

    662 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. pawan kumarln

    234 Points

  2. Ahwan

    118 Points

  3. jjayantamahata

    106 Points

  4. joshi_nitish

    106 Points

  5. Aditya GN

    63 Points


22,722 questions
29,048 answers
65,039 comments
27,510 users