I am preparing for my CS exams first year, I need help in understanding the below solution for given $$T(n)= \begin{cases} 3T(n-1),& \mbox{if }n>0\\ 1,& \mbox{otherwise} \end{cases}$$ equation.
solution: $$T(n) = 3T(n-1)$$ $$T(n) = 3 ( 3T(n-2)) = 3^2T(n-2)$$ $$T(n)= 3^2(3T(n-3))$$ how are we getting this $(n-3)$ from $(n-2)?$
We know that $T(n) = 3T(n-1)$. But this is true for all $n$. So it must be true for $n - 2$, as well. So $T(n-2) = 3T((n - 2) - 1)$. Simplifying inside the $T$, we have $T(n-2) = 3T(n-3)$. Since $T(n) = 3^2T(n-2)$, substituting $T(n-2) = 3T(n-3)$ gives us $T(n) = 3^2(3T(n-3))$.
We can simplify one step further, to get $T(n) = 3^3T(n-3)$.
• You might as well mention also that $\forall n \ge 0, T(n) = 3^n$. – Wildcard Jan 4 '17 at 2:35