Sums Jesper Larsson, IT University of Copenhagen Important basic knowledge required for the course Foundations of Computing – Algorithms and Data Structures.

Notation We use the following “capital-sigma notation” for a sum of a number of terms ti :

i= A

∑ ti

B

= t A + t A +1 + t A +2 + · · · + t B −1 + t B

We can vary the notation somewhat, as long as the meaning is clear. The variant ∑i∈S ti denotes the sum over all i that belong to some set S. For instance,

i ∈{ A,..., B}

ti =

i = A... B

ti =

i= A

∑ ti

B

If it is clear from the context what it means (or if we want to be less precise) we can even write the following to sum “over all i”:

∑ ti i

When B is a number, a sum ∑iB = A ti is called a ﬁnite series. If B approaches inﬁnity, we have an inﬁnite series or just series: intuitively a sum of inﬁnitely many terms. Mathematical pedants would sneer at that idea (because you can’t add up inﬁnitely many terms). We get around that by deﬁning:

i= A

ti = lim

B→∞

i= A

∑ ti

B

This saves our honor by declaring that we are just using a shorthand for the limit of the sum as the number of terms approaches inﬁnity, which is mathematically well-deﬁned.

Powers of two The following sum of inverse powers of two, which is a special case of a geometric series, appears frequently in analyzing algorithms: 1 1 1 1 + + + + ··· = 1 2 4 8 16 Or, using the sigma notation: ∞

Important to quickly recall and motivate!

i =1

∑ 2i

1

=1

Rather than giving full formal proof, we shall settle for a sketch that shows an intuitive idea, which is often more valuable for remembering and applying something. (But a formal proof is also a good

sums

2

exercise! You can come up with one yourself, or ﬁnd it somewhere else.) The following is probably enough to make you believe: 1 1 1 1 1 1 1 1 1 + = + + = + + + = 2 2 2 4 4 2 4 8 8 1 1 1 1 1 = + + + + = ··· 2 4 8 16 16 1 We can generalize to starting terms other than : 2 1 = 1 = i i= A 2

i =1

∑ 2 A + i −1 1 2 A −1

1

=

i =1

∑ 2 A − 1 · 2i

1

=

1 2 A −1

i =1

∑ 2i

1

Practice reproducing this deduction!

=

Finally, we give the ﬁnite series of positive powers of two: 1+2+4+8+ ··· + In sigma notation: lg N i =0

N + N = 2 N − 1, where N is a power of two. 2

Important to quickly recall and motivate!

∑ 2i

= 2N − 1

For instance 1 + 2 + 4 + · · · + 64 = 127. The result can be proved by induction, or deduced using previous equations as follows. The ﬁrst step is to reverse the order of the terms, to make them decreasing like in previous series: lg N i =0

lg N

2i =

i =0

N = N 2i

lg N i =0

1 2i

Then split the sum into three ranges, which we know how to compute:   lg N ∞ 1 1 1  = N 1+1− 1 = 2N − 1 = N 0 + ∑ i − ∑ i N 2 2 i =1 2 i =1+lg N

Practice reproducing this or some other deduction of the equation!

Integers from 1 to N 1+2+3+ ··· + N =

i =1

∑i

N

=

N ( N + 1) 2

Important to quickly recall and motivate!

An easy way to deduce this is to rewrite it as N /2 terms, each having the sum N + 1:

(1 + N ) + (2 + N − 1) + (3 + N − 2) + · · · +

N N + +1 2 2

That doesn’t make it obvious that the equation holds for odd N as well, but it does. It can be proved, e.g., by induction. In algorithm analysis, we often disregard lower order terms, terms with smaller exponents on the variable we are interested in ( N in this case). If we do, it only matters that

i =1

∑i

N

1 2 N 2

Important to quickly recall and motivate!

Sums copy 2