0
$\begingroup$

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)?$

$\endgroup$
1
$\begingroup$

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)$.

$\endgroup$
2
  • $\begingroup$ You might as well mention also that $\forall n \ge 0, T(n) = 3^n$. $\endgroup$ – Wildcard Jan 4 '17 at 2:35
  • $\begingroup$ Thanks so much Reese!!, It makes sense to me now. $\endgroup$ – here4learn Jan 4 '17 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.