Summations COSC 3101, PROF. J. ELDER 2 Recall: Insertion Sort.

Slides:



Advertisements
Similar presentations
10.4 The Divergence and Integral Test Math 6B Calculus II.
Advertisements

MCA 202: Discrete Mathematics Instructor Neelima Gupta
5/5/20151 Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Discrete Mathematics CS 2610 February 26, part 1.
Nattee Niparnan. Recall What is the measurement of algorithm? How to compare two algorithms? Definition of Asymptotic Notation.
The Growth of Functions
Asymptotic Growth Rate
CSCE 411 Design and Analysis of Algorithms Andreas Klappenecker TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAA.
Lecture 2: Math Review and Asymptotic Analysis. Common Math Functions Floors and Ceilings: x-1 < └ x ┘ < x < ┌ x ┐ < x+1. Modular Arithmetic: a mod n.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
Chapter 2: Algorithm Analysis Big-Oh and Other Notations in Algorithm Analysis Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Riemann Sums and the Definite Integral Lesson 5.3.
Asymptotic Notations Iterative Algorithms and their analysis
Relevant Mathematics Lecture 2 Classifying Functions The Time Complexity of an Algorithm Adding Made Easy Recurrence Relations.
Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity.
Number Sequences Lecture 7: Sep 29 ? overhang. This Lecture We will study some simple number sequences and their properties. The topics include: Representation.
Mon 29 Sep 2014Lecture 4 1. Running Time Performance analysis Techniques until now: Experimental Cost models counting execution of operations or lines.
Mathematics Review and Asymptotic Notation
Iterative Algorithm Analysis & Asymptotic Notations
Fundamentals of Algorithm Analysis Dr. Steve Goddard CSCE 310J: Data Structures &
J. Elder COSC 3101N Thinking about Algorithms Abstractly Lecture 2. Relevant Mathematics: Classifying Functions Input Size Time f(i) = n  (n)
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
10/25/20151 CS 3343: Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 2: Mathematical Foundations.
9.3 Integral Test and P-Series. p-series Test converges if, diverges if. We could show this with the integral test.
Appendix A: Summations Motivation: Evaluating and/or bounding sums are frequently needed in the solution of recurrences Two types of evaluation problems:
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. CSE 3101Z Design and Analysis of Algorithms.
Antiderivatives Lesson 7.1A. Think About It Suppose this is the graph of the derivative of a function What do we know about the original function? Critical.
Time Complexity of Algorithms
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
COSC 3101Winter, 2004 COSC 3101 Design and Analysis of Algorithms Lecture 2. Relevant Mathematics: –The time complexity of an algorithm –Adding made easy.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
4.2 Area Definition of Sigma Notation = 14.
Appendix A: Summations Two types of summation problems in algorithms: 1) Prove by induction that formula is correct 2) Find the function that the sum equals.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
Number Sequences Lecture 7: Sep 27 (chapter 4.1 of the book and chapter of the notes) ? overhang.
CSC317 1 Recap: Oh, Omega, Theta Oh (like ≤) Omega (like ≥) Theta (like =) O(n) is asymptotic upper bound 0 ≤ f(n) ≤ cg(n) Ω(n) is asymptotic lower bound.
Big-O. Speed as function Function relating input size to execution time – f(n) = steps where n = length of array f(n) = 4(n-1) + 3 = 4n – 1.
Lecture 17 – Sequences A list of numbers following a certain pattern
Asymptotic Complexity
CSCE 411 Design and Analysis of Algorithms
Analysis of Non – Recursive Algorithms
Analysis of Non – Recursive Algorithms
Thinking about Algorithms Abstractly
Computational Complexity
Running Time Performance analysis
Riemann Sums and the Definite Integral
David Kauchak CS52 – Spring 2015
Growth of functions CSC317.
The Growth of Functions
CS 3343: Analysis of Algorithms
Introduction to Algorithms Analysis
BIG-OH AND OTHER NOTATIONS IN ALGORITHM ANALYSIS
Properties of Definite Integrals
Should know some common ones:
Antiderivatives Lesson 7.1A.
Algebra Rules!-Part 1.
Antiderivatives.
Quiz 1, Monday 1/28/19 Chapters 1,2 and 3 HW assignments 1-5.
Properties of Definite Integrals
Summations Alexandra Stefan.
Advanced Analysis of Algorithms
Big-O & Asymptotic Analysis
Algorithms and Data Structures Lecture II
Presentation transcript:

Summations

COSC 3101, PROF. J. ELDER 2 Recall: Insertion Sort

COSC 3101, PROF. J. ELDER 3 ∑ i=1..n i = n = ? Arithmetic Sum

COSC 3101, PROF. J. ELDER n-1+n=S n+n-1+n =S (n+1) + (n+1) + (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S

COSC 3101, PROF. J. ELDER 5 Let’s restate this argument using a geometric representation Algebraic argument n-1+n=S n+ +n =S (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S

COSC 3101, PROF. J. ELDER n = number of blue dots n-1+n=S n+ +n =S (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S

COSC 3101, PROF. J. ELDER n = number of blue dots = number of black dots n n-1+n=S n+ +n =S (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S

COSC 3101, PROF. J. ELDER 8 n+1 n+1 n+1 n+1 n+1 n n n n n n There are n(n+1) dots in the grid (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S = number of blue dots = number of black dots n-1+n=S n+ +n =S

COSC 3101, PROF. J. ELDER 9 n+1 n+1 n+1 n+1 n+1 n n n n n n Note =  (# of terms · last term)) (n+1) (n+1) + (n+1) = 2S n (n+1) = 2S = number of blue dots = number of black dots n-1+n=S n+ +n =S 2 1)(n n S  

COSC 3101, PROF. J. ELDER 10 ∑ i=1..n i = n =  (# of terms · last term) Arithmetic Sum True whenever terms increase slowly

COSC 3101, PROF. J. ELDER 11 ∑ i=0..n 2 i = n = ? Geometric Sum

COSC 3101, PROF. J. ELDER 12 Geometric Sum

COSC 3101, PROF. J. ELDER 13 ∑ i=0..n 2 i = n = 2 · last term - 1 Geometric Sum

COSC 3101, PROF. J. ELDER 14 ∑ i=0..n r i = r 0 + r 1 + r r n = ? Geometric Sum

COSC 3101, PROF. J. ELDER 15 S Srrrr...rr S 1r S r1 r1 23nn1 n1 n1  1rrr r n          Geometric Sum

COSC 3101, PROF. J. ELDER 16 ∑ i=0..n r i r1 r1 n1     Geometric Sum θ(rn)θ(rn) Biggest Term When r>1

COSC 3101, PROF. J. ELDER 17 ∑ i=0..n r i = r 0 + r 1 + r r n =  (biggest term) Geometric Increasing True whenever terms increase quickly

COSC 3101, PROF. J. ELDER 18 ∑ i=0..n r i  Geometric Sum When r<1? 1 r n1   

COSC 3101, PROF. J. ELDER 19 ∑ i=0..n r i  Geometric Sum 1 r n1     θ(1) When r<1 Biggest Term

COSC 3101, PROF. J. ELDER 20 ∑ i=0..n r i = r 0 + r 1 + r r n =  (1) Bounded Tail True whenever terms decrease quickly

COSC 3101, PROF. J. ELDER 21 f(i) = 1 ∑ i=1..n f(i) = n n Sum of Shrinking Function

COSC 3101, PROF. J. ELDER 22 f(i) = 1/2 i  Sum of Shrinking Function

COSC 3101, PROF. J. ELDER 23 f(i) = 1/i ∑ i=1..n f(i) = ? n Sum of Shrinking Function

COSC 3101, PROF. J. ELDER 24 ∑ i=1..n 1 / i = 1 / / / / / 5 + …+ 1 / n = ? Harmonic Sum

COSC 3101, PROF. J. ELDER 26 ∑ i=1..n 1 / i = 1 / / / / / 5 + …+ 1 / n =  (log(n)) Harmonic Sum

COSC 3101, PROF. J. ELDER 27 Approximating Sum by Integrating The area under the curve approximates the sum ∑ i=1..n f(i) ≈ ∫ x=1..n f(x) dx

COSC 3101, PROF. J. ELDER 28 Approximating Sums by Integrating: Harmonic Sum

COSC 3101, PROF. J. ELDER 29 Approximating Sums by Integrating: Arithmetic Sums

COSC 3101, PROF. J. ELDER 30 Approximating Sums by Integrating: Geometric Sum

COSC 3101, PROF. J. ELDER 31 Adding Made Easy We will now classify (most) functions f(i) into four classes: –Geometric Like –Arithmetic Like –Harmonic –Bounded Tail For each class, we will give an easy rule for approximating its sum θ( ∑ i=1..n f(i) )

COSC 3101, PROF. J. ELDER 32 Adding Made Easy f(n) n

COSC 3101, PROF. J. ELDER 33 If the terms f(i) grow sufficiently quickly, then the sum will be dominated by the largest term. f(n)  2 Ω(n)  ∑ i=0..n f(i) = θ(f(n)) Geometric Like: Classic example: ∑ i=0..n 2 i = 2 n+1 -1 ≈ 2 f(n)

COSC 3101, PROF. J. ELDER 34 If the terms f(i) grow sufficiently quickly, then the sum will be dominated by the largest term. f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like: For which functions f(i) is this true? How fast and how slow can it grow?

COSC 3101, PROF. J. ELDER 35 ∑ i=1..n (1000) i ≈ 1.001(1000) n = f(n) Even bigger? f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 36 2n2n 2i2i ∑ i=1..n 2 2 ≈ 2 2 = 1f(n) No Upper Extreme: Even bigger! f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 37 f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 38 f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 39 Do All functions in 2 Ω(n) have this property? Maybe not. f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 40 Functions that oscillate with exponentially increasing amplitude do not have this property. f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 41 Functions expressed with +, -, , , exp, log do not oscillate continually. They are well behaved for sufficiently large n. These do have this property. f(n)  2 Ω(n)  ∑ i=1..n f(i) = θ(f(n)) Geometric Like:

COSC 3101, PROF. J. ELDER 42 Adding Made Easy f(n) n

COSC 3101, PROF. J. ELDER 43 If the terms f(i) are increasing or decreasing relatively slowly, then the sum is roughly the number of terms, n, times the final value. Example 1: ∑ i=1..n 1 = n · 1 f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 44 If the terms f(i) are increasing or decreasing relatively slowly, then the sum is roughly the number of terms, n, times the final value. Example 2: ∑ i=1..n i = n f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 45 Note that the final term is within a constant multiple of the middle term: Thus half the terms are roughly the same and the sum is roughly the number of terms, n, times this value ∑ i=1..n i = n/ n ∑ i=1..n i = θ(n · n) f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 46 Is the statement true for this function? ∑ i=1..n i 2 = n 2 f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 47 Again half the terms are roughly the same. ∑ i=1..n i = (n/2) n 2 1 / 4 n 2 f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like: ∑ i=1..n i 2 = θ(n · n 2 )

COSC 3101, PROF. J. ELDER 48 area of small square  ∑ i=1..n f(i) ≈ area under curve  area of big square f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like: = n / 2 · f( n / 2 )  n · f(n)

COSC 3101, PROF. J. ELDER 49 ∑ i=1..n i 2 = n 2 f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like: f(n) = n 2 f( n / 2 ) = θ(f(n)) The key property is = ?

COSC 3101, PROF. J. ELDER 50 Adding Made Easy Half done f(n) n

COSC 3101, PROF. J. ELDER 51 f(i) = 1 ∑ i=1..n f(i) = θ(n) n Sum of Shrinking Function

COSC 3101, PROF. J. ELDER 52 f(i) = ? ∑ i=1..n f(i) = θ(n 1/2 ) n Sum of Shrinking Function 1/i 1/2

COSC 3101, PROF. J. ELDER 53 f(i) = 1/i ∑ i=1..n f(i) = θ(log n) n Sum of Shrinking Function

COSC 3101, PROF. J. ELDER 54 Does the statement hold for the Harmonic Sum? ∑ i=1..n 1 / i = 1 / / / / / 5 + … + 1 / n ∑ i=1..n f(i) = θ(n · f(n)) = ∑ i=1..n 1 / i =θ(log n) θ(1) = θ(n · 1 / n ) ≠ No the statement does not hold! f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 55 Adding Made Easy not included

COSC 3101, PROF. J. ELDER 56 ∑ i=1..n 1 = n · 1 = n · f(n) Intermediate Case: Lower Extreme: ∑ i=1..n 1 / i = θ(n ) = θ(n · f(n)) Upper Extreme: ∑ i=1..n i 1000 = 1 / 1001 n 1001 = 1 / 1001 n · f(n) f(n) = n θ(1)-1  ∑ i=1..n f(i) = θ(n·f(n)) Arithmetic Like:

COSC 3101, PROF. J. ELDER 57 Adding Made Easy Done

COSC 3101, PROF. J. ELDER 58 Adding Made Easy

COSC 3101, PROF. J. ELDER 59 If the terms f(i) decrease towards zero sufficiently quickly, then the sum will be a constant. The classic example ∑ i=0..n 1 / 2 i = / / / 8 + … < 2. f(n)  n -1-Ω(1)  ∑ i=1..n f(i) = θ(1) Bounded Tail:

COSC 3101, PROF. J. ELDER 60 Upper Extreme: ∑ i=1..n 1 / i = θ(1) No Lower Extreme: 2i2i ∑ i=1..n 2 2 = θ(1). 1 All functions in between. f(n)  n -1-Ω(1)  ∑ i=1..n f(i) = θ(1) Bounded Tail:

COSC 3101, PROF. J. ELDER 61 Adding Made Easy Done

COSC 3101, PROF. J. ELDER 62 Summary Geometric Like: If f(n)  2 Ω(n), then ∑ i=1..n f(i) = θ(f(n)). Arithmetic Like: If f(n) = n θ(1)-1, then ∑ i=1..n f(i) = θ(n · f(n)). Harmonic: If f(n) = 1 / n, then ∑ i=1..n f(i) = θ(logn). Bounded Tail: If f(n)  n -1-Ω(1), then ∑ i=1..n f(i) = θ(1). (For +, -, , , exp, log functions f(n))

End of Lecture 3 March 11, 1009