4,193 views
6 6 votes

Q . In the standard merge sort algorithm on a list of size n, what is the maximum number of times an item can be compared?

a)2

b)logn

c)n-1

d)NOT

My doubt is here ,Are we considering a specific Item throughout our Analysis.?

3 Answers

10 10 votes

Let us consider n=2k

let at level i , L1 and L2 is merged,

An item in L1 is compared maximum times when all the items in L2 is less than item in L1.

Say at leaf level k (level at smallest subproblem having one element in each list), an item is compared only once when merging.

at level k-1  an item is compared twice when merging.

say at level i , it is compared n/2i times

at level 2 it is compare n/2 times and after merging we get the sorted array of our problem

total comparison of an item = n/2+ n/(22)+. . . . +   .n/(2k)    where n/(2k) =1

                                          = n*(1-1/(2k))

                                          = n - n/(2k)

                                          = n-1

Answer is c) n-1.

Correct me if I am Wrong

0 0 votes
the answer will be (n-1). Take any array and compute the sort with the worst case.you will get it!
Position:
Show:

Related questions

1 1 vote
2 2 answers
3.0k
3.0k views
Akriti sood asked Oct 28, 2016
3,048 views
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...
1 1 vote
1 1 answer
180
180 views
GO Classes asked Aug 10
180 views
Mergesort recursively sorts the two halves of an array.After both recursive calls have finished, but before the merge operation, which statement must be true?The complete...
1 1 vote
4 4 answers
5.7k
5.7k views
iarnav asked Apr 25, 2019
5,695 views
In Merge sort Algorithm when I took input array of size 2 and I got 4 function calls as including original function call with which I call MS algorithm i.e. MS (1,2) and ...
0 0 votes
0 0 answers
1.0k
1.0k views
Nandkishor3939 asked Jan 21, 2019
1,013 views
What is the extra memory needed for merge sort:1] In case of Iterative merge sort.(DS:Array)2]In case of Recursive merge sort.(DS:Array)3] In case of Iterative merge sort...