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

1 Answers 1

1

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

  • 0
    You might as well mention also that $\forall n \ge 0, T(n) = 3^n$.2017-01-04
  • 0
    Thanks so much Reese!!, It makes sense to me now.2017-01-04