3,970 views
1 votes
1 votes
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 which in turn calls two recursive function calls to merge sort as MS (1,1) and MS (2,2) and one function call to merge procedure as Merge (1,1,2)


Likewise for input array of size 3 I got 7 function calls.

for input array of size 6 I got 16 function calls.
So, how can I analyze the total number of function calls when input array size is n?


thank you!

4 Answers

4 votes
4 votes
For Merge Sort

no of times Merge Sort called = $2n - 1$

no of times merge is called = $n-1$
2 votes
2 votes
For ‘Merge-sort’ the number of function calls can be represented by T(n)

$T(n)=2T(\frac{n}{2})+2$, and T(2)=2

Solving which we get 2n-2, we add 1 for call from the main function, therefore (2n-1).

SImilarly for ‘Merge’ function

$T(n)=2T(\frac{n}{2})+1$ and T(2)=1

Which comes out to be (n-1).
0 votes
0 votes

for n=2    4 calls

for n=3    7 calls

for n=6     16 calls

thus for “n” calls “3n-2” calls

0 votes
0 votes

Total number of MERGESORT() calls = 2n-1

Total number of RECURSIVE MERGESORT() calls = 2n-2 (The very first call will not be a recursive call)

Total number of MERGE() calls = n-1

Related questions

1 votes
1 votes
1 answer
1
rahul sharma 5 asked Mar 9, 2018
1,317 views
Consider the modified merge sort where we divide array into 5 equal sub arrays instead if 2(as in standard merge sort).What is the time complexity if modified merge sort?...
2 votes
2 votes
2 answers
2
sumit goyal 1 asked Aug 9, 2017
725 views
HOW NO. OF LEVELS IS LOG N + 1 CAN ANYONE HELP ME , how to solve this and get log n + 1
0 votes
0 votes
0 answers
3
Nandkishor3939 asked Jan 21, 2019
698 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...
0 votes
0 votes
0 answers
4
Vikas123 asked Jan 8, 2019
1,034 views
Can anyone help me to understand this problem….??