retagged by
951 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.
retagged by

1 Answer

Best answer
2 votes
2 votes
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

Related questions

2 votes
2 votes
1 answer
1
Hirak asked May 21, 2019
1,242 views
.Given an array of distinct integers A[1, 2,…n]. Find the tightest upper bound to check the existence of any index i for which A[i]=i.Ans should be O(log n) right by do...
48 votes
48 votes
2 answers
2
Kathleen asked Sep 23, 2014
22,695 views
If one uses straight two-way merge sort algorithm to sort the following elements in ascending order: $20, \ 47, \ 15, \ 8, \ 9, \ 4, \ 40, \ 30, \ 12, \ 17$then the o...
0 votes
0 votes
1 answer
3
Hirak asked May 25, 2019
682 views
Minimum number of tables required to represent the relation R where the $A_n$ stands for the primary key of each entity is ___________
2 votes
2 votes
0 answers
4