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 : B

∑ ti

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

i= A

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,

B

ti =

ti =

i = A...B

i ∈{ A,...,B}

∑ ti

i= A

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 finite series. If B approaches infinity, we have an infinite series or just series: intuitively a sum of infinitely many terms. Mathematical pedants would sneer at that idea (because you can’t add up infinitely many terms). We get around that by defining: ∞

B

ti = lim

B→∞

i= A

∑ ti

i= A

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 infinity, which is mathematically well-defined.

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: ∞

1

∑ 2i

=1

i =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

Important to quickly recall and motivate!

sums

2

exercise! You can come up with one yourself, or find 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

1

∑ 2 A + i −1

i =1

=

1

∑ 2 A − 1 · 2i

=

=

i =1

1 2 A −1

1

∑ 2i

i =1

1

Practice reproducing this deduction!

2 A −1

Finally, we give the finite series of positive powers of two: 1+2+4+8+ ··· +

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

Important to quickly recall and motivate!

In sigma notation: lg N

∑ 2i

= 2N − 1

i =0

For instance 1 + 2 + 4 + · · · + 64 = 127. The result can be proved by induction, or deduced using previous equations as follows. The first 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 − ∑ N 2 2i i =1 2 i =1+lg N

Practice reproducing this or some other deduction of the equation!

Integers from 1 to N N

1+2+3+ ··· + N =

∑i

i =1

=

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:   N N + +1 (1 + N ) + (2 + N − 1) + (3 + N − 2) + · · · + 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 N

∑i

i =1

1 2 N 2

Important to quickly recall and motivate!

Sums copy 6
Sums copy 6