I am studying for an exam, and one practice problem I attempted asks me to prove that:
$T(n) = T(n - 2) + n^2 = O(n^3)$
I need to use the induction/substitution method for this problem. My proof attempt is below. Is this correct? If so, is there a more concise way to do this?
We claim that $T(n) = O(n^3)$. To prove this, we need to show that $T(n) \leq Cn^3$ $\forall n > n_0$ (for any positive constants $C$ and $N_0$). We prove this as follows:
\begin{align} T(n) &= T(n - 2) + n^2 &&\\ &\leq C(n - 2)^3 + n^2 \text{ (by inductive hypothesis)} &&\\ &= Cn^3 - 6Cn^2 + 12Cn - 8C + n^2 &&\\ &= X \end{align}
In order for our proof to hold, we must show that $X < Cn^3$:
\begin{align} X &\leq Cn^3 &&\\ Cn^3 - 6Cn^2 + 12Cn - 8C + n^2 &\leq Cn^3 &&\\ -6Cn^2 + 12Cn - 8C + n^2 &\leq 0 &&\\ -6Cn^2 + 12Cn - 8C &\leq -n^2 &&\\ C(-6n^2 + 12n - 8) &\leq -n^2 &&\\ C(6n^2 - 12n + 8) &\geq n^2 \text{ (multiply by -1)} &&\\ C &\geq \frac{n^2}{6n^2 - 12n + 8} \text{ (assumes $n \geq 2$)} \end{align}
The right-hand-side of this equation is always less than or equal to one if $n \geq 2$. Thus, if we simply choose $C = 1$ and $n_0 = 3$, $T(n) \leq Cn^3$, which is what we set out to prove. It follows by the principle of induction that $T(n) \leq 1 * n^3$ $\forall n > 3$, and thus that $T(n) = O(n^3)$.