LOGBOOK

HELP

Quiz Entry - updated: 2026.09.18

What is Gauss's summation formula, and why does it keep appearing in complexity analysis?

$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$ — it is the closed form of "1 + 2 + … + n", and that sum is what nested loops and shrinking-sequence scans produce.

A staircase of bars of heights 1 to n inside an n by n+1 rectangle

* Two copies of the staircase tile the box exactly — which is the formula, drawn. *

$$\sum_{i=1}^{n} i = 1 + 2 + 3 + \dots + n = \frac{n(n+1)}{2}$$

Why it is true, in one picture: pair the first term with the last, the second with the second-last, and so on. Each pair sums to $n+1$, and there are $n/2$ pairs — hence $n(n+1)/2$. Equivalently, the staircase of bars of heights $1, 2, \dots, n$ fills exactly half of an $n \times (n+1)$ rectangle.

Why it matters for analysis: expanded, $\frac{n(n+1)}{2} = \frac{1}{2}n^2 + \frac{1}{2}n$ — leading term $n^2$, so it is $O(n^2)$. This single fact converts a whole family of loop patterns into a growth class:

  • an inner loop whose length grows with the outer counter ($1, 2, \dots, n$)
  • a scan over a sequence that shrinks by one each round ($n, n-1, \dots, 1$ — the same sum backwards)

Both are $O(n^2)$, which is why selection-sort, insertion-sort and the naive prefix-average algorithm all land in the same class despite doing quite different things.

Go deeper:

  • doc Triangular number — the pairing proof and the picture of the staircase as half a rectangle.

From Quiz: ADS / Asymptotic Analysis, O-Notation and Recursion | Updated: Sep 18, 2026