So far I have used substitution to solve this problem but I am stuck at getting the pattern equation:
T(n) = T(n-1) + 2n - 1
=[T((n-1) - 1) + 2(n-1) - 1] + 2n - 1
=T(n-2) + 2n - 3 + 2n - 1
=T(n-2) + 4n - 4
=[T((n-2) - 1) + 2(n-2) - 1] + 4n + 4
=T(n-3) + 2n - 5 + 4n - 4
= T(n-3) + 6n - 9
*
*
*
T(n) = T(n-k) + k(2n) + ??? //This is the part I am Having issues with.
For me, it is hard to see the last part pattern. I tried to see if I could find some correlation between previous substitutions but I can't seem to piece it together.
This is a link for the resource I used to solve this problem:https://www.youtube.com/watch?v=Ob8SM0fz6p0
I am trying to learn this concept, so step by step is preferred. Otherwise, Thank you for your help.
\begin{align}T(n) &= T(n-1) + 2n - 1\\ T(n-1) &= T(n-2) + 2n - 3\\ T(n-2) &= T(n-3) + 2n - 5\\ &\vdots \\ T(3) &= T(2) + 5\\ T(2) &= T(1) + 3 \end{align}
Sum those equations and you get:
$$T(n) = -1+1+3+5+...+(2n-3)+(2n-1) = n^2-1$$