Help in Linear summation of n(any given number)

35 Views Asked by At

The original formula is this. enter image description here

We're computing the complexity of an insertion sort.

enter image description here

How did the first formula turned into the second formula?

1

There are 1 best solutions below

11
On

$t_j = 1$ for $j = 2,\ldots,n$, so the sums with $(t_j-1)$ vanish, and $\sum_{j=2}^{n} t_j = n-1$. We then get:

$$\begin{align} T(n) &= c_1 n + c_2(n-1) + c_4(n-1) + c_5(n-1) + c_8(n-1) \\ &= c_1 n + (c_2 + c_4 + c_5 + c_8)(n-1) \\&= c_1 n + (c_2 + c_4 + c_5 + c_8)n - (c_2 + c_4 + c_5 + c_8) \\&= (c_1 + c_2 + c_4 + c_5 + c_8)n - (c_2 + c_4 + c_5 + c_8) \end{align} $$