The Growth of Functions: Selected Exercises

Slides:



Advertisements
Similar presentations
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Introduction to Algorithms
Data Structures Through C
Analysis of Algorithms II
BY Lecturer: Aisha Dawood. The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains.
Introduction to Algorithms 6.046J/18.401J
The Pigeonhole Principle: Selected Exercises
22C:19 Discrete Math Algorithms and Complexity
The Basics of Counting: Selected Exercises. Copyright © Peter Cappello2 Sum Rule Example There are 3 sizes of pink shirts & 7 sizes of blue shirts. How.
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
Recurrence Relations: Selected Exercises
Recursive Definitions & Structural Induction: Selected Exercises
Generalized Permutations & Combinations: Selected Exercises.
Introduction to Proofs
Algorithm Analysis.
Algorithm Complexity Level II, Term ii CSE – 243 Md. Monjur-ul-hasan
Chapter Algorithms 3.2 The Growth of Functions
Complexity Analysis (Part II)
Asymptotics Section 3.2 of Rosen Spring 2010 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
Master Theorem Chen Dan Dong Feb. 19, 2013
Copyright © Cengage Learning. All rights reserved.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
CSE115/ENGR160 Discrete Mathematics 03/01/12
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
Discrete Mathematics CS 2610 February 26, part 1.
The Growth of Functions
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 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.
3/10/03Tucker, Sec.3-51 Tucker, Applied Combinatorics, Sec. 3.5, Jo E-M “Big O” Notation We say that a function is if for some constant c, when n is large.
Partial Orderings: Selected Exercises
Introduction to Proofs Goals 1.Introduce notion of proof & basic proof methods. 2.Distinguish between correct & incorrect arguments 3.Understand & construct.
Proof Methods & Strategy
Algorithms: Selected Exercises Goals Introduce the concept & basic properties of an algorithm.
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
Instructor Neelima Gupta
The Growth of Functions Rosen 2.2 Basic Rules of Logarithms log z (xy) log z (x/y) log z (x y ) If x = y If x < y log z (-|x|) is undefined = log z (x)
MCA 202: Discrete Structures Instructor Neelima Gupta
Introduction to Programming (in C++) Complexity Analysis of Algorithms
CPSC 411 Design and Analysis of Algorithms
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Relations & Their Properties: Selected Exercises.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Section 5.6 Comparing Rates of Growth We often need to compare functions ƒ and g to see whether ƒ(n) and g(n) are about the same or whether one grows.
EXAMPLE 3 Write an indirect proof Write an indirect proof that an odd number is not divisible by 4. GIVEN : x is an odd number. PROVE : x is not divisible.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
Strong Induction: Selected Exercises Goal Explain & illustrate proof construction of a variety of theorems using strong induction.
Introduction to Proofs Goals 1.Introduce notion of proof & basic proof methods. 2.Distinguish between correct & incorrect arguments 3.Understand & construct.
The Growth of Functions: Selected Exercises
Partial Orderings: Selected Exercises
Analysis of Algorithms
EQUATION IN TWO VARIABLES:
The Growth of Functions
The Growth of Functions
CS 3343: Analysis of Algorithms
O-notation (upper bound)
Algorithm design and Analysis
Asymptotic Notations Algorithms Lecture 9.
Asymptotic Growth Rate
BIG-OH AND OTHER NOTATIONS IN ALGORITHM ANALYSIS
Analysis of Algorithms
Algorithmic Complexity
CSE 373, Copyright S. Tanimoto, 2002 Asymptotic Analysis -
Applied Combinatorics, 4th Ed. Alan Tucker
More on Asymptotic Analysis + Performance Measurement
Advanced Algorithms Analysis and Design
Analysis of Algorithms
Relations & Their Properties: Selected Exercises
Presentation transcript:

The Growth of Functions: Selected Exercises Goals Introduce big-O & big-Omega Show how to estimate the size of functions using this notation.

Copyright © Peter Cappello Preface You may use without proof that: The functions below increase asymptotically from top to bottom: f( n ) = k, for some constant k. f( n ) = logk n, for all k  N & any constant log base ≥ 2. f( n ) = nq, for all q  Q+ f( n ) = kn < (k+1)n, for all k  N f( n ) = n! Copyright © Peter Cappello

Copyright © Peter Cappello Preface continued The book says that f(n) is O( g( n ) ) when k c n ( n > k  | f( n ) |  c | g( n ) | ) In computational complexity, we deal exclusively with functions whose domains & ranges are positive. We thus may simplify the definition of O( ) as follows: k c n > k f( n )  c g( n ). You are not responsible for knowing o(). This is different from O(). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 10 Defn: f( n ) is O( g( n ) ) if k c n > k f( n )  cg( n ). Show that: 1) n3 is O( n4 ) 2) n4 is not O( n3 ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise10: Solution Defn: f( n ) is O( g( n ) ) when k c n > k f( n )  cg( n ). Show that: 1) n3 is O( n4 ) 2) n4 is not O( n3 ). For n ≥ 1 & c = 1: n3  1n4  1  n. Proof (by contradiction) Assume k c n > k n4  cn3. k c n > k n4  cn3  k c n > k n  c ), which is false. ( Divide both sides by n3 ) 3) Therefore, n4 is not O( n3 ). Copyright © Peter Cappello

Copyright © Peter Cappello Theorems You Can Use Thm 1: Let f(x) = anxn + an-1xn-1 + … + a1x + a0, where the ai are real. Then, f(x) is O( xn ). Let f1(x) is O (g1(x) ) & f2(x) is O( g2(x) ). Thm 2: (f1 + f2)(x) is O( max( g1(x), g2(x) ) ) Thm 3: (f1 f2)(x) is O( (g1g2)(x) ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 Give a big-O estimate for the functions: (Use a simple g of smallest order.) a) f( n ) = ( n3 + n2logn )( logn + 1 ) + ( 17logn + 19 )( n3 + 2 ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 a) Solution Give a big-O estimate for the functions: (Use a simple g of smallest order.) a) f( n ) = ( n3 + n2logn )( logn + 1 ) + ( 17logn + 19 )( n3 + 2 ). Using our theorems, ( n3 + n2logn )( logn + 1 ) + ( 17logn + 19 )( n3 + 2 ) Is O( ( n3 )( logn ) + ( 17logn )( n3 ) ) Is O( ( n3 logn ) + ( n3 17logn ) Is O( ( n3 logn ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 b) b) f( n ) = ( 2n + n2 )( n3 + 3n ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 b) Solution b) f( n ) = ( 2n + n2 )( n3 + 3n ). Using our theorems, f( n ) = ( 2n + n2 )( n3 + 3n ) is O( ( 2n )( 3n ) ) which is O( 2n3n ) which is O( 6n ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 c) c) f( n ) = ( nn + n2n + 5n )( n! + 5n ) Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 20 c) Solution Defn: f( n ) is O( g( n ) ) when k c n > k f( n )  cg( n ). c) f( n ) = ( nn + n2n + 5n )( n! + 5n ) Using our theorems, f( n ) is O( ( nn + n2n )( n! ) ) In nn + n2n, which is the fastest growing term? Claim: n2n is O ( nn ) : n ≥ 2  2n-1  nn-1. n ≥ 2  n2n  2nn. (Multiply both sides of 1. by 2n.) Thus, f( n ) is O( nnn! ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 30 Defn: f( n ) is O( g( n ) ) when k c n > k f( n )  cg( n ). Defn. f( n ) is Ω( g( n ) ) when k c > 0 n > k f( n ) ≥ cg( n ). What does it mean for f( n ) to be Ω( 1 )? Hint: graph f( n ). Copyright © Peter Cappello

Copyright © Peter Cappello Exercise 30 Solution Defn. f( n ) is Ω( g( n ) ) when k c > 0 n > k f( n ) ≥ c g( n ). What does it mean for a function to be Ω( 1 )? From the definition, f( n ) is Ω( 1 ) when k c > 0 n > k f( n ) ≥ c. f( n ) ≥ c > 0, for sufficiently large n. f( n ) = 1/n is Ω( 1 ). True or false? Copyright © Peter Cappello

Generalizing the definitions Defn: f( n ) is O( g( n ) ) when k c n > k f( n )  cg( n ). What is a good definition of f( n, m ) is O( g( n, m ) )? Copyright © Peter Cappello

Time Complexity of Bubble Sort void bubblesort( int[] a ) { for ( int i = 0; i < a.length – 1; i++ ) for ( int j = 0; j < a.length – 1 – i; j++ ) if ( a[ j ] < a[ j + 1 ] ) int temp = a[ j ]; a[ j ] = a[ j + 1 ]; a[ j + 1 ] = temp; } Let a.length = n. What is the total # of comparisons as a function of n? This number is O( ? ) Copyright © Peter Cappello

Copyright © Peter Cappello End 3.2 Copyright © Peter Cappello

Copyright © Peter Cappello 2011 40 Defn. f( n ) is Θ( g( n ) ) when f( n ) is O( g ( n ) ) and f( n ) is Ω( g( n ) ). Show that: if f1( x ) & f2( x ) are functions from Z+ to R and f1( x ) is Θ( g1( x ) ) and f2( x ) is Θ( g2( x ) ), then f1f2 ( x ) is Θ( g1g2( x ) ). Copyright © Peter Cappello 2011

Copyright © Peter Cappello 2011 40 Proof Assume f1( x ) & f2( x ) are functions from Z+ to R and f1( x ) is Θ( g1( x ) ) and f2( x ) is Θ( g2( x ) ). f1( x ) is O( g1( x ) ). (1. and defn of Θ) k1, C1, x > k1  f1( x )  C1g1( x ) (2.,Defn of O) f2( x ) is O( g2( x ) ). (1. and defn of Θ) k2, C2, x > k2  f2( x )  C2g2( x ) (4., Defn of O) x > max{ k1, k2 }  f1 f2( x )  C1C2g1g2( x ) f1 f2( x ) is O( g1g2( x ) ). (6., Defn of O) Copyright © Peter Cappello 2011

Copyright © Peter Cappello 2011 40 Proof continued f1( x ) is Ω( g1( x ) ). (Previous 1. & defn of Θ) k’1, C’1, x > k’1  f1( x ) ≥ C’1g1( x ) (1. & Defn of Ω) f2( x ) is Ω( g2( x ) ). (Previous 1. & defn of Θ) k’2, C’2, x > k’2  f2( x ) ≥ C’2g2( x ) (3. & Defn of Ω) x > max{ k’1, k’2 }  f1 f2( x ) ≥ C’1C’2g1g2( x ) f1 f2( x ) is Ω( g1g2( x ) ). (5. & Defn of Ω) f1 f2( x ) is Θ( g1g2( x ) ). (6., previous 7., defn Θ) Copyright © Peter Cappello 2011

Copyright © Peter Cappello 2011 50 Show that ┌ xy ┐ is Ω(xy). Proof: ┌ xy ┐ ≥ xy. (Defn of ceiling) Let c = 1. For x > 0, y > 0, ┌ xy ┐ ≥ cxy. Therefore,┌ xy ┐ is Ω(xy). (Defn of Ω) Copyright © Peter Cappello 2011