0

Solve the recurrence relation $T(n) \le 2T(n−1)+n$ , given that $T(1) = 1$, to obtain an asymptotic upper bound for $T(n)$ in terms of big-O.

I believe I need to do this with the substitution method, but all the ideas I've tried don't appear solve it correctly.

Zacky
  • 27,674

1 Answers1

2

It is a bit unclear, but I will suppose you desire to solve$$T(n)=2T(n-1)+n, \ T(1)=1$$ This is how I would do it, first we will try to find a pattern. $$T(n)=2T(n-1)+n$$ $$2T(n-1)=2(2T(n-2)+n-1)=2^2T(n-2)+2(n-1)$$ $$2^2T(n-2)=2^2(2T(n-3)+n-2)=2^3T(n-3)+2^2(n-2)$$ $$2^3T(n-3)=2^3(2T(n-4)+n-3)=2^4T(n-4)+2^3(n-3)$$ $$\dots$$ $$2^{k-1}T(n-k-1)=2^kT(n-k)+2^{k-1}(n-k-1)$$ Now since we desire to get to $T(1)=1$ we will set $n-k=1$. this gives us $$T(n-k)=T(1)\Rightarrow n-k=1 \Rightarrow k=n+1$$ Now let us combine back the original recurrence, note that we only did it for the first term, and the second one $n, n-1 \dots $ were left out. $$T(n)=2^{n+1}T(1)+n+2(n-1)+2^2(n-2)+\dots + 2^{k-1} (n-k-1)$$ $$= 2^{n+1} +\sum_{i=0}^{k-1} 2^i (n-i)=2^{n+1} +n\sum_{i=0}^{k-1} 2^i - \sum_{i=0}^{k-1} i 2^i$$ $$=2^{n+1} +n (2^k -1 )- (k-1)2^{k+1}+k2^{k}-2, \quad k=n+1$$ $$=2^{n+1}+n 2^{n+1}- n - n \cdot 2^{n+2} +(n+1)2^{n+1} -2= O(n2^n)$$ See here for the previous step with the sum. Let me know if I missed something.

Replace $=$ with $\le$ sign if that is the case, you will obviously get the same result, but I am not familiar with inequality recurrences.

Zacky
  • 27,674