31
Computer Science Department University of Central Florida Fun With Summations COP 3502 – Computer Science I

Fun With Summations

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Fun With Summations

Computer Science DepartmentUniversity of Central Florida

Fun With Summations

COP 3502 – Computer Science I

Page 2: Fun With Summations

Fun With Summations page 2

Announcements

Quiz 2 is TODAY Must be complete by 11:55 PM

Summation homework will be available by 2PM today it will be on the course website under Assignments It is due, IN CLASS, on Wednesday.

Test is this coming Friday!

Page 3: Fun With Summations

Fun With Summations page 3

Summations

Is this a Math class? Why do we study summations?

In order to effectively approximate algorithms We NEED mathematical tools

It is not always as simply as doing a 4 second examination of a for loop and deciphering the Big-O time

So for iterative algorithms We use summations as the tool (discussed today)

For recursive algorithms, this doesn’t work We need yet another tool Recurrence relations (coming after the exam)

Page 4: Fun With Summations

Fun With Summations page 4

Summations

Definition: In very basic terms, a summation is the addition of a

set of numbers.

Example: Let’s say we want to sum the integers from 1 to 5 Here is how you write this out as a summation:

Here, the “i” is just a variable. Let’s look at this notation in more detail…

∑=

5

1ii 54321 ++++= 15=

Page 5: Fun With Summations

Fun With Summations page 5

Summations

A summation:

or

is like a for loop:int sum = 0;for ( int j = m; j <= n; j++ )

sum += f(j);

∑=

n

mjjf )( ∑ = )( jfn

mj

index ofsummation

upper limit

lower limit

Here, f(j) is simply a function in terms of jJust like f(x) = 2x+1 is a function in terms of x.f(j) is simply some function in terms of j.

So what is f(j)?

Page 6: Fun With Summations

Fun With Summations page 6

Summations

Example con’d: Since “i” is just a variable, we can use any variable

name…

We also recognize that a summation is merely summing (adding) the values of some given function This far, we’ve only looked at this most simply function:

f(i) = i And then we summed up those i terms.

∑=

5

1JasonJason 54321 ++++= 15=

Page 7: Fun With Summations

Fun With Summations page 7

Summations

Example 2: Now, let us choose our function to be i2, and let us

again sum this from 1 to 5.

So, the deal here is we are summing whatever the function is, and we are summing this from the lower limit all the way to the upper limit, adding all the values together

What if we let the function be 2i+1

∑=

5

1

2

ii 22222 54321 ++++= 552516941 =++++=

∑=

+5

112

ii 119753 ++++= 35=

Page 8: Fun With Summations

Fun With Summations page 8

Summations More summations:

Now let us write this purely in “function” form so we all see what is going on.

Again, on the previous example, we let f(i) = 2i+1 Thus, we had…

∑=

5

1)(

iif )5()4()3()2()1( fffff ++++=

∑=

+5

112

ii )1)5(2()1)4(2()1)3(2()1)2(2()1)1(2( +++++++++=

119753 ++++= 35=

Page 9: Fun With Summations

Fun With Summations page 9

Summations Summation Rules:

Here are several useful rules of summations:

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(

2)1(

1

+=∑

=

nnin

i 6)12)(1(

1

2 ++=∑

=

nnnin

i 4)1( 22

1

3 +=∑

=

nnin

i

∑∑∑−

===

−=1

11)()()(

m

i

n

i

n

miififif

nkkkn

i

n

i*1

11== ∑∑

==

∑=

5

22

i

i

*k is a constant

Page 10: Fun With Summations

Fun With Summations page 10

Summations

Examples:

Here, 42 is a just a constant We can bring it outside of the summation

And now we can solve using this rule:

∑=

n

i 142

∑∑==

=n

i

n

i 1114242

nn

i=∑

=11

nn

i

n

i4214242

11== ∑∑

==

Page 11: Fun With Summations

Fun With Summations page 11

Summations

Examples:

Again, we need to determine, for the “stuff” inside the summation, what are constants and what are variables. We know 42 is a constant. What about j? j is also a constant! Why? The only time that letters (inside the summation) count

as variables are when they are the EXACT SAME letter as the index of the summation

jn

i∑=1

42

Page 12: Fun With Summations

Fun With Summations page 12

Summations

Examples:

Again, we need to determine, for the “stuff” inside the summation, what are constants and what are variables. i is the index of the summation Do you see any i‘s inside the summation? Nope. So ANY and ALL other letters (or anything that looks

like it could be a variable) are NOT variables Treat them as constants!

jn

i∑=1

42

Page 13: Fun With Summations

Fun With Summations page 13

Summations

Examples:

In summary, treat the entire 42j as a constant

Now we can solve using the rule:

jn

i∑=1

42

∑∑==

=n

i

n

ijj

1114242

nn

i=∑

=11

njjjn

i

n

i*4214242

11== ∑∑

==

Page 14: Fun With Summations

Fun With Summations page 14

Summations

Examples:

Again, look at what is inside the summation All we have is “Jeff” inside the summation The index of the summation is “Bob” So “Jeff” is simply a constant

∑=

n

BobJeff

1

nJeffJeffn

Bob*1

1=∑

=

Page 15: Fun With Summations

Fun With Summations page 15

Summations

Additional Problems: We now give several example problems For each problem, we give you the summation

RULES that you need for the specific problem These are RULES you will need to know for exams

Learn ‘em, memorize ‘em, or include them on your 1 page sheet

You then use the rules to solve the problem

Page 16: Fun With Summations

Fun With Summations page 16

Summations

Problem 1. Evaluate:

The purpose of this example is to simply show that when the limits of the summation are small, you can often ignore rules and just apply an old-school “plug and chug”

= (5+1) + (5+2) + (5+4) + (5+8) = 6 + 7 + 9 + 13 = 35

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(Use:

Page 17: Fun With Summations

Fun With Summations page 17

Summations

Problem 2. Evaluate:

= 400 + 15,150 = 15,550

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(Use: 2

)1(1

+=∑

=

nnin

i

Page 18: Fun With Summations

Fun With Summations page 18

Summations

Problem 3. Evaluate:

= 2,686,700 - 120,600 + 1800= 2,567,900.

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(Use: 2

)1(1

+=∑

=

nnin

i

6)12)(1(2^

1

++=∑

=

nnnin

i

Page 19: Fun With Summations

Fun With Summations page 19

Summations

Problem 4. Evaluate:

What is different on this problem? The index of the summation does NOT start at 1! The rules we know and need to solve this problem

all assume that the lower index is 1 So we need a rule that will change the bounds of

the summation A rule that will somehow get as a 1 as the lower limit

Page 20: Fun With Summations

Fun With Summations page 20

Summations

Problem 4. Evaluate:

= 4(11,325 - 105) + (136)= 45,016.

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(Use: 2

)1(1

+=∑

=

nnin

i

∑∑∑−

===

−=1

11)()()(

m

i

n

i

n

miififif

Page 21: Fun With Summations

Fun With Summations page 21

Summations

Problem 5. Evaluate:

= 10,497,600 - 2025 + 173,880 - 285= 10,669,170.

nn

i=∑

=11 ∑∑∑

===

+=+n

mi

n

mi

n

miigifigif )()()()(Use:

4)1( 22

1

3 +=∑

=

nnin

i

∑∑∑−

===

−=1

11)()()(

m

i

n

i

n

miififif

6)12)(1(

1

2 ++=∑

=

nnnin

i

Page 22: Fun With Summations

Fun With Summations page 22

Summations

Problem 6. Evaluate:

Not all summations result in a number for an answer Often, the answer has many variables in it The is called the “closed form” of the summation

Such is the case for this problem And the remaining ones

∑=

n

kii

Page 23: Fun With Summations

Fun With Summations page 23

Summations

Problem 6. Evaluate:

i is clearly a variable (within the summation) k is a constant, representing the lower limit of the

summation gotta fix that!

∑=

n

kii

∑∑∑−

===

−=1

11

k

i

n

i

n

kiiii

∑∑∑−

===

−=1

11)()()(

m

i

n

i

n

miifififUse:

2)11)(1(

2)1( +−−−

+=

kknn

2))(1(

2)1( kknn −−

+=

Page 24: Fun With Summations

Fun With Summations page 24

Problem 7. Evaluate:

Start with the right-most summation Apply the rule above

Now, think about something: How did we know that c was a constant

Well, at least in part, cuz I told you! In addition to this fact, you know it is a constant because variables

are always the SAME letter as the index of the summation j was the index of the inner summation Thus, any letter would be a constant if it was other than the letter j

Summations

∑∑==

m

j

n

ic

11

nkkn

i*

1=∑

=Use:

∑∑∑===

=n

i

m

j

n

imcc

111*

Page 25: Fun With Summations

Fun With Summations page 25

Problem 7. Evaluate:

Start with the right-most summation Apply the rule above

Now, look at c*m We know c is a constant, but what about m? Well, the index of the summation is i Any other letter, INSIDE the summation simply acts as a constant So c*m is also a constant

Summations

∑∑==

m

j

n

ic

11

nkkn

i*

1=∑

=Use:

∑∑∑===

=n

i

m

j

n

imcc

111*

Page 26: Fun With Summations

Fun With Summations page 26

Problem 7. Evaluate:

Start with the right-most summation Apply the rule above

So we apply the same rule again:

Summations

∑∑==

m

j

n

ic

11

nkkn

i*

1=∑

=Use:

∑∑∑===

=n

i

m

j

n

imcc

111*

nmcmccn

i

m

j

n

i*)*(*

111==∑∑∑

===

Page 27: Fun With Summations

Fun With Summations page 27

Problem 8. Evaluate:

Start with the right-most summation Apply the rule above

Now, refer back to the previous example Ask yourself, is c*i a constant? Answer: you must look at the INDEX of the summation

i is the index, AND i is in the “body” of the summation Therefore, i is most certainly a variable and should be treated as

such!

Summations

∑∑==

i

j

n

ic

11

nkkn

i*

1=∑

=Use:

∑∑∑===

=n

i

i

j

n

iicc

111*

2)1(

1

+=∑

=

nnin

iUse:

Page 28: Fun With Summations

Fun With Summations page 28

Problem 8. Evaluate:

Start with the right-most summation Apply the rule above

Now, we pull out the constant, and apply the next rule:

Summations

∑∑==

i

j

n

ic

11

nkkn

i*

1=∑

=Use:

∑∑∑===

=n

i

i

j

n

iicc

111*

2)1(

1

+=∑

=

nnin

iUse:

∑=

=n

iic

1∑∑∑===

=n

i

i

j

n

iicc

111*

+

=2

)1(nnc

Page 29: Fun With Summations

Fun With Summations page 29

Problem 9. Evaluate:

Summations

∑−=

n

njjn

105

∑∑−=−=

==n

nj

n

njjnjn

101055

−= ∑∑

==

11

115

n

j

n

jjjn ( ) ( )( )

−−

−+

=2

10112

15 nnnnn

)11021(2

52

)11021(5 2222

−+−+=

+−−+= nnnnnnnnnn

)5(552

)11022(5−=

−= nnnn

Page 30: Fun With Summations

Fun With Summations page 30

Problem 10. Evaluate:

Summations

( )∑∑= =

n

i

i

ji

1 12

( )( )6

1211

2 ++=∑

=

nnnkn

k

( ) ∑ ∑∑∑= == =

=n

i

i

j

n

i

i

jii

1 11 1122

∑=

=n

ii

1

22

Use:

3)12)(1(

6)12)(1(2 ++=

++=

nnnnnn

Page 31: Fun With Summations

Computer Science DepartmentUniversity of Central Florida

Fun With Summations

COP 3502 – Computer Science I