Processing math: 100%
Close
Close Window

CS3 Data Structures & Algorithms

Chapter 3 Mathematical Background

Show Source |    | About   «  3.4. Logarithms   ::   Contents   ::   3.6. Recurrence Relations  »

3.5. Summations

3.5.1. 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 parameter values. Summations are typically written with the following “Sigma” notation:

ni=1f(i).

This notation indicates that we are summing the value of f(i) over some range of (integer) values. The parameter to the expression and its initial value are indicated below the symbol. Here, the notation i=1 indicates that the parameter is i and that it begins with the value 1. At the top of the symbol is the expression n. This indicates the maximum value for the parameter i. Thus, this notation means to sum the values of f(i) as i ranges across the integers from 1 through n. This can also be written f(1)+f(2)++f(n1)+f(n). Within a sentence, Sigma notation is typeset as ni=1f(i).

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. For example, the summation ni=11 is simply the expression “1” summed n times (remember that i ranges from 1 to n). Because the sum of n 1s is n, the closed-form solution is n.

Here is an explanation about the closed form solution of one summation that you will see many times in this book. Since this appears so often, it will help you later if you can get comfortable with it.

1 / 12 Settings
<<<>>>

Let's see how to find the closed form solution for $\displaystyle\sum_{i=1}^{n}i$.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

1 / 13 Settings
<<<>>>

Let's see how to find the closed form solution for $\displaystyle\sum_{i=0}^{n} 2^i$.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

Here is a list of useful summations, along with their closed-form solutions.

ni=1i=n(n+1)2ni=1i2=2n3+3n2+n6=n(2n+1)(n+1)6logni=1n=nlogni=0ai=11a for 0<a<1ni=0ai=an+11a1 for a1As special cases to the last summation, we have the following two: ni=112i=112nni=02i=2n+11As a corollary to the previous summation:  logni=02i=2logn+11=2n1Finally:  ni=1i2i=2n+22n

The sum of reciprocals from 1 to n, called the Harmonic Series and written Hn, has a value between logen and logen+1. To be more precise, as n grows, the summation grows closer to

Hnlogen+γ+12n,

where γ is Euler’s constant and has the value 0.5772…

Most of these equalities can be proved easily by 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.

   «  3.4. Logarithms   ::   Contents   ::   3.6. Recurrence Relations  »

Close Window