This document covers a few mathematical constructs that appear very frequently when doing algorithmic analysis. We spend minimal time in class reviewing these concepts, so this document is intended to serve as a general reference guide and as a concept refresher. Please head to office hours if you have any follow-up questions.
We also have a few practice problems located at the bottom if you’re very rusty and want some practice.
This document was written by Michael Lee, Meredith Wu, & Brian Chan.
Summations Review The summation (∑ \sum ∑ ) is a way of concisely expressing the sum of a series of related values. For example, suppose we wanted a concise way of writing 1 + 2 + 3 + ⋯ + 8 + 9 + 10 1 + 2 + 3 + \cdots + 8 + 9 + 10 1 + 2 + 3 + ⋯ + 8 + 9 + 1 0 . We can do so like this:
∑ i = 1 10 i \sum_{i=1}^{10} i i = 1 ∑ 1 0 i
The “i = 1 i = 1 i = 1 ” expression below the ∑ \sum ∑ symbol is initializing a variable called i i i which is initially set to 1. We then increase i i i by one from that initial value up to and including the number at the top of the ∑ \sum ∑ symbol. We then take each value of i i i and substitute it to the expression to the right of the ∑ \sum ∑ symbol, and add each of those expressions together.
Here is another example:
∑ i = 1 3 2 + i 2 = ( 2 + 1 2 ) + ( 2 + 2 2 ) + ( 2 + 3 2 ) = 3 + 6 + 11 = 20 \begin{aligned} \sum_{i=1}^3 2 + i^2 &= (2 + 1^2) + (2 + 2^2) + (2 + 3^2) \\ &= 3 + 6 + 11 \\ &= 20 \end{aligned} i = 1 ∑ 3 2 + i 2 = ( 2 + 1 2 ) + ( 2 + 2 2 ) + ( 2 + 3 2 ) = 3 + 6 + 1 1 = 2 0
More generally, the summation operation is defined as follows:
∑ i = a b f ( i ) = f ( a ) + f ( a + 1 ) + f ( a + 2 ) + ⋯ + f ( b − 2 ) + f ( b − 1 ) + f ( b ) \sum_{i=a}^b f(i) = f(a) + f(a + 1) + f(a + 2) + \cdots + f(b - 2) + f(b - 1) + f(b) i = a ∑ b f ( i ) = f ( a ) + f ( a + 1 ) + f ( a + 2 ) + ⋯ + f ( b − 2 ) + f ( b − 1 ) + f ( b )
…where a , b a, b a , b are integers such that a ≤ b a \leq b a ≤ b and f ( x ) f(x) f ( x ) is some arbitrary function.
One thing to note is that the bounds of a summation are inclusive : in the examples above, i i i varies from a a a up to and including b b b .
We will see examples of summations in use when analyzing the behavior of loops later this quarter.
Useful Summation Identities Splitting a Sum Rule:
∑ i = a b ( x + y ) = ∑ i = a b x + ∑ i = a b y \displaystyle \sum_{i=a}^b (x + y) = \sum_{i=a}^b x + \sum_{i=a}^b y i = a ∑ b ( x + y ) = i = a ∑ b x + i = a ∑ b y Example:
∑ i = 5 8 i = 5 + 6 + 7 + 8 = ∑ i = 0 8 i − ∑ i = 0 4 i \displaystyle \sum_{i=5}^{8} i = 5 + 6 + 7 + 8 = \sum_{i=0}^{8} i - \sum_{i=0}^{4} i i = 5 ∑ 8 i = 5 + 6 + 7 + 8 = i = 0 ∑ 8 i − i = 0 ∑ 4 i Adjusting Summation Bounds Rule:
∑ i = a b f ( x ) = ∑ i = 0 b f ( x ) − ∑ i = 0 a − 1 f ( x ) \displaystyle \sum_{i=a}^b f(x) = \sum_{i=0}^b f(x) - \sum_{i=0}^{a - 1} f(x) i = a ∑ b f ( x ) = i = 0 ∑ b f ( x ) − i = 0 ∑ a − 1 f ( x ) Example:
∑ i = 5 8 i = 5 + 6 + 7 + 8 = ∑ i = 0 8 i − ∑ i = 0 4 i \displaystyle \sum_{i=5}^{8} i = 5 + 6 + 7 + 8 = \sum_{i=0}^{8} i - \sum_{i=0}^{4} i i = 5 ∑ 8 i = 5 + 6 + 7 + 8 = i = 0 ∑ 8 i − i = 0 ∑ 4 i Factoring out a Constant Rule:
∑ i = a b c f ( i ) = c ∑ i = a b f ( i ) \displaystyle \sum_{i=a}^b cf(i) = c \sum_{i=a}^b f(i) i = a ∑ b c f ( i ) = c i = a ∑ b f ( i ) Example:
∑ i = 1 5 10 n = 10 ∑ i = 1 5 n \displaystyle \sum_{i=1}^5 10n = 10\sum_{i=1}^5 n i = 1 ∑ 5 1 0 n = 1 0 i = 1 ∑ 5 n Summation of a Constant Rule:
∑ i = 0 n − 1 c = c + c + ⋯ + c ⏟ n times = c n \displaystyle \sum_{i=0}^{n-1} c = \underbrace{c + c + \cdots + c}_{\text{$n$ times}} = cn i = 0 ∑ n − 1 c = n times c + c + ⋯ + c = c n Example:
∑ i = 0 5 − 1 10 = 10 + 10 + 10 + 10 + 10 = 50 \displaystyle \sum_{i=0}^{5-1} 10 = 10 + 10 + 10 + 10 + 10 = 50 i = 0 ∑ 5 − 1 1 0 = 1 0 + 1 0 + 1 0 + 1 0 + 1 0 = 5 0 Gauss’s Identity Rule:
∑ i = 0 n − 1 i = n ( n − 1 ) 2 \displaystyle \sum_{i=0}^{n-1} i = \frac{n(n - 1)}{2} i = 0 ∑ n − 1 i = 2 n ( n − 1 ) Example:
∑ i = 0 10 − 1 i = 10 ( 9 ) 2 = 45 \displaystyle \sum_{i=0}^{10-1} i = \frac{10(9)}{2} = 45 i = 0 ∑ 1 0 − 1 i = 2 1 0 ( 9 ) = 4 5 Sum of Squares Rule:
∑ i = 0 n − 1 i 2 = n ( n − 1 ) ( 2 n − 1 ) 6 \displaystyle \sum_{i=0}^{n-1} i^2 = \frac{n(n - 1)(2n - 1)}{6} i = 0 ∑ n − 1 i 2 = 6 n ( n − 1 ) ( 2 n − 1 ) Example:
∑ i = 0 10 − 1 i 2 = 10 ⋅ 9 ⋅ 19 6 = 285 \displaystyle \sum_{i=0}^{10-1} i^2 = \frac{10 \cdot 9 \cdot 19}{6} = 285 i = 0 ∑ 1 0 − 1 i 2 = 6 1 0 ⋅ 9 ⋅ 1 9 = 2 8 5 Finite Geometric Series Rule:
(Applicable only when x ≠ 1 x \ne 1 x = 1 )
∑ i = 0 n − 1 x i = x n − 1 x − 1 \displaystyle \sum_{i=0}^{n-1} x^i = \frac{x^n - 1}{x - 1} i = 0 ∑ n − 1 x i = x − 1 x n − 1 Example:
∑ i = 0 10 − 1 5 i = 5 10 − 1 5 − 1 = 2441406 \displaystyle \sum_{i=0}^{10 - 1} 5^i = \frac{5^{10} - 1}{5 - 1} = 2441406 i = 0 ∑ 1 0 − 1 5 i = 5 − 1 5 1 0 − 1 = 2 4 4 1 4 0 6 Infinite Geometric Series Rule:
(Applicable only when − 1 < x < 1 -1 \lt x \lt 1 − 1 < x < 1 )
∑ i = 0 ∞ x i = 1 1 − x \displaystyle \sum_{i=0}^\infty x^i = \frac{1}{1 - x} i = 0 ∑ ∞ x i = 1 − x 1 Example:
∑ i = 0 ∞ ( 1 2 ) i = 1 1 − 1 / 2 = 2 \displaystyle \sum_{i=0}^\infty \left(\frac{1}{2}\right)^i = \frac{1}{1 - 1/2} = 2 i = 0 ∑ ∞ ( 2 1 ) i = 1 − 1 / 2 1 = 2 Practice Problems Simplify ∑ k = 1 n k ( k + 1 ) \displaystyle \sum_{k=1}^n k(k + 1) k = 1 ∑ n k ( k + 1 ) Show that the sum of the first n n n positive odd integers is n 2 n^2 n 2 . Simplify ∑ k = 1 n ( n − k ) \displaystyle \sum_{k=1}^n (n-k) k = 1 ∑ n ( n − k ) . Simplify ∑ k = 0 n 2 k \displaystyle \sum_{k=0}^n 2^k k = 0 ∑ n 2 k . Show that ∑ k = 1 ∞ 1 2 k \displaystyle \sum_{k=1}^{\infty} \frac{1}{2^k} k = 1 ∑ ∞ 2 k 1 converges to 1. Solutions Problem 1: Simplify ∑ k = 1 n k ( k + 1 ) \displaystyle \sum_{k=1}^n k(k + 1) k = 1 ∑ n k ( k + 1 )
∑ k = 1 n k ( k + 1 ) = ∑ k = 1 n k 2 + k = n ( n + 1 ) ( 2 n + 1 ) 6 + n ( n + 1 ) 2 \displaystyle \begin{aligned} \sum_{k=1}^n k(k+1) &= \sum_{k=1}^n k^2+k \\ &= \frac{n(n+1)(2n+1)}{6} + \frac{n(n+1)}{2} \end{aligned} k = 1 ∑ n k ( k + 1 ) = k = 1 ∑ n k 2 + k = 6 n ( n + 1 ) ( 2 n + 1 ) + 2 n ( n + 1 ) Problem 2: Show that the sum of the first n n n positive odd integers is n 2 n^2 n 2 .
∑ k = 1 n ( 2 k − 1 ) = 2 ∑ k = 1 n k − ∑ k = 1 n 1 = 2 n ( n + 1 ) 2 − n = n 2 \displaystyle \begin{aligned} \sum_{k=1}^n (2k - 1) &= 2 \sum_{k=1}^n k - \sum_{k=1}^n 1\\ & = 2 \frac{n(n+1)}{2} - n \\ & = n^2 \end{aligned} k = 1 ∑ n ( 2 k − 1 ) = 2 k = 1 ∑ n k − k = 1 ∑ n 1 = 2 2 n ( n + 1 ) − n = n 2 Problem 3: Simplify ∑ k = 1 n ( n − k ) \displaystyle \sum_{k=1}^n (n-k) k = 1 ∑ n ( n − k ) .
∑ k = 1 n ( n − k ) = ( n − 1 ) + ( n − 2 ) + ( n − 3 ) + . . . + 0 = 1 + 2 + . . . + ( n − 1 ) = ∑ k = 1 n − 1 k = n ( n − 1 ) 2 \displaystyle \begin{aligned} \sum_{k=1}^n (n-k) &= (n-1) + (n-2) + (n-3) + ... + 0\\ &= 1 + 2 + ... + (n-1) \\ &= \sum_{k=1}^{n-1} k \\ &= \frac{n(n-1)}{2} \end{aligned} k = 1 ∑ n ( n − k ) = ( n − 1 ) + ( n − 2 ) + ( n − 3 ) + . . . + 0 = 1 + 2 + . . . + ( n − 1 ) = k = 1 ∑ n − 1 k = 2 n ( n − 1 ) Problem 4: Simplify ∑ k = 0 n 2 k \displaystyle \sum_{k=0}^n 2^k k = 0 ∑ n 2 k .
∑ k = 0 n 2 k = 2 0 + 2 1 + 2 2 + . . . + 2 n = 1 + 2 + 4 + . . . + 2 n = 2 n + 1 − 1 2 − 1 = 2 n + 1 − 1 \displaystyle \begin{aligned} \sum_{k=0}^n 2^k &= 2^0 + 2^1 + 2^2 + ... + 2^n \\ &= 1 + 2 + 4 + ... + 2^n \\ &= \frac{2^{n+1} - 1}{2 - 1} \\ &= 2^{n+1} - 1 \end{aligned} k = 0 ∑ n 2 k = 2 0 + 2 1 + 2 2 + . . . + 2 n = 1 + 2 + 4 + . . . + 2 n = 2 − 1 2 n + 1 − 1 = 2 n + 1 − 1 Problem 5: Show that ∑ k = 1 ∞ 1 2 k \displaystyle \sum_{k=1}^{\infty} \frac{1}{2^k} k = 1 ∑ ∞ 2 k 1 converges to 1.
∑ k = 1 ∞ 1 2 k = 1 2 + 1 4 + 1 8 + 1 16 . . . = ∑ k = 0 ∞ 1 2 1 2 k = 1 2 ∑ k = 0 ∞ 1 2 k = 1 2 ⋅ 1 1 − 1 2 = 1 \displaystyle \begin{aligned} \sum_{k=1}^{\infty} \frac{1}{2^k} &= \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} ...\\ &= \sum_{k=0}^{\infty} \frac{1}{2}\frac{1}{2^k}\\ &= \frac{1}{2} \sum_{k=0}^{\infty} \frac{1}{2^k}\\ &= \frac{1}{2} \cdot \frac{1}{1-\frac{1}{2}} \\ &= 1 \end{aligned} k = 1 ∑ ∞ 2 k 1 = 2 1 + 4 1 + 8 1 + 1 6 1 . . . = k = 0 ∑ ∞ 2 1 2 k 1 = 2 1 k = 0 ∑ ∞ 2 k 1 = 2 1 ⋅ 1 − 2 1 1 = 1