sums - COP 3502 Lab Notes Summations The CS1 portion of the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 1 i 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 1 i 15 3 3 3 3 3 3 This expression is equivalent to: 15 ) 5 4 3 2 1 ( 3 i 3 5 1 i = + + + + × = × = 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 1 i 3 We just saw that this was equivalent to: = × n 1 i 1 3 The question becomes: How many 1’s are there in = n 1 i 1 ? There are n of them! Summations - 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
So the general formula for n 1 n 1 i = = Therefore, = = × = × n 1 i n 3 n 3 1 3 Summations beginning with 0 How many terms are there in the following summation? 6 1 1 1 1 1 1 1 6 0 i = + + + + + = = or, one term for each index in the range 0, 1, 2, 3, 4, 5 The general rule is: 1 n 1 n 0 i + = = since the summation has n+1 terms. So, 3 n 3 ) 1 n ( 3 1 3 n 0 i + = + × = × = Examples = 4 1 i 7 = 5 0 i 6 = n 0 i 4 + = 1 n 1 i 3 = + 5 1 i ) 3 2 ( Summations involving the summation index Now suppose that summation involves the index itself. Such as:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 8

sums - COP 3502 Lab Notes Summations The CS1 portion of the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online