I am trying to understand a simplification step in one of the recurrence examples solved by repeated substitution in a book of algorithms problems I found on Github. I am using it for extra practice in solving recurrences. Anyways, here's the step I am stuck on:
I don't understand how to get from this:
$$3^{i-1}(3T(n-i)+2) + 2\sum_{j=0}^{i-2}3^j$$
To this:
$$3^iT(n-i)+2\sum_{j=0}^{i-1}3^j$$
The part I am particularly confused about is how the summation at the end of the recurrence changes from the first part above to the second. I don't understand how the upper limit in the summation changes from $i-2$ to $i-1$. I imagine I am forgetting something simple about how summations work. Any help is appreciated. I also appreciate excruciatingly detailed steps in showing the algebra or simplification math, if it's not too much trouble. This is often how I get stuck; when a simple step is omitted for brevity.
So first we can distribute the $3^{i-1}$ $$ 3^{i-1}(3T(n-i)+2) + 2\sum_{j=0}^{i-2}3^i \\ 3^iT(n-i)+2\cdot3^{i-1} + 2\sum_{j=0}^{i-2}3^i $$ Now if we write out the terms of that summation: $$ 2\sum_{j=0}^{i-2}3^i = 2\cdot3^0 + 2\cdot3^1 +\dotsb + 2\cdot3^{i-2} $$ It looks like they just tacked that $2\cdot3^{i-1}$ onto the end of the summation: $$ 3^iT(n-i)+2\cdot3^{i-1} + 2\sum_{j=0}^{i-2}3^i \\ 3^iT(n-i) + 2\sum_{j=0}^{i-2}3^i +2\cdot3^{i-1} \\ 3^iT(n-i) + \Big(2\cdot3^0 + 2\cdot3^1 +\dotsb + 2\cdot3^{i-2}\Big) +2\cdot3^{i-1} \\ 3^iT(n-i)+ 2\sum_{j=0}^{i-1}3^i \\ $$