Big-O Analysis. Asymptotics

Similar documents
Big-O Analysis. Asymptotics

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

CS473-Algorithms I. Lecture 2. Asymptotic Notation. CS 473 Lecture 2 1

Algorithms Chapter 3 Growth of Functions

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

Lecture 6. Lecturer: Ronitt Rubinfeld Scribes: Chen Ziv, Eliav Buchnik, Ophir Arie, Jonathan Gradstein

Lecture 5. Counting Sort / Radix Sort

2. ALGORITHM ANALYSIS

Lecture 1: Introduction and Strassen s Algorithm

Homework 1 Solutions MA 522 Fall 2017

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

1.2 Binomial Coefficients and Subsets

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Analysis of Algorithms

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions

CSE 417: Algorithms and Computational Complexity

Practical Session 2 Constants Don t Matter!!!

Convergence results for conditional expectations

1 Graph Sparsfication

condition w i B i S maximum u i

6.854J / J Advanced Algorithms Fall 2008

Recursive Estimation

Assignment 5; Due Friday, February 10

Name of the Student: Unit I (Logic and Proofs) 1) Truth Table: Conjunction Disjunction Conditional Biconditional

2 X = 2 X. The number of all permutations of a set X with n elements is. n! = n (n 1) (n 2) nn e n

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Improved Random Graph Isomorphism

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))

c-dominating Sets for Families of Graphs

Algorithm. Counting Sort Analysis of Algorithms

The isoperimetric problem on the hypercube

15-859E: Advanced Algorithms CMU, Spring 2015 Lecture #2: Randomized MST and MST Verification January 14, 2015

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

NTH, GEOMETRIC, AND TELESCOPING TEST

Math 10C Long Range Plans

ON A PROBLEM OF C. E. SHANNON IN GRAPH THEORY

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Fundamentals of Media Processing. Shin'ichi Satoh Kazuya Kodama Hiroshi Mo Duy-Dinh Le

Exact Minimum Lower Bound Algorithm for Traveling Salesman Problem

Planar graphs. Definition. A graph is planar if it can be drawn on the plane in such a way that no two edges cross each other.

South Slave Divisional Education Council. Math 10C

5.3 Recursive definitions and structural induction

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

The Graphs of Polynomial Functions

prerequisites: 6.046, 6.041/2, ability to do proofs Randomized algorithms: make random choices during run. Main benefits:

Order statistics. Order Statistics. Randomized divide-andconquer. Example. CS Spring 2006

MATHEMATICAL METHODS OF ANALYSIS AND EXPERIMENTAL DATA PROCESSING (Or Methods of Curve Fitting)

Module 8-7: Pascal s Triangle and the Binomial Theorem

CMPT 125 Assignment 2 Solutions

CIS 121. Introduction to Trees

Massachusetts Institute of Technology Lecture : Theory of Parallel Systems Feb. 25, Lecture 6: List contraction, tree contraction, and

Ones Assignment Method for Solving Traveling Salesman Problem

A study on Interior Domination in Graphs

Ch 9.3 Geometric Sequences and Series Lessons

Thompson s Group F (p + 1) is not Minimally Almost Convex

Numerical Methods Lecture 6 - Curve Fitting Techniques

Counting the Number of Minimum Roman Dominating Functions of a Graph

The Adjacency Matrix and The nth Eigenvalue

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Lower Bounds for Sorting

Examples and Applications of Binary Search

Counting Regions in the Plane and More 1

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Computational Geometry

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

On Infinite Groups that are Isomorphic to its Proper Infinite Subgroup. Jaymar Talledo Balihon. Abstract

Lecture 2: Spectra of Graphs

9 x and g(x) = 4. x. Find (x) 3.6. I. Combining Functions. A. From Equations. Example: Let f(x) = and its domain. Example: Let f(x) = and g(x) = x x 4

Mathematical Stat I: solutions of homework 1

MAXIMUM MATCHINGS IN COMPLETE MULTIPARTITE GRAPHS

Algorithm Efficiency

ON MATHIEU-BERG S INEQUALITY

Relational Interpretations of Neighborhood Operators and Rough Set Approximation Operators

Matrix Partitions of Split Graphs

New Results on Energy of Graphs of Small Order

How do we evaluate algorithms?

Chapter 3 Classification of FFT Processor Algorithms

UNIT 1 RECURRENCE RELATIONS

A Comparative Study of Positive and Negative Factorials

Combination Labelings Of Graphs

Math Section 2.2 Polynomial Functions

Alpha Individual Solutions MAΘ National Convention 2013

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

. Written in factored form it is easy to see that the roots are 2, 2, i,

Data Structures Week #9. Sorting

CSE 2320 Notes 8: Sorting. (Last updated 10/3/18 7:16 PM) Idea: Take an unsorted (sub)array and partition into two subarrays such that.

Transcription:

Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses a upper boud o the growth rate of a fuctio, for sufficietly large values of. By the defiitio above, demostratig that a fuctio f is big-o of a fuctio g requires that we fid specific costats C ad N for which the iequality holds (ad show that the iequality does, i fact, hold).

Big-O Example Cosider the followig fuctio: 5 5 T ( ) We might guess that: T ( ) 5 for all We could easily verify the guess by iductio: If =, the T() = 17 which is less tha 0, so the guess is valid if =. Assume that for some, T() 5. The: 5 5 5 5 5 5 T 5 5 5 5 ( 1) ( 1) ( 1) 5 5 5 5 by the iductive assumptio 5 10 5 5( 1) Thus, by iductio, T() 5 for all. So, by defiitio, T() is O( ).

Makig the Guess 3 The obvious questio is "how do we come up with the guess i the first place"? Here's oe possible aalysis (which falls a bit short of beig a proof): 5 5 T 5 5 ( ) 5 (replace with ^, subtract ) The middle step seems soud sice if the, substitutig will thus add at least 5 to the expressio, so that subtractig should still result i a larger value.

Big-O Theorems 4 For all the followig theorems, assume that f() is a o-egative fuctio of ad that K is a arbitrary positive costat. Theorem 1: K is O(1) Theorem : A polyomial is O(the term cotaiig the highest power of ) f ( ) 7 4 3 5 1000 is O(7 4 ) Theorem 3: K*f() is O(f()) [i.e., costat coefficiets ca be dropped] g( ) 7 4 is O( 4 ) Theorem 4: If f() is O(g()) ad g() is O(h()) the f() is O(h()). [trasitivity] f ( ) 7 4 3 5 1000 is O( 4 )

Big-O Theorems 5 Theorem 5: Each of the followig fuctios is strictly big-o of its successors: K [costat] log b () [always log base if o base is show] log b () to higher powers 3 larger costats to the -th power! [ factorial] smaller larger f ( ) 3 log( ) is O( log( )) ad O( ) ad O( )

Big-O Theorems 6 Theorem 6: I geeral, f() is big-o of the domiat term of f(), where domiat may usually be determied from Theorem 5. f ( ) 7 3 log( ) 5 1000 is O( ) g( ) 7 3 1000000 is O(3 4 ) h( ) 7( log( )) is O( ) Theorem 7: For ay base b, log b () is O(log()).

Big-Omega 7 I additio to big-o, we may seek a lower boud o the growth of a fuctio: Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is (g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big- expresses a lower boud o the growth rate of a fuctio, for sufficietly large values of. Aalagous theorems ca be proved for big-ω.

Big-Theta 8 Fially, we may have two fuctios that grow at essetially the same rate: Defiitio: Alerative: Suppose that f() ad g() are oegative fuctios of. The we say that f() is (g()) provided that f() is O(g()) ad also that f() is (g()). Suppose that f() ad g() are oegative fuctios of. The we say that f() is (g()) provided that there exist costats C1 > 0, C > 0 ad N > 0 such that, for all > N, C 1 g() f() C g(). If f is (g) the, from some poit o, f is bouded below by oe multiple of g ad bouded above by aother multiple of g (ad vice versa). So, i a very basic sese f ad g grow at the same rate.

Order ad Limits 9 The task of determiig the order of a fuctio is simplified cosiderably by the followig result: Theorem 8: f() is (g()) if lim f ( ) g( ) c where 0 c Recall Theorem 7 we may easily prove it (ad a bit more) by applyig Theorem 8: lim log b ( ) log( ) lim 1 l( b) 1 l() lim l() l( b) l() l( b) The last term is fiite ad positive, so log b () is (log()) by Theorem 8. Corollary: if the limit above is 0 the f() is strictly O(g()), ad if the limit is the f() is strictly (g()).

Order ad Limits 10 The coverse of Theorem 8 is false. However, it is possible to prove: Theorem 9: If f() is (g()) the provided that the limit exists. lim f ( ) g( ) c where 0 c A similar extesio of the precedig corollary also follows.

More Theorems 11 May of the big-o theorems may be stregtheed to statemets about big-: Theorem 10: If K > 0 is a costat, the K is (1). Theorem 11: A polyomial is (the highest power of ). proof: Suppose a polyomial of degree k. The we have: lim a a a k 0 1 k lim k a 0 k a 1 k 1 a k 1 a k a Now a k > 0 sice we assume the fuctio is oegative. So by Theorem 8, the polyomial is ( k ). k QED

More Theorems 1 Theorems 3, 6 ad 7 ca be similarly exteded. Theorem 1: K*f() is (f()) [i.e., costat coefficiets ca be dropped] Theorem 13: I geeral, f() is big- of the domiat term of f(), where domiat may usually be determied from Theorem 5. Theorem 14: For ay base b, log b () is (log()).

Strict Comparisos 13 For coveiece, we will say that: - f is strictly O(g) if ad oly if f is O(g) but f is ot Θ(g) - f is strictly Ω(g) if ad oly if f is Ω(g) but f is ot Θ(g) For example, log is strictly O( ) by Theorem 8 ad its corollary, because: log log 1/ lim lim lim 0 1

Big- Is a Equivalece Relatio 14 Theorem 15: If f() is (f()). [reflexivity] Theorem 16: If f() is (g()) the g() is (f()). [symmetry] Theorem 17: If f() is (g()) ad g() is (h()) the f() is (h()). [trasitivity] By Theorems 15 17, is a equivalece relatio o the set of positive-valued fuctios. The equivalece classes represet fudametally differet growth rates. Algorithms whose complexity fuctios belog to the same class are essetially equivalet i performace (up to costat multiples, which are ot uimportat i practice).

Applicatios to Algorithm Aalysis 15 Ex 1: A algorithm with complexity fuctio 3 T ( ) 5 3 is ( ) by Theorem 10. Ex : A algorithm with complexity fuctio T ( ) 3 log 4log is O( log()) by Theorem 5. Furthermore, the algorithm is also ( log()) by Theorem 8 sice: lim T ( ) log lim 3 4 log 3 For most commo complexity fuctios, it's this easy to determie the big-o ad/or big- complexity usig the give theorems.

Complexity of Liear Storage 16 For a cotiguous list of N elemets, assumig each is equally likely to be the target of a search: - average search cost is (N) if list is radomly ordered - average search cost is (log N) is list is sorted - average radom isertio cost is (N) - isertio at tail is (1) For a liked list of N elemets, assumig each is equally likely to be the target of a search: - average search cost is (N), regardless of list orderig - average radom isertio cost is (1), excludig search time

Most Commo Complexity Classes 17 Theorem 5 lists a collectio of represetatives of distict big-θ equivalece classes: K [costat] log b () [always log base if o base is show] log b () to higher powers 3 larger costats to the -th power! [ factorial] Most commo algorithms fall ito oe of these classes. Kowig this list provides some kowledge of how to compare ad choose the right algorithm. The followig charts provide some visual idicatio of how sigificat the differeces are

Graphical Compariso 18 Commo Growth Curves 100 1000 800 600 400 log log ^ ^3 ^ 10^ 00 0 1 3 4 5 6 7 8 9 10 11 (iput size)

Lower-order Classes 19 For sigificatly large values of, oly these classes are truly practical, ad whether is practical is debated. 10 100 Low-order Curves log 80 60 40 0 0 log 1 3 5 7 9 11 13 15 17 19 1 3 (iput size)

Proof of Theorem 8 0 Theorem 8: f() is (g()) if lim f ( ) g( ) c where 0 c Suppose that f ad g are o-egative fuctios of, ad that lim f ( ) g( ) c where 0 c The, from the defiitio of the limit, for every ε > 0 there exists a N > 0 such that wheever > N: f ( ) c from which we have ( c ) g( ) f ( ) ( c ) g( ) g ( ) Let ε = c/, the we have that: Therefore, by defiitio, f is Θ(g). 3c f ( ) g( ) whece f is ( g) c g ( ) f ( ) whece f is ( g )