I am not able to solve the following recurrence relation:
$$ T(n) = \begin{cases} T(n-1) + n^2 & \text{if } n \ge 2, \\ 1 & \text{otherwise.}\\ \end{cases} $$
How do I start?
I am not able to solve the following recurrence relation:
$$ T(n) = \begin{cases} T(n-1) + n^2 & \text{if } n \ge 2, \\ 1 & \text{otherwise.}\\ \end{cases} $$
How do I start?
In general, the recursion formula T(n) = T(n-1) + g(n), T(1) = c has the solution T(n) = c + sum of g(k) over 2 <= k <= n. No recursion, just a simple summation.
$$T(n)=T(1)+\sum_{i=2}^{n}i^2$$ $$T(n)=T(1)+\sum_{i=1}^{n}i^2-\sum_{i=1}^{1}i^2$$
So as @plop mentioned in comments, we have: $$\lim_{n\to \infty} T(n)=\frac{n(n+1)(2n+1)}{6}=O(n^3)$$