retagged by
17,708 views
7 votes
7 votes
T.C of T(n)=2T(n-1)+n,n > 1 ,T(1)=1 ?
retagged by

3 Answers

Best answer
14 votes
14 votes

$T(n) = 2T(n-1)+n \\= 2^2T(n-2) + 2(n-1) + n \\=2^3T(n-3) + 2^2(n-2) + 2(n-1) + n \\ .\\. \\.\\=2^{n-1}T(n-(n-1)) + 2^{n-2}(n-(n-2)) + 2^{n-3}(n-(n-3)) + \dots + 2(n-1) + n \\=  2^{n-1}T(1) +  2^{n-2} .2 + 2^{n-3}.3 + \dots + 2(n-1) + n$ $\to (1)$

Now multiply $T(n)$ By 2

$2T(n)=2^n+ 2^{n-1}.2 + 2^{n-2}.3+\dots + 2^2(n-1) + 2n$ $\to (2)$

Now $(2) - (1) \implies \\T(n) =2^n+ 2^{n-1}+ 2^{n-2}+ 2^{n-3}+ \dots +2^2+ 2 -n \\= 2^n +2^{n-1}+ 2^{n-2}+ 2^{n-3}+\dots +2^2+2 -n \\= 2.\frac{(2^{n} -1)}{(2-1)} \text{ (Sum to n terms of GP with a = r = 2) }  -n \\=2^{n+1} -2 - n \\= \Theta\left(2^n\right)$


Alternatively,

$T(1) = 1$
$T(2) = 2.1 + 2 = 4$
$T(3) = 2.4 + 3 = 11$
$T(4) = 2.11 + 4 = 26$
$T(5) = 2.26 + 5 = 57$
$T(6) = 2.57 + 6 = 120$
$\dots$ 
$T(n) = 2^{n+1} - (n+2)$

edited by
0 votes
0 votes
  1. This is d correct approach

Related questions

5 votes
5 votes
1 answer
1
3 votes
3 votes
1 answer
2
im.raj asked Jun 16, 2016
3,027 views
A. T(n) = $O( n Log n)$B. T(n) = $O({(logn)}^2)$C. T(n) = $O(n)$D. T(n) = $O(n^2)$
1 votes
1 votes
2 answers
3
mdboi asked Oct 28, 2022
784 views
how do i apply master theorem to this? T(n)=2T(n/2)−n^3n
0 votes
0 votes
1 answer
4
lucasbbs asked Feb 28, 2022
6,854 views
How do I apply the master theorem in the above recurrence? Please give details about which case and on hiow to solve the asymptotic analysis...