Recurrence T N Minus 2
1. **Problem statement:** Solve the recurrence relation $T(n) = T(n - 2) + n^2$ using the Master Theorem step-by-step.
2. **Note:** The Master Theorem applies to recurrences of the form $T(n) = aT(\frac{n}{b}) + f(n)$ where $a \geq 1$ and $b > 1$ are constants. Here, the recurrence is $T(n) = T(n - 2) + n^2$, which is not in the form required for the Master Theorem because the subproblem size is $n-2$, not $n/b$.
3. **Therefore, the Master Theorem cannot be directly applied.** Instead, we solve this recurrence by iteration (unfolding).
4. **Unfold the recurrence:**
$$
\begin{aligned}
T(n) &= T(n-2) + n^2 \\
&= T(n-4) + (n-2)^2 + n^2 \\
&= T(n-6) + (n-4)^2 + (n-2)^2 + n^2 \\
&\quad \vdots \\
&= T(\text{base case}) + \sum_{k=0}^{m} (n - 2k)^2
\end{aligned}
$$
where $m$ is such that $n - 2m$ reaches the base case (e.g., $n - 2m = 0$ or 1).
5. **Assuming base case $T(0) = 0$,** then $m = \frac{n}{2}$ (assuming $n$ even for simplicity).
6. **Sum of squares:**
$$
\sum_{k=0}^{\frac{n}{2}} (n - 2k)^2 = \sum_{k=0}^{\frac{n}{2}} (2k)^2 = 4 \sum_{k=0}^{\frac{n}{2}} k^2
$$
(reversing order of terms since $(n - 2k)$ decreases as $k$ increases).
7. **Use formula for sum of squares:**
$$
\sum_{k=0}^m k^2 = \frac{m(m+1)(2m+1)}{6}
$$
8. **Plug in $m = \frac{n}{2}$:**
$$
4 \cdot \frac{\frac{n}{2} (\frac{n}{2} + 1)(n + 1)}{6} = \frac{2n}{1} \cdot \frac{(\frac{n}{2} + 1)(n + 1)}{6} = \Theta(n^3)
$$
9. **Conclusion:** The solution to the recurrence is $T(n) = \Theta(n^3)$.
**Summary:** Since the recurrence is not suitable for the Master Theorem, we solved it by iteration and found that $T(n)$ grows on the order of $n^3$.