Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.

Similar presentations


Presentation on theme: "Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation."— Presentation transcript:

1 Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation

2 Introduction We are interested how fast a function grows Usually this is related to the running time of an algorithm compared to the size of the input –We may also be interested in space required by an algorithm We may wish to estimate the running time of a program that implements an algorithm Copyright © 2014 Curt Hill

3 Speed of a program There are many factors of a program that have nothing to do with the underlying algorithm Clock speed of the computer Instruction set of the computer Language in which program is written Coding details We may change the running speed by changing any of the above Instead we are interested in those intrinsic factors of the algorithm itself Copyright © 2014 Curt Hill

4 Big O Notation The O stands for Order of This notation captures the most elementary function that describes how the running time varies with the input size We typically eliminate everything except the most rapidly growing function We also eliminate all constant factors as well Copyright © 2014 Curt Hill

5 Example Suppose that the running time of a program is given by the following function: f(x) = 1.8x 2 + 182.9x + 43.78 –Where x is the number of input items –Result is in some unit of time, eg milliseconds We would then say the program is O(x 2 ) Changing any number of things would change the constants but not the O Copyright © 2014 Curt Hill

6 Again What does this really mean? When we say our program with running time 1.8x 2 + 182.9x + 43.78 is O(x 2 ) what we really mean is the following: –There is a constant k –When x gets large then f(x) < kx 2 Since the square term will ultimately dominate all the lesser terms this will continue as x gets larger Copyright © 2014 Curt Hill

7 Big O Rules Again If f(x) is the sum of several functions the one with the fastest rate is retained and others discarded If there are constants that are multiplied times a function they are also ignored Copyright © 2014 Curt Hill

8 Common Os Constant – O(1) or O(c) Logarithmic – O(log 2 n) Linear – O(n) NlogN – O(nlog 2 n) Quadratic – O(n 2 ) Cubic – O(n 3 ) Polynomial – O(n c ), where c is a constant, i ncludes quadratic and cubic Exponential – O(2 n ) Factorial – O(n!) Copyright © 2014 Curt Hill

9 Picture Copyright © 2014 Curt Hill

10 Notation Again Sometimes we say f(x) is O(g(x)) –Eg. f(x) is O(n log n) This is sometimes written f(x) = O(g(x)) –This is strange, but accepted, use of = Thus O(x) = O(x 2 ) is not symmetric with O(x 2 ) = O(x) Instead what we are saying in O(x) = O(x 2 ) is that linear time is a subset of quadratic time –Eg. Has an upper bound Copyright © 2014 Curt Hill

11 Commentary Big O is all about the upper bound of a computation Algorithms with exponents large than four are unusual Polynomial and slower growing are tractable Exponential, factorial and faster growing algorithms are generally called intractable Copyright © 2014 Curt Hill

12 Tractable and Intractable Copyright © 2014 Curt Hill 10501003001000 O(n)10501003001000 O(n log n)332826652,4699,966 n2n2 1002,50010,00090,0001 x 10 7 n3n3 1000125,0001 x 10 7 2.7 x 10 8 1 x 10 10 2n2n 1024~10 16 ~10 161 ~10 623 Big n!3.6 x 10 7 ~10 65 ~10 201 ~10 744 Big

13 Other Notations Big O is all about the upper bound of a computation Occasionally we want other bounds Big Omega (big  ) is used for lower bounds –There is k factor that will always be less than the running time Big Theta (big  ) is used for both upper and lower bounds –There are two constants that bracket upper and lower bounds Copyright © 2014 Curt Hill

14 Example Suppose that: f(x) = 2x 4 +42x 3 +902x 2 +2096x+8095.3 What is big  ? Copyright © 2014 Curt Hill

15 Exercises 3.2 –3, 7, 19, 23, 27 Copyright © 2014 Curt Hill


Download ppt "Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation."

Similar presentations


Ads by Google