2,464 views
1 votes
1 votes
T(n) = 2T(n/2) + C

2 Answers

0 votes
0 votes

T(n) = 2T(n/2) + c

If you draw the recursion tree, you find constants at every level. Height of the tree is log n. It is easy to see that the number of constants at every level is the number of recursvie calls at that level!
Level Constants
n c
n/2,n/2 2c
n/4,n/4,n/4,n/4 4c

Last level will have 2log2(n)

terms, hence 2log2(n)∗c=cn

(Note - its log base 2)

This is because for every recursion you have a constant c. (Usually the constants are ignored, but for this case it is easier to see the problem as constants)

So, T(n) = c + 2c + 4c + ...... + nc

The above summation can be intimidating initially, until you realize it is the same as the number of nodes in the tree. We now know that there are n leaves 2log2(n)=n

. Therefore, we have n-1 internal nodes. So, the total number of nodes in the tree is n+n-1 = 2n-1.

Hence, T(n) = 2n-1 = O(n); the solution using recursion method.

0 votes
0 votes
use master theorem

according to master theorem f(n) = c, a = 2, b = 2

compare f(n) and n^log a base b

so c , n ^ [log 2 to base 2 is 1]

n is polynomial times greater than c[constant]

so theta(n)

Related questions