Summations¶
Most programs contain loop constructs. When analyzing running time costs for programs with loops, we need to add up the costs for each time the loop is executed. This is an example of a summation. Summations are simply the sum of costs for some function applied to a range of values. Summations are typically written with the following “Sigma” notation:
This notation indicates that we are adding the result of \(f(k)\) over some range of (integer) values.
The expression parameter and its initial value are indicated below the \(\sum\) symbol. Here, the notation \(k=1\) indicates that the parameter is \(k\) and that it begins with the value 1. At the top of the \(\sum\) symbol is the expression \(n\). This indicates the maximum value for the parameter \(k\). Thus, this notation means to sum the values of \(f(k)\) as \(k\) ranges across the integers from 1 through \(n\). In other words,
is simply a way to express the sum
Given a summation, you often wish to replace it with an algebraic equation with the same value as the summation. This is known as a closed-form solution, and the process of replacing the summation with its closed-form solution is known as solving the summation.
A closed form is an expression that can be computed by applying a fixed number of familiar operations to the arguments. For example, the expression \(2 + 4 + \cdots + 2n\) is not a closed form, but the expression \(n(n+1)\) is a closed form.
For example, the summation \(\sum_{k=1}^{n} 1\) is simply the constant expression “1” added \(n\) times (remember that \(k\) ranges from 1 to \(n\)). Because the sum of \(n\) 1s is \(n\), the closed-form solution is \(n\). In other words, a summation of a constant expression is equivalent to counting by the constant value “math”n times, or multiplying the constant by \(n\).
Summation facts¶
Fact 1
\[\sum ca_k = c\sum a_k\]
|
Fact 2
\[\sum (a_k + b_k) =
\sum a_k + \sum b_k\]
|
Fact 3
\[\sum a_kx^{i+k} =
x^i \sum a_kx^k\]
|
Fact 4
\[\sum_{k = m}^{n} a_{k+i} =
\sum_{k = m+i}^{n+i} a_{k}\]
|
Collapsing sums (Fact 5) |
||
\[\sum_{k = 1}^{n}
(a_k - a_{k-1}) = a_n - a_0\]
|
and |
\[\sum_{k = 1}^{n}
(a_{k-1} - a_k) = a_0 - a_n\]
|
Here is a list of useful summations, along with their closed-form solutions.
As special cases to (1), we have the following two:
As a corollary to equation (3),
Finally,
Most of these equalities can be proved using a proof by induction. Unfortunately, induction does not help us derive a closed-form solution. Induction only confirms when a proposed closed-form solution is correct.
Approximating Sums¶
Not all sums have closed forms. In those cases, we can try to find a suitable approximation. For example, consider the following sum:
This is called the Harmonic Series and it has no closed form. It is closely approximated by \(\ln{n}\) because the definite integral of \(1/x\) from 1 to n is \(\ln{n}\). The constant known as Euler’s constant \((\gamma)\) with a value close to 0.577, approximates the difference between \({\cal H}_n\) and \(\ln{n}\) when \(n\) is large.