Docsity

Summations and Sigma Notation: Understanding Summations in CS1 Exams, Exams of Computer Science

Toggle sidebar
bg1
COP 3502 – Lab Notes
Summations
The CS1 portion of the foundation exam focuses primarily on algorithm analysis either
through tracing the execution of code or asymptotic behavior based upon Big-Oh
notation. Typically, you will see several problems where you will determine the final
value produced from the execution of a code segment or possibly expressed in a
summation form. This set of notes is designed to give you a look at this topic and work
through some examples.
Sigma notation
10
1i
i
= 1+2+3+4+5+6+7+8+9+10.
The sigma (summation symbol) has a summation variable or index, i in this case, an
initial value, 1 in this case, and an upper limit, 10 in this case. This expression is
equivalent to starting i at 1 and incrementing it by 1 ten times and adding the value of i
before each increment.
Summations involving constants
Start solving summations using a constant, like 3:
5
1i
15333333
This expression is equivalent to:
15)54321(3i3
5
1i
Constants are not part of the summation and can be removed from it.
What about a case where we don’t know the upper end of the summation range?
n
1i
3
We just saw that this was equivalent to:
n
1i
13
The question becomes: How many 1’s are there in
n
1i
1
? There are n of them!
So the general formula for
n1
n
1i
Summations - 1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Summations and Sigma Notation: Understanding Summations in CS1 Exams and more Exams Computer Science in PDF only on Docsity!

COP 3502 – Lab Notes

Summations

The CS1 portion of the foundation exam focuses primarily on algorithm analysis either

through tracing the execution of code or asymptotic behavior based upon Big-Oh

notation. Typically, you will see several problems where you will determine the final

value produced from the execution of a code segment or possibly expressed in a

summation form. This set of notes is designed to give you a look at this topic and work

through some examples.

Sigma notation

 10 i 1

i = 1+2+3+4+5+6+7+8+9+10.

The sigma (summation symbol) has a summation variable or index, i in this case, an

initial value, 1 in this case, and an upper limit, 10 in this case. This expression is

equivalent to starting i at 1 and incrementing it by 1 ten times and adding the value of i

before each increment.

Summations involving constants

Start solving summations using a constant, like 3:

5 i 1

This expression is equivalent to:

3 i 3 ( 1 2 3 4 5 ) 15 5 i 1

Constants are not part of the summation and can be removed from it.

What about a case where we don’t know the upper end of the summation range?

 n i 1

3 We just saw that this was equivalent to: 

n i 1

The question becomes: How many 1’s are there in 

 n i 1

1? There are n of them!

So the general formula for 1 n

n i 1

^ 

Therefore, 

n i 1 3 1 3 n 3 n

Summations beginning with 0

How many terms are there in the following summation?

6 i 0

      ^ 

or, one term for each index in the range 0, 1, 2, 3, 4, 5

The general rule is: 1 n^1

n i 0

 ^ 

since the summation has n+1 terms.

So, 3 1 3 (n^1 )^3 n^3

n i 0

Examples

 4 i 1

 5 i 0

 n i 0

  n 1 i 1

5 i 1

Summations involving the summation index

Now suppose that summation involves the index itself. Such as: 

 5 i 1 i i 1 2 3 4 5 15 5 i 1

     ^ 

Summations such as this can become very time consuming to add by hand if the range

of the summation is large. For example,

 100 i 1

i has 100 terms to add. Fortunately, there is an equation that will give the solution

to such summations, regardless of how many terms there are in the summation.

An equation that solves a summation without requiring the addition of all of the terms is

called the closed form of the summation or just the closed form.

 n i 1

i has the closed form:

n (n 1 )

Try this example: (^)  

n i 0 ( 3 i 4 ) 2 3 n 11 n 8 2

8 n 2 3 n 2 3 n 4 (n 1 ) 2 n(n 1 ) 3 i 4 3 i 4 1 3 n 2 2 i 0 n i 0 n i 0 n i 1

      ^      Notice that the range from 0 to n affects the constant term, but not the i term. Summations where the index begins at a number greater than 1 We know how to solve summations where the index begins at 0 or 1. How do we handle summations where the index begins at a number greater than 1? We will look at two methods, one where we calculate the difference between two sums and one where we convert the sum we want to solve into a sum where the index starts at 0 or 1. Method I – subtract the difference between two summations: We want to solve: (^)   10 i 4 i (^) which is equal to (4+5+6+7+8+9+10). But, isn't that also equal to (1+2+3+4+5+6+7+8+9+10) – (1+2+3) ??? Another way of saying that is:   10 i 4 i (^) =   10 i 1 i (^) -   3 i 1 i Try it for other summations! Method II – shift the range of the summation: Here is another way of looking at the same problem. Notice that there are 7 terms in   10 i 4 i (^) , i.e. (4+5+6+7+8+9+10), the difference between those seven numbers and the summation (1+2+3+4+5+6+7) is that the numbers in (4+5+6+7+8+9+10) are each 3 larger than the numbers in (1+2+3+4+5+6+7). We could also say that: (4+5+6+7+8+9+10) is equal to: (1+3)+(2+3)+(3+3)+(4+3)+(5+3)+(6+3)+(7+3) and we can write (1+3)+(2+3)+(3+3)+(4+3)+(5+3)+(6+3)+(7+3) as (^)  

7 i 1 (i 3 ). This leads us to a different method for solving (^)   10 i 4 i (^) , one where we convert a summation that doesn't start with 1 into a summation which starts at 1 by shifting the index range from i=4 to 10 down to i=1 to 7 (note, both have the same number of

terms). However, and this is very important, we must also add 3 to each i term of the summation. So,   10 i 4 i (^) =  

7 i 1 (i 3 ). Note that we could have also converted this to a summation which starts at 0 by shifting the index range to i=0 to 6 (still 7 terms) and adding 4 to each i term, i.e. (^)   10 i 4 i (^) = (^)  

6 i 0 (i 4 ). This summation is equal to: (0+4)+(1+4)+(2+4)+(3+4)+(4+4)+(5+4)+(6+4) but this is equal to: (4)+(5)+(6)+(7)+(8)+(9)+(10) In either case, when we shift the index range down by a certain number, we must add that number to each i term of the summation. Here is a more complex problem, and the solution using both methods: Example solve (^)  

67 i 23 ( 3 i 5 ) Method I: First, lets split (^)  

67 i 23 ( 3 i 5 )into two summations, (^)   67 i 23 3 i (^) + (^)   67 i 23

Second, we convert each of those summations into the difference between two summations, both of which start at 1.   67 i 23 3 i (^) =   67 i 1 3 i (^) -   22 i 1 3 i (^) and   67 i 23 (^5) =   67 i 1 (^5) -   22 i 1

Third, we solve each of the four summations:

  1. (^)  

n i 1 c cn where c isa constan t

  1. (^)  

n i 0 c c(n 1 ) where c isa constan t PRACTICE SUMMATION PROBLEMS

  1. (^)  

8 k 1 k 36

  1.  

50 i 1 (i 1 ) 1325

2 3 n(n 1 ) ( 3 i ) n i 1

^  

  1. 1 51 50 i 0  
  1. 4 44 10 i 0  

2 2 n ( 2 n 1 ) k 2 n 2 2 k 1 2  ^  

  1. (^3 i^3 )^825 22 i 1  
  1. (^4 i^21 )^165 5 i 1  
  1. (^3 k)^630 20 k 1  

2 2 k 2 k 90 ( 2 k 3 ) 15 2 k 1

 ^  