CSC300 / CSC402: Adding up an arithmetic series [1/7] |
Suppose we add up the elements we get counting by adding 1:
0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + ... + N
Let's count to 16!
01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 06 06 06 06 06 06 07 07 07 07 07 07 07 08 08 08 08 08 08 08 08 09 09 09 09 09 09 09 09 09 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16
You get a triangle, which is half of a square.
The sum is approximately N squared divided by 2.
0 + 1 + 2 + 3 + 4 + ... + N = (N^2)/2 + N/2
Why add N/2
?
(N^2)/2
only includes half of the diagonal