Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2

Similar documents
Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Algorithms and Their Complexity

With Question/Answer Animations

The Growth of Functions (2A) Young Won Lim 4/6/18

Theory of Computation

3. Algorithms. What matters? How fast do we solve the problem? How much computer resource do we need?

Discrete Mathematics CS October 17, 2006

COMP 182 Algorithmic Thinking. Algorithm Efficiency. Luay Nakhleh Computer Science Rice University

Big O Notation. P. Danziger

Asymptotic Analysis of Algorithms. Chapter 4

Big O Notation. P. Danziger

Growth of Functions (CLRS 2.3,3)

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004

Data Structures and Algorithms. Asymptotic notation

ECOM Discrete Mathematics

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Reading 10 : Asymptotic Analysis

Assignment 5 Bounding Complexities KEY

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

Growth of Functions. As an example for an estimate of computation time, let us consider the sequential search algorithm.

Limits at Infinity. Horizontal Asymptotes. Definition (Limits at Infinity) Horizontal Asymptotes

Running Time Evaluation

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

Computer Science Section 3.2

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0

3 The Fundamentals:Algorithms, the Integers, and Matrices

CISC 235: Topic 1. Complexity of Iterative Algorithms

CSC236 Week 4. Larry Zhang

Analysis of Algorithms

CSC Design and Analysis of Algorithms. Lecture 1

Principles of Algorithm Analysis

Algorithms 2/6/2018. Algorithms. Enough Mathematical Appetizers! Algorithm Examples. Algorithms. Algorithm Examples. Algorithm Examples

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo

The Time Complexity of an Algorithm

EECS 477: Introduction to algorithms. Lecture 5

COE428 Notes Week 4 (Week of Jan 30, 2017)

Define Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 417: Algorithms and Computational Complexity. Winter 2007 Larry Ruzzo

The Time Complexity of an Algorithm

Algorithms: Review from last time

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo

An analogy from Calculus: limits

Asymptotic Analysis 1

Computational Complexity

Ch01. Analysis of Algorithms

Data Structures and Algorithms Running time and growth functions January 18, 2018

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College

Introduction to Algorithms and Asymptotic analysis

Asymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2

CS 344 Design and Analysis of Algorithms. Tarek El-Gaaly Course website:

(2) Generalize De Morgan s laws for n sets and prove the laws by induction. 1

AP Calculus Summer Homework

Describe an algorithm for finding the smallest integer in a finite sequence of natural numbers.

Data Structures and Algorithms CMPSC 465

Ch 01. Analysis of Algorithms

Notes for Recitation 14

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

The Growth of Functions and Big-O Notation

CSCI 3110 Assignment 6 Solutions

Computational Complexity - Pseudocode and Recursions

MATH 1A, Complete Lecture Notes. Fedor Duzhin

Electrical & Computer Engineering University of Waterloo Canada February 26, 2007

Math Practice Exam 3 - solutions

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Orders of Growth. Also, f o(1) means f is little-oh of the constant function g(x) = 1. Similarly, f o(x n )

Analysis of Algorithms

CSE 417: Algorithms and Computational Complexity

On the number of ways of writing t as a product of factorials

CS383, Algorithms Spring 2009 HW1 Solutions

3.1 Asymptotic notation

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

Mathematics for Business and Economics - I. Chapter 5. Functions (Lecture 9)

CSE 373: Data Structures and Algorithms Pep Talk; Algorithm Analysis. Riley Porter Winter 2017

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016

Review Asympto&c Bounds

Math 391: Midterm 1.0 Spring 2016

Lecture 3. Big-O notation, more recurrences!!

The Growth of Functions. A Practical Introduction with as Little Theory as possible

P, NP, NP-Complete, and NPhard

Math 328 Course Notes

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Lecture 2: Asymptotic Analysis of Algorithms

8. Limit Laws. lim(f g)(x) = lim f(x) lim g(x), (x) = lim x a f(x) g lim x a g(x)

Cpt S 223. School of EECS, WSU

Section 1.8 The Growth of Functions. We quantify the concept that g grows at least as fast as f.

Terminology Notation Definition Big oh notation f(s) = O(g(s)) (s S) There exists a constant c such that f(s) c g(s) for all s S

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Algorithms Design & Analysis. Analysis of Algorithm

Infinite Limits. By Tuesday J. Johnson

MAT01A1: Precise Definition of a Limit and Continuity

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare

Analysis of Algorithms

Section 3.2 The Growth of Functions. We quantify the concept that g grows at least as fast as f.

Introduction to Algorithms

Thus f is continuous at x 0. Matthew Straughn Math 402 Homework 6

2. Limits at Infinity

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. B) 6x + 4

CSCE 222 Discrete Structures for Computing

Transcription:

CompSci 230 Discrete Math for Computer Science Announcements Read Chap. 3.1-3.3 No recitation Friday, Oct 11 or Mon Oct 14 October 8, 2013 Prof. Rodger Section 3.2 Big-O Notation Big-O Estimates for Important Functions Big-Omega and Big-Theta Notation The Growth of Functions Want to know how fast a function grows Want to understand how quickly an algorithm can solve a problem as the size of the input grows compare the efficiency of two different algorithms for solving the same problem. determine whether it is practical to use a particular algorithm as the input grows. Paul Gustav Heinrich Bachmann (1837 1920) Donald E. Knuth (Born 1938)

Big-O Notation Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) is O(g(x)) if there are constants C and k such that Illustration of Big-O Notation f(x) is O(g(x) whenever x > k. This is read as f(x) is big-o of g(x) or g asymptotically dominates f. Important Points about Big-O Notation If a pair C,k is found, then there are infinitely many pairs. We can always make the k or the C larger and still maintain the inequality Any pair C and k where C < C and k < k is also a valid pair since whenever x > k > k. Don t use f(x) = O(g(x)) instead of f(x) is O(g(x)). It is ok to write f(x) O(g(x)), because O(g(x)) represents the set of functions that are O(g(x)). Using the Definition of Big-O Notation Example: Show that is. Since when x >, x < x 2 and < x 2 Can take C = 4 and k = 1 to show that Alternatively, when x >, we have x < x 2. Hence, when x > Can take C = 3 and k = 2 instead. x 2 and

Using the Definition of Big-O Notation Example: Show that is. Since when x >, x < x 2 and < x 2 Illustration of Big-O Notation is Can take C = 4 and k = 1 to show that Alternatively, when x >, we have x < x 2. Hence, when x > Can take C = 3 and k = 2 instead. x 2 and Big-O Notation Both and are such that and. We say that the two functions are of the same order. If and h(x) is larger than g(x) for all positive real numbers, then. Note that if for x > k and if for all x, then if x > k. Hence,. For many applications, the goal is to select the function g(x) in O(g(x)) as small as possible (up to multiplication by a constant, of course). Using the Definition of Big-O Notation Example: Show that x 2 is O(x 3 ). When x >, x 2 x 3 Take C and k to establish that x 2 is O(x 3 ). Would C and k work?) Example: Show that n 2 is not O(n). Suppose there are constants C and k for which n 2 Cn, whenever n > k. Then (by dividing both sides of n 2 Cn) by n, then n C must hold for all n > k. A contradiction!

Using the Definition of Big-O Notation Example: Show that x 2 is O(x 3 ). When x >, x 2 x 3 Take C and k to establish that x 2 is O(x 3 ). Would C and k work?) Example: Show that n 2 is not O(n). Suppose there are constants C and k for which n 2 Cn, whenever n > k. Then (by dividing both sides of n 2 Cn) by n, then n C must hold for all n > k. A contradiction! Big-O Estimates for Polynomials Example: Let where are real numbers with a n 0. Then f x is O x n ). Proof: f(x) = a n x n + a n-1 x n-1 + + a 1 x 1 + a 1 a n x n + a n-1 x n-1 + + a 1 x 1 + a 1 Uses triangle inequality, an exercise in Section 1.8. x n ( a n + a n-1 /x + + a 1 /x n-1 + a 1 / x n ) x n ( a n + a n-1 + + a 1 + a 1 ) Take C = a n + a n-1 + + a 1 + a 1 and k = 1. Then f x is O x n ). The leading term a n x n of a polynomial dominates its growth. Assuming x > 1 Big-O Estimates for Polynomials Example: Let where are real numbers with a n 0. Then f x is O x n ). Proof: f(x) = a n x n + a n-1 x n-1 + + a 1 x 1 + a 1 a n x n + a n-1 x n-1 + + a 1 x 1 + a 1 Uses triangle inequality, an exercise in Section 1.8. x n ( a n + a n-1 /x + + a 1 /x n-1 + a 1 / x n ) x n ( a n + a n-1 + + a 1 + a 1 ) Take C = a n + a n-1 + + a 1 + a 1 and k = 1. Then f x is O x n ). The leading term a n x n of a polynomial dominates its growth. Assuming x > 1 Big-O Estimates for some Important Functions Example: Use big-o notation to estimate the sum of the first n positive integers. Example: Use big-o notation to estimate the factorial function Continued

Big-O Estimates for some Important Functions Example: Use big-o notation to estimate the sum of the first n positive integers. Example: Use big-o notation to estimate the factorial function Big-O Estimates for some Important Functions Example: Use big-o notation to estimate log n! Given that (previous slide) then. Hence, log(n!) is O(n C Continued Big-O Estimates for some Important Functions Display of Growth of Functions Example: Use big-o notation to estimate log n! Given that (previous slide) then. Hence, log(n!) is O(n C Note the difference in behavior of functions as n gets larger

Useful Big-O Estimates Involving Logarithms, Powers, and Exponents If d > c >, then n c is O(n d ), but n d is not O(n c ). If b > and c and d are positive, then (log b n) c is O(n d ), but n d is not O((log b n) c ). If b > and d is positive, then n d is O(b n ), but b n is not O(n d ). If c > b >, then b n is O(c n ), but c n is not O(b n ). Combinations of Functions If f 1 x is O g 1 (x)) and f 2 x is O g 2 (x)) then ( f 1 + f 2 )(x) is O(max( g 1 (x), g 2 (x). See next slide for proof If f 1 x and f 2 x are both O g(x)) then ( f 1 + f 2 )(x) is O(g(x). See text for argument If f 1 x is O g 1 (x)) and f 2 x is O g 2 (x)) then ( f 1 f 2 )(x) is O(g 1 (x)g 2 (x). See text for argument Combinations of Functions If f 1 x is O g 1 (x)) and f 2 x is O g 2 (x)) then ( f 1 + f 2 )(x) is O(max( g 1 (x), g 2 (x). By the definition of big-o notation, there are constants C 1,C 2,k 1,k 2 such that f 1 x C 1 g 1 (x) when x k 1 and f 2 x C 2 g 2 (x) when x k 2. ( f 1 + f 2 )(x) = f 1 (x) + f 2 (x) f 1 x f 2 x by the triangle inequality a b a b f 1 x f 2 x C 1 g 1 (x) C 2 g 2 (x) C 1 g(x) C 2 g(x) where g(x) = max( g 1 (x), g 2 (x) C 1 C 2 ) g(x) C g(x) where C = C 1 C 2 Therefore ( f 1 + f 2 )(x) C g(x) whenever x > k, where k = max(k 1,k 2 ). Combinations of Functions If f 1 x is O g 1 (x)) and f 2 x is O g 2 (x)) then ( f 1 + f 2 )(x) is O(max( g 1 (x), g 2 (x). By the definition of big-o notation, there are constants C 1,C 2,k 1,k 2 such that f 1 x C 1 g 1 (x) when x k 1 and f 2 x C 2 g 2 (x) when x k 2. ( f 1 + f 2 )(x) = f 1 (x) + f 2 (x) f 1 x f 2 x by the triangle inequality a b a b f 1 x f 2 x C 1 g 1 (x) C 2 g 2 (x) C 1 g(x) C 2 g(x) where g(x) = max( g 1 (x), g 2 (x) C 1 C 2 ) g(x) C g(x) where C = C 1 C 2 Therefore ( f 1 + f 2 )(x) C g(x) whenever x > k, where k = max(k 1,k 2 ).

Ordering Functions by Order of Growth Put the functions below in order so that each function is big-o of the next function on the list. f 1 (n) = (1.5) n f 2 (n) = 8n 3 17n 2 111 f 3 (n) = (log n ) 2 f 4 (n) = 2 n f 5 (n) = log log n f 6 (n) = n 2 (log n) 3 f 7 (n) = 2 n n 2 1 f 8 (n) = n 3 n log n 2 f 9 (n) = 10000 f 10 (n) = n! We solve this exercise by successively finding the function that grows slowest among all those left on the list. f 9 (n) = 10000 constant, does not increase with n f 5 (n) = log log n grows slowest of all the others f 3 (n) = (log n ) 2 grows next slowest f 6 (n) = n 2 (log n) 3 next largest, (log n) 3 factor smaller than any power of n f 2 (n) = 8n 3 17n 2 111 tied with the one below f 8 (n) = n 3 n log n 2 tied with the one above f 1 (n) = (1.5) n (next largest, an exponential function) f 4 (n) = 2 n grows faster than one above since 2 1.5 f 7 (n) = 2 n n 2 1 grows faster than above because of the n 2 1 factor f 10 (n) = 3 n n! grows faster than c n for every c Ordering Functions by Order of Growth Put the functions below in order so that each function is big-o of the next function on the list. f 1 (n) = (1.5) n f 2 (n) = 8n 3 17n 2 111 f 3 (n) = (log n ) 2 f 4 (n) = 2 n f 5 (n) = log log n f 6 (n) = n 2 (log n) 3 f 7 (n) = 2 n n 2 1 f 8 (n) = n 3 n log n 2 f 9 (n) = 10000 f 10 (n) = n! We solve this exercise by successively finding the function that grows slowest among all those left on the list. f 9 (n) = 10000 constant, does not increase with n f 5 (n) = log log n grows slowest of all the others f 3 (n) = (log n ) 2 grows next slowest f 6 (n) = n 2 (log n) 3 next largest, (log n) 3 factor smaller than any power of n f 2 (n) = 8n 3 17n 2 111 tied with the one below f 8 (n) = n 3 n log n 2 tied with the one above f 1 (n) = (1.5) n (next largest, an exponential function) f 4 (n) = 2 n grows faster than one above since 2 1.5 f 7 (n) = 2 n n 2 1 grows faster than above because of the n 2 1 factor f 10 (n) = 3 n n! grows faster than c n for every c Big-Omega Notation Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that if there are constants C and k such that when x > k. We say that f(x) is big-omega of g(x). Big-O gives an upper bound on the growth of a function, while Big-Omega gives a lower bound. f(x) is Ω(g(x)) if and only if g(x) is O(f(x)). This follows from the definitions. Big-Omega Notation Example: Show that is where. for all positive real numbers x. Is it also the case that is Ω is the upper case version of the lower case Greek letter ω.

Big-Omega Notation Big-Theta Notation Θ is the upper case version of the lower case Greek letter θ. Example: Show that is where. for all positive real numbers x. Is it also the case that is Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. The function if and. We say that f is big-theta of g(x) and also that f(x) is of order g(x) and also that f(x) and g(x) are of the same order. if and only if there exists constants C 1, C 2 and k such that C 1 g(x)< f(x) < C 2 g(x) if x > k. This follows from the definitions of big-o and big- Omega. Big Theta Notation Example: Show that the sum of the first n positive integers is (n 2 ). Let f(n) = + + + n. We have already shown that f(n) is O(n 2 ). To show that f(n) is Ω(n 2 ), we need a positive constant C such that f(n) > Cn 2 for sufficiently large n. Summing only the terms greater than n/2 we obtain the inequality 1 + 2 + + n n/2 + ( n/2 + 1 + + n n/2 + n/2 + + n/2 n n/2 + 1 ) n/2 n/2 n/2 n 2 /4 Taking C ¼, f(n) > Cn 2 for all positive integers n. Hence, f(n) is Ω(n 2 ), and we can conclude that f(n) is Θ(n 2 ). Big-Theta Notation Example: Show that f(x) = x 2 + 8x log x is x 2 ). 3x 2 + 8x log x 11x 2 for x 1, since 0 8x log x 8x 2. Hence, 3x 2 + 8x log x is O x 2 ). x 2 is clearly O 3x 2 + 8x log x) Hence, 3x 2 + 8x log x is Θ x 2 ).

Big-Theta Notation Example: Show that f(x) = x 2 + 8x log x is x 2 ). 3x 2 + 8x log x 11x 2 for x 1, since 0 8x log x 8x 2. Hence, 3x 2 + 8x log x is O x 2 ). x 2 is clearly O 3x 2 + 8x log x) Hence, 3x 2 + 8x log x is Θ x 2 ). When the case that Big-Theta Notation it must also be Note that if and only if it is the case that and Big-Theta Estimates for Polynomials Theorem: Let where are real numbers with a n 0. Then f x is of order x n (or Θ x n )). (The proof is an exercise.) Example: The polynomial is order of x 5 (or Θ x 5 )). The polynomial is order of x 199 (or Θ x 199 ) ). Big-Theta Estimates for Polynomials Theorem: Let where are real numbers with a n 0. Then f x is of order x n (or Θ x n )). (The proof is an exercise.) Example: The polynomial is order of x 5 (or Θ x 5 )). The polynomial is order of x 199 (or Θ x 199 ) ).