in Algorithms retagged by
950 views
0 votes
0 votes
Find the total number of comparisons if merge sort is used. Explain with proper steps.

2, 5, 8, 4, 1, 7, 6, 3

Total no of comparison.
in Algorithms retagged by
by
950 views

2 Comments

is it 17?
0
0
yes..

Please explain, i am not able to understand the procedure to count the total number of comparisions

Thank you in advance.. :)
0
0

1 Answer

2 votes
2 votes
Best answer
2, 5, 8, 4, 1, 7, 6, 3

 

break them in 2 halves.
2, 5, 8, 4,                            1, 7, 6, 3

 

Break each of them in 2 halves.
2, 5,           8, 4,                  1, 7,           6, 3

Break each of them in 2 halves.
2,     5,      8,      4,     1,    7,     6,     3

 

Sort and combine adjacent 2 at a time by comparing them.
2,5           4,8             1,7              6,3  
No of comparisons done? = $4$

 

Sort and combine adjacent 2 at a time by comparing them.
2,4,5,8             1,3,6,7  
No of comparisons done? = 3+3=$6$
Notice that in 1st case you compare 2 and 4 and select 2. Then compare 4 and 5 and select 4. Then compare 5 and 8 and select 5. Now no need to compare 8 with anything just select it at last. So total 3 comparisons.

Sort and combine adjacent 2 at a time by comparing them.
1,2,3,4,5,6,7,8
No of comparisons done? = 7 for a similar reason as above.

So total = 4+6+7=$17$
selected by

1 comment

Thanks a TON for Helping..

Love and good wishes.. :)
0
0