This document covers a few mathematical constructs that appear very frequently when doing algorithmic analysis. We will spend only minimal time in class reviewing these concepts, so if you're unfamiliar with the following concepts, please be sure to read this document and head to office hours if you have any follow-up questions.
We also have a few practice problems located at the bottom of this doc if you're very rusty and want some practice.
(Note: this document was co-written with Meredith Wu)
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 + \cdots + 8 + 9 + 10\). We can do so like this:
$$ \sum_{i=1}^{10} i $$The "\(i = 1\)" expression below the \(\sum\) symbol is initializing a variable called \(i\) which is initially set to 1. We then increase \(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\) and substitute it to the expression to the right of the \(\sum\) symbol, and add each of those expressions together.
Here is another example:
$$ \begin{align*} \sum_{i=1}^3 2 + i^2 &= (2 + 1^2) + (2 + 2^2) + (2 + 3^2) \\ &= 3 + 6 + 11 \\ &= 20 \end{align*} $$More generally, the summation operation is defined as follows:
$$ \sum_{i=a}^b f(i) = f(a) + f(a + 1) + f(a + 2) + \cdots + f(b - 2) + f(b - 1) + f(b) $$...where \(a, b\) are integers such that \(a \leq b\) and \(f(x)\) is some arbitrary function.
One thing to note is that the bounds of a summation are inclusive: in the examples above, \(i\) varies from \(a\) up to and including \(b\).
We will see examples of summations in use when analyzing the behavior of loops later this quarter.
Note: you can also download these identities as a pdf.
Splitting a sum
Rule:
\(\displaystyle \sum_{i=a}^b (x + y) = \sum_{i=a}^b x + \sum_{i=a}^b y \)Example:
\(\displaystyle \sum_{i=1}^{10} (5 + 7) = 120 = 50 + 70 = \sum_{i=1}^{10} 5 + \sum_{i=1}^{10} 7 \)Adjusting summation bounds
Rule:
\(\displaystyle \sum_{i=a}^b f(x) = \sum_{i=0}^b f(x) - \sum_{i=0}^{a - 1} f(x) \)Example:
\(\displaystyle \sum_{i=5}^{8} i = 5 + 6 + 7 + 8 = \sum_{i=0}^{8} i - \sum_{i=0}^{4} i \)Factoring out a constant
Rule:
\(\displaystyle \sum_{i=a}^b cf(i) = c \sum_{i=a}^b f(i) \)Note: \(c\) is some constant.
Example:
\(\displaystyle \sum_{i=1}^5 10n = 10\sum_{i=1}^5 n \)Summation of a constant
Rule:
\(\displaystyle \sum_{i=0}^{n-1} c = \underbrace{c + c + \cdots + c}_{\text{$n$ times}} = cn \)Note: \(c\) is some constant. This rule is a special case of the previous one.
Example:
\(\displaystyle \sum_{i=0}^{5-1} 10 = 10 + 10 + 10 + 10 + 10 = 50 \)Gauss's identity
Rule:
\(\displaystyle \sum_{i=0}^{n-1} i = \frac{n(n - 1)}{2} \)Example:
\(\displaystyle \sum_{i=0}^{10-1} i = \frac{10(9)}{2} = 45 \)Sum of squares
Rule:
\(\displaystyle \sum_{i=0}^{n-1} i^2 = \frac{n(n - 1)(2n - 1)}{6} \)Example:
\(\displaystyle \sum_{i=0}^{10-1} i^2 = \frac{10 \cdot 9 \cdot 19}{6} = 285 \)Finite geometric series
Rule:
Applicable only when \(x \ne 1\).
\(\displaystyle \sum_{i=0}^{n-1} x^i = \frac{x^n - 1}{x - 1} \)Example:
\(\displaystyle \sum_{i=0}^{10 - 1} 5^i = \frac{5^{10} - 1}{5 - 1} = 2441406 \)Infinite geometric series
Rule:
Applicable only when \(-1 < x < 1\).
\(\displaystyle \sum_{i=0}^\infty x^i = \frac{1}{1 - x} \)Example:
\(\displaystyle \sum_{i=0}^\infty \left(\frac{1}{2}\right)^i = \frac{1}{1 - 1/2} = 2 \)