$$T(n) =\begin{cases}5, & \text{if $n=1$} \\2T(n-1)+3n+1, & \text{if $n\geq 2$}\end{cases}$$
Now the answer is as such:
- $T(n)=5\cdot 2^{n-1}+\sum_{i=2}^n2^{n-i}(3i+1)$, which I certainly understand.
- $=(3n+6)2^{n-1}-3n-1-3\sum_{i=1}^{n-2}i\cdot 2^i=15\cdot 2^{n-1}-3n-7$, which throws me a big curve ball right immediately without any sense.
Could anyone explain to me the drastic transition algebraically?