in Algorithms edited by
2,464 views
1 vote
1 vote
Can pls someome. Tell.number of comparisons in. Merge sort in best case as well as worst case.

Acc to. Me, at. Each level we need O(n) comaprisons and number of levels are log n in merge sort(whether it. Is a best case or worst case).hence mumber o comparisons should be nlogn in worst case as well as best case.

 

Pls guide me.
in Algorithms edited by
2.5k views

1 comment

standard merge sort can't stop in between so best ,avg, worst will have O(nlogn)
0
0

2 Answers

0 votes
0 votes
In merge sort whatever may be sequence of inputs average best worst all cases has same nlogn complexity

Each level we need O(n) comaprisons and number of levels are log n in merge sort  is true
by

3 Comments

If we write in asymptotic notation then no of comparison in both the case = O(nlog n).

But if we have to find exact no of comp. in the best case and in the worst case then following two example can help - 

Best case   - 1, 2, 3, 4, 5, 6, 7, 8

Total no of comparisons = 12.

Worst case - 2, 5, 8, 4, 1, 7, 6, 3

Total no of comp.           = 17.   

0
0
what is the number of comparision if it will be two way merge sort?
0
0
How are you counting the total number of comparisions.. Please help..
0
0
0 votes
0 votes

in worst case number of comparisions required  nlogn 

in best case it is half = nlogn/2

Related questions