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

asked in Algorithms by Loyal (4.7k points)   | 49 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 (6.8k points)  
edited by
so nicely explained..thanx a lot..:)
welcome!
Top Users Feb 2017
  1. Arjun

    5410 Points

  2. Bikram

    4230 Points

  3. Habibkhan

    3952 Points

  4. Aboveallplayer

    3086 Points

  5. Debashish Deka

    2564 Points

  6. sriv_shubham

    2318 Points

  7. Smriti012

    2240 Points

  8. Arnabi

    2008 Points

  9. mcjoshi

    1696 Points

  10. sh!va

    1684 Points

Monthly Topper: Rs. 500 gift card

20,864 questions
26,030 answers
59,704 comments
22,144 users