Skip to content

adding up 1+2+⋯+n1 + 2 + \dots + n

the maths you need

what it is

Add the whole numbers from 1 to nn and you get n(n+1)2\frac{n(n + 1)}{2}. Stop one short, as in 1 + 2 + 3 for 4, and you get the comparisons bubble sort makes on a row of nn numbers back to front.

Take a row back to front, each number smaller than the one before: 5, 4, 3, 2, 1. Bubble sort walks along it, comparing each pair of neighbours and swapping them when the bigger comes first. Walk 1 makes 4 comparisons and carries the 5 to the end. Each walk after it stops one pair sooner. That is 4 + 3 + 2 + 1 = 10 comparisons.

54321the row43215after walk 14 pairs compared32145after walk 23 pairs compared21345after walk 32 pairs compared12345after walk 41 pair comparedone walkin place for good
Bubble sort on 5, 4, 3, 2, 1, walk by walk. Each walk compares one pair fewer: 4 + 3 + 2 + 1 = 10 comparisons.

The comparisons 4, 3, 2, 1 form a run: whole numbers next to each other. Its sum is 10, and turned round, 1 + 2 + 3 + 4 has the same sum. 1+2+⋯+n1 + 2 + \dots + n means every whole number from 1 to nn, added. The table adds the runs up to 6.

nnthe runn(n+1)n(n + 1)half of thatthe run's sum
11211
21 + 2633
31 + 2 + 31266
41 + 2 + 3 + 4201010
51 + 2 + 3 + 4 + 5301515
61 + 2 + 3 + 4 + 5 + 6422121
Each run's sum, beside n(n+1)n(n + 1), halved. The last two columns agree every time.

One formula gives the sum at once: n(n+1)2\frac{n(n + 1)}{2}, half of nn times one more than nn. Two staircases show why.

Two staircases of 1 to 4 squares, yellow hanging and blue standing. Each column holds 5, so the 4 columns hold 20, twice the sum. One staircase is half, 10.

where the formulas come from

Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about nn, or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.

question 1Fit two staircases of squares together. What shape do they make?
  1. the move: draw the sum as a staircase

    the line:
    S=1+2+⋯+nS = 1 + 2 + \dots + n

    why it is allowed: Let SS be the sum of the whole numbers from 1 to nn. Draw it as a staircase, a column for each number: 1 square, then 2, and so on up to nn. For 5, columns of 1, 2, 3, 4 and 5 hold 15 squares.

  2. the move: take two staircases

    the line:
    2S=2(1+2+⋯+n)2S = 2(1 + 2 + \dots + n)

    why it is allowed: Two staircases hold twice the squares. Doubling both sides of line 1 keeps it true.

  3. the move: fit them into a rectangle

    the line:
    2S=n(n+1)2S = n(n + 1)
    Blue stands, yellow hangs. Two staircases of 1 to 5 squares fill a rectangle 5 wide and 6 tall, 30 squares. So 1 + 2 + 3 + 4 + 5 is 5 times 6, halved, which is 15.

    why it is allowed: Stand one staircase with its tallest column on the left. Hang the other upside down from the top, its tallest column on the right, as in the picture. The first column holds nn standing and 1 hanging. Each column to the right, the standing one loses a square and the hanging one gains one. So every column holds n+1n + 1, and the nn columns fill a rectangle nn wide and n+1n + 1 tall.

  4. the move: halve both sides

    the line:
    S=n(n+1)2S = \frac{n(n + 1)}{2}

    why it is allowed: Halving both sides of line 3 keeps it true and leaves one SS. For 5, half of 30 is 15.

try it with a small nn: at n=5n = 5, line 1 gives S=15S = 15, which you can work out by hand

question 2Fill a square nn small squares wide. How many lie on or below its diagonal?
  1. the move: count row by row

    the line:
    T=1+2+⋯+nT = 1 + 2 + \dots + n
    A square 5 wide, its diagonal edged in heavy ink. The squares on or below it are yellow, 1, 2, 3, 4 and 5 by row, 15 in all.
    rowon or below the diagonalon or above iton it
    1151
    2241
    3331
    4421
    5511
    in all15155
    The square 5 wide, counted row by row.

    why it is allowed: Counting rows from the top, row 1 has 1 square on or below it, row 2 has 2, and row nn has nn. Let TT be their total, the sum of question 1 again.

  2. the move: double both sides

    the line:
    2T=2(1+2+⋯+n)2T = 2(1 + 2 + \dots + n)
    Yellow and red, 15, lie on or below the diagonal; blue and red, 15, on or above it. The 5 red are in both: 15 + 15 is 30, the 25 squares and the 5 red again.

    why it is allowed: The plan: two lots of TT cover the square with the nn diagonal squares counted twice, as the picture shows. Lines 2 and 3 build that from line 1, and line 4 counts it. Doubling both sides keeps them equal.

  3. the move: take n from both sides

    the line:
    2T−n=2(1+2+⋯+n)−n2T - n = 2(1 + 2 + \dots + n) - n

    why it is allowed: Taking the same number from both sides of line 2 keeps them equal.

  4. the move: count the whole square

    the line:
    2T−n=n22T - n = n^2

    why it is allowed: Flip the square over along its diagonal: each square below it trades places with one above. So TT squares lie on or above it too, as the grid at line 1 shows. The right side of line 3 counts both lots, less the nn counted twice: every square once, nn rows of nn, which is n2n^2, read nn squared. For 5, 15 + 15 is 30, and 30 less 5 is 25.

  5. the move: add n to both sides

    the line:
    2T=n2+n2T = n^2 + n

    why it is allowed: Adding the same number to both sides of line 4 keeps them equal. For 5, twice 15 is 30, which is 25 + 5.

  6. the move: halve both sides

    the line:
    T=n2+n2T = \frac{n^2 + n}{2}

    why it is allowed: Halving both sides of line 5 keeps them equal.

  7. the move: write it as n times one more

    the line:
    T=n(n+1)2T = \frac{n(n + 1)}{2}

    why it is allowed: n2+nn^2 + n is nn lots of nn and nn lots of 1, which is nn times one more than nn. The same formula as question 1.

try it with a small nn: at n=5n = 5, line 1 gives T=15T = 15, which you can work out by hand

question 3Add one more number to the run. Does the formula grow by the number added?
  1. the move: name the growth

    the line:
    F=n(n+1)2−(n−1)((n−1)+1)2F = \frac{n(n + 1)}{2} - \frac{(n - 1)\bigl((n - 1) + 1\bigr)}{2}

    why it is allowed: The sum to nn is the sum to n−1n - 1 with nn added. Let FF be how much the formula grows over that step: the formula at nn, less the formula at n−1n - 1, which puts n−1n - 1 in place of each nn. At 4, that is 10 less 6, which is 4.

  2. the move: tidy the bracket

    the line:
    F=n(n+1)2−(n−1)n2F = \frac{n(n + 1)}{2} - \frac{(n - 1)n}{2}

    why it is allowed: In line 1, (n−1)+1(n - 1) + 1 is nn.

  3. the move: put both over 2

    the line:
    F=n(n+1)−(n−1)n2F = \frac{n(n + 1) - (n - 1)n}{2}

    why it is allowed: Half of one number, less half of another, is half of their difference. At 4, 10 less 6 is 4, and 20 less 12, halved, is 4 too.

  4. the move: multiply out both brackets

    the line:
    F=(n2+n)−(n2−n)2F = \frac{(n^2 + n) - (n^2 - n)}{2}

    why it is allowed: nn lots of n+1n + 1 make n2+nn^2 + n. n−1n - 1 lots of nn are nn lots of nn, less one nn, so n2−nn^2 - n. At 4, 20, and 16 less 4, 12.

  5. the move: take away part by part

    the line:
    F=n2+n−n2+n2F = \frac{n^2 + n - n^2 + n}{2}

    why it is allowed: Taking away n2−nn^2 - n takes away n2n^2 and gives back nn. At 4, taking 12 from 20 is taking 16 and giving back 4, which leaves 8.

  6. the move: collect like parts

    the line:
    F=2n2F = \frac{2n}{2}

    why it is allowed: In line 5, n2n^2 less n2n^2 is nothing, and nn and nn make 2n2n.

  7. the move: halve

    the line:
    F=nF = n
    the sumthe last number05101520250246the sumthe last number05101520250246
    • the formula, n(n+1)2\frac{n(n + 1)}{2}
    The formula from 1 to 6, steeper at each step. The table gives each climb: 2, 3, 4, 5 and 6.
    nnthe sum to nnthe formulagrows by
    111
    2332
    3663
    410104
    515155
    621216
    The sum and the formula side by side, each growing by the number added.

    why it is allowed: Half of 2n2n is nn. The plot and the table check it from 2 to 6.

  8. the move: read it

    the line:
    equal at 1 and growing alike,equal for every n\begin{gathered} \text{equal at 1 and growing alike,} \\ \text{equal for every } n \end{gathered}

    why it is allowed: At 1 the sum is 1, and 1 times 2, halved, is 1 too. Each step puts nn onto the sum, and by line 7 the formula grows by nn too. Equal at the start and growing alike, they stay equal for every nn. This is an argument from a start and a step, called proof by induction.

try it with a small nn: at n=4n = 4, line 1 gives F=4F = 4, which you can work out by hand

question 4Stop one short. What is 1+2+⋯+(n−1)1 + 2 + \dots + (n - 1)?
  1. the move: name the sum

    the line:
    B=1+2+⋯+(n−1)B = 1 + 2 + \dots + (n - 1)

    why it is allowed: Let BB be the sum from 1 to n−1n - 1, for nn from 2; at 1 there is nothing to add. Here nn is how many numbers bubble sort's row holds. For 4, BB is 1 + 2 + 3.

  2. the move: use question 1 again

    the line:
    B=(n−1)((n−1)+1)2B = \frac{(n - 1)\bigl((n - 1) + 1\bigr)}{2}

    why it is allowed: Question 1 holds for any last number from 1. Put n−1n - 1 in place of each nn in line 4 of question 1.

  3. the move: tidy the bracket

    the line:
    B=(n−1)n2B = \frac{(n - 1)n}{2}
    4321the row3214after walk 13 pairs compared2134after walk 22 pairs compared1234after walk 31 pair comparedone walkin place for good
    Bubble sort on 4, 3, 2, 1 makes 3 + 2 + 1 = 6 comparisons, and 3 times 4, halved, is 6.
    nnthe sum to n−1n - 1(n−1)n(n - 1)n, halvedbubble sort on nn back to front
    2111
    3333
    4666
    5101010
    6151515
    The sum one short, its formula and bubble sort's comparisons agree for rows of 2 to 6 numbers.

    why it is allowed: In line 2, (n−1)+1(n - 1) + 1 is nn. For 4, 3 times 4, halved, is 6.

  4. the move: read it

    the line:
    the comparisonsof bubble sort on a rowback to front\begin{gathered} \text{the comparisons} \\ \text{of bubble sort on a row} \\ \text{back to front} \end{gathered}

    why it is allowed: Bubble sort stops after a walk with no swap. On nn numbers back to front, each walk carries the biggest unsorted number to the end and leaves the rest back to front. So every walk swaps, and bubble sort never stops before walk n−1n - 1. Walk 1 compares all n−1n - 1 pairs of neighbours, and each walk after it one fewer, down to 1. That is this sum, added from the top down, as the picture at line 3 shows for 4.

try it with a small nn: at n=4n = 4, line 1 gives B=6B = 6, which you can work out by hand

question 5How does the sum grow?
  1. the move: name the sum

    the line:
    S=1+2+⋯+nS = 1 + 2 + \dots + n

    why it is allowed: Let SS be the sum of question 1.

  2. the move: use question 1

    the line:
    S=n(n+1)2S = \frac{n(n + 1)}{2}

    why it is allowed: By line 4 of question 1.

  3. the move: multiply out the bracket

    the line:
    S=n2+n2S = \frac{n^2 + n}{2}

    why it is allowed: nn lots of nn make n2n^2, and nn lots of 1 make nn.

  4. the move: halve each part

    the line:
    S=n22+n2S = \frac{n^2}{2} + \frac{n}{2}
    The sum to 10 as a staircase in a square 10 wide, 55 of its 100 squares. The dashed line halves the square, 50, and the staircase pokes above it by 10 half squares, 5.
    nnhalf of n2n^2the sumn2n^2
    10.511
    2234
    481016
    105055100
    20200210400
    408008201,600
    The sum always lies between half of n2n^2 and n2n^2.

    why it is allowed: Half of a total is half of each part, added. For 4, 8 and 2 make 10.

  5. the move: a fact about n

    the line:
    n≤n2n \le n^2

    why it is allowed: nn is at least 1, so nn times nn is at least nn times 1. For 4, 4 is at most 16.

  6. the move: halve both sides

    the line:
    n2≤n22\frac{n}{2} \le \frac{n^2}{2}

    why it is allowed: Halving both sides of line 5 keeps 'at most' the right way round, since one half is above zero. For 4, 2 is at most 8.

  7. the move: put half of n squared for half of n

    the line:
    S≤n22+n22S \le \frac{n^2}{2} + \frac{n^2}{2}

    why it is allowed: By line 6, half of nn is at most half of n2n^2. Put half of n2n^2 in its place in line 4. The right side gets no smaller, so SS is at most it. For 4, 8 + 2 is at most 8 + 8.

  8. the move: add the halves

    the line:
    S≤n2S \le n^2

    why it is allowed: In line 7, two halves of n2n^2 make n2n^2. For 4, 10 is at most 16.

  9. the move: read it as a ceiling

    the line:
    S∈O(n2)S \in O(n^2)

    why it is allowed: By line 8, SS is at most 1 times n2n^2 from 1 on, and 1 is a fixed number above zero. So a fixed multiple of n2n^2 is a ceiling of SS: SS is in big O of n2n^2. At 10, 55 is at most 100.

  10. the move: leave out the half of n

    the line:
    S≥n22S \ge \frac{n^2}{2}

    why it is allowed: Line 4 adds half of nn, which is above zero, to half of n2n^2. So SS is at least half of n2n^2. For 4, 10 is at least 8.

  11. the move: read it as a floor

    the line:
    S∈Ω(n2)S \in \Omega(n^2)
    the sumthe last number0204060801000246810the sumthe last number0204060801000246810
    • the sum, n(n+1)2\frac{n(n + 1)}{2}
    • the ceiling of line 8, n2n^2
    • the floor of line 10, n22\frac{n^2}{2}
    The sum between its ceiling and its floor, for 1 to 10. At 10 they are 55, 100 and 50, so the sum is about half of n2n^2.

    why it is allowed: By line 10, SS is at least one half times n2n^2 from 1 on, and one half is a fixed number above zero. So a fixed multiple of n2n^2 is a floor of SS too: SS is in big omega of n2n^2.

  12. the move: a ceiling and a floor together

    the line:
    S∈Θ(n2)S \in \Theta(n^2)

    why it is allowed: By lines 9 and 11, SS is in O(n2)O(n^2) and in Ω(n2)\Omega(n^2), so it is in Θ(n2)\Theta(n^2). It grows like n2n^2. By line 4, doubling nn makes half of n2n^2 4 times as big and half of nn only twice as big. So the sum grows a little under 4 times: 55 at 10, 210 at 20, 820 at 40.

try it with a small nn: at n=4n = 4, line 1 gives S=10S = 10, which you can work out by hand

a worked example

Add up 1 to 12 three ways.

  1. Two staircases: 12 columns of 13 squares hold 156, so one staircase, the sum, is half of that, 78.
  2. The square: a square 12 wide holds 144 squares. Twice the sum covers it with its 12 diagonal squares counted twice: 144 + 12 is 156. So the sum is 78.
  3. One at a time: the formula at 11, 11 times 12, halved, is 66, the sum to 11. Adding 12 gives 78, and the formula at 12, 12 times 13, halved, is 78 too.

the trap

check yourself

  1. What is 1 + 2 + ... + 60?

    the answer

    60 times 61 is 3,660, and half of that is 1,830, by question 1.

  2. How many comparisons does bubble sort make on 20 numbers back to front?

    the answer

    19 + 18 + ... + 1, the sum one short for 20. That is 19 times 20, halved, 190, by question 4.

  3. What is 21 + 22 + ... + 30? It is the run from 1 to 30 without its first 20 numbers.

    the answer

    1 to 30 is 30 times 31, halved, 465. 1 to 20 is 20 times 21, halved, 210. So 465 less 210 leaves 255.