Most programmers (including me) are painfully aware of quadratic behavior resulting from a loop that internally performs 1, 2, 3, 4, 5 and so on operations per iteration,
$$\sum_{i=1}^n i = \frac{n \left(n+1\right)}{2} $$
It’s very easy to derive, e.g. considering the double of the sum like $(1+2+3) + (3+2+1) = 3\times4$ .
For the sum of squares there is a very similar formula,
$$\sum_{i=1}^n i^2 = \frac{n(n+\frac{1}{2})(n+1)}{3}$$
But the only way I found to derive that was to assume it would sum to a cubic polynomial $f(x)=Ax^3+Bx^2+Cx+D$, and solve for $f(n)-f(n-1)=n^2$.
I’m guessing that there is a much simpler system and concept here, generalizing to $\sum_{i=1}^n i^k$?
No comments:
Post a Comment