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:

\[\sum_{k=1}^{n} f(k)\]

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,

\[\sum_{k=1}^{n} f(k)\]

is simply a way to express the sum

\[f(1) + f(2) + \cdots + f(n-1) + f(n)\]

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.

\[\sum_{k = 1}^{n} k = \frac{n (n+1)}{2}.\]
\[\sum_{k = 1}^{n} k^2 = \frac{2 n^3 + 3 n^2 + n}{6} = \frac{n(2n + 1)(n + 1)}{6}.\]
\[\sum_{k = 1}^{\log n} n = n \log n.\]
(1)\[\sum_{k=0}^{n} a^k = \frac{a^{n+1} - 1}{a - 1}\ \mbox{where} \ a \neq 1.\]

As special cases to (1), we have the following two:

(2)\[\sum_{k = 1}^{n} \frac{1}{2^k} = 1 - \frac{1}{2^n},\]
(3)\[\sum_{k = 0}^{n} 2^k = 2^{n+1} - 1.\]

As a corollary to equation (3),

\[\sum_{k = 0}^{\log n} 2^k = 2^{\log n + 1} - 1 = 2n - 1.\]

Finally,

(4)\[\sum_{k=1}^{n} \frac{k}{2^k} = 2 - \frac{n+2}{2^n}.\]

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:

\[\begin{split}{\cal H}_n &= 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{n} \\ &= \sum_{k=1}^{n} \frac{1}{k}\end{split}\]

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.

\[\begin{split}{\cal H}_{10} - \ln{10} \approx 2.93 - 2.31 = 0.62 \\ {\cal H}_{20} - \ln{20} \approx 3.00 - 2.60 = 0.60 \\ {\cal H}_{40} - \ln{40} \approx 4.28 - 3.69 = 0.59\end{split}\]
You have attempted of activities on this page