Solve the following recurrence equation: $T(n) = T(n-2)+n^2$, having $T(0)=1$, $T(1)=5$.
I need to solve this equation but when I get to the particular solution with $n^2$ some of the terms I need cancel out and it's kind of impossible to find the constants at that point.
Here is the way I'm doing it, using $an^2+bn+c$ to replace $T(n)$; $$\begin{split} 0&=an^2+bn+c - a(n-2)^2-b(n-2)-c-n^2\\ &=an^2+bn- a(n-2)^2-b(n-2)+n^2\\ &=an^2+bn- a(n^2-4n+4)-b(n-2)-n^2\\ &=an^2+bn- an^2+4an-4a-bn-2b-n^2\\ &=4an-4a-2b-n^2\\ &=n(4a-n)+(-4a+2b)\\ \end{split}$$ But beyond that, I cannot find any way to find the constants.
You need to solve for even and odd separately, but first let's find the value of the sum of squares of all nonnegative integers from $0$ to $m$, a quantity we denote by $S(m)$ and which we will need later.
We make an assumption that $m\to S(m)$ is a polynomial of degree $3$ (which I won't justify here, and you can prove the formula by induction after we find it). Observing that $S(0)=0$, we have $S(m) = c_3 m^3 + c_2 m^2+ c_1 m$. Since $S(1)=1,S(2)=5$ and $S(3)=14$, we also have
\begin{align*} c_3+c_2+c_1 &= 1\\ 8*c_3+4*c_2+2*c_1 &= 5\\ 27*c_3+9*c_2+3*c_1 &= 14\end{align*}
The solution to this system of equations is $c_3=\frac 16, c_2=\frac 12, c_1=\frac13$. That is
$$S(m) = \frac{m^3+3m^2+2m}{6}= \frac{m(m+1)(m+2)}{6}.$$
Now to the problem:
$$T(2)-T(0)=2^2, T(4)-T(2)=4^2,\dots,T(2m)-T(2m-2)= (2m)^2.$$ Adding up,
$$T(2m)-T(0)= \underset{\mbox{even}}{\underbrace{2^2+ \dots + (2m)^2}}= 2^2(1^2+\dots+m^2) = 4S(m).$$
That is $$T(2m)= T(0)+ \frac{2m(m+1)(m+2)}{3}.$$
Similarly $$T(3)-T(1)=3^2,\dots, T(2m+1)-T(2m-1)=(2m+1)^2,$$
Therefore
$$T(2m+1)-T(1) = \underset{\mbox{odd}}{\underbrace{3^2+5^2+ \dots + (2m+1)^2}} = S(2m+1) - 1^2- (2^2+\dots + (2m)^2)=S(2m+1)-1 - 4S(m).$$
I'll leave simplifying this last expression to you.