CMPS Itroductio to Aalysis of Algorithms Fall 3 Asymptotic Growth of Fuctios We itroduce several types of asymptotic otatio which are used to compare the performace ad efficiecy of algorithms As we ll see, the asymptotic ru time of a algorithm gives a simple, ad machie idepedet, characterizatio of it s complexity Defiitio Let g ( be a fuctio The set O ( is defied as O = { f ( c >, >, : f ( c ) } ( I other words, f ( O( if ad oly if there exist positive costats c, ad, such that for all, the iequality f ( c is satisfied We say that f ( is Big O of g (, or that g ( is a asymptotic upper boud for f ( We ofte abuse otatio slightly by writig f ( to mea f ( O( Actually f ( O( is also a abuse of otatio We should really write f O(g) sice what we have defied is a set of fuctios, ot a set of umbers The otatioal covetio O ( is useful sice it allows us to refer to the set O ( 3 ) say, without havig to itroduce a fuctio symbol for the 3 polyomial Observe that if f ( the f ( is asymptotically o-egative, ie f ( is o-egative for all sufficietly large, ad liewise for g ( We mae the blaet assumptio from ow o that all fuctios uder discussio are asymptotically o-egative I practice we will be cocered with iteger valued fuctios of a (positive) iteger ( g : Z + Z + ) However, i what follows, it is useful to cosider to be a cotiuous real variable taig positive values ad g to be real valued fuctio ( g : R + R + ) Geometrically f ( says: cg ( f (
Example 4 + + + 3) Observe that 4 + + + 3 for all, as ca be easily verified Thus we may tae = ad c = i the defiitio + + 3 3 4 + Note that i this example, ay value of greater tha will also wor, ad liewise ay value of c greater tha wors I geeral if there exist positive costats ad c such that f ( c for all, the ifiitely may such costats also exist I order to prove that f ( it is ot ecessary to fid the smallest possible ad c maig the f ( c true It is oly ecessary to show that at least oe pair of such costats exist Geeralizig the last example, we will show that a + b c + d + e) for ay costats a-e, ad i fact p ( q( wheever p ( ad q ( are polyomials with de p) de q) Defiitio Let g ( be a fuctio ad defie the set Ω ( to be Ω = { f ( c >, >, : c f ( )} ( We say f ( is big Omega of g (, ad that g ( is a asymptotic lower boud for f ( As before we write f ( to mea f ( Ω( The geometric iterpretatio is: f ( cg (
Lemma f ( if ad oly if f ( Proof: If f ( the there exist positive umbers c, such that f ( c for all Let c = / c ad = The c f ( for all, provig f ( The coverse is similar ad we leave it to the reader /// Defiitio Let g ( be a fuctio ad defie the set Θ ( Ω( Equivaletly Θ( = { f ( c >, c >, >, : c f ( c } We write f ( ad say the g ( is a asymptotically tight boud for f (, or that f ( ad g ( are asymptotically equivalet We iterpret this geometrically as: c f ( c Exercise Prove that if c is a positive costat, the cf ( f ( Exercise Prove that f ( if ad oly if f ( Example Prove that ) + Proof: Accordig to the defiitio, we must fid positive umbers c, c,, such that the iequality c + c holds for all Pic c =, c =, ad = The if we have: ad ( ) ad ( ) ( c ) ad ( c ) + c ad + c, c + c, + c, c as required /// 3
The reader may fid our choice of values for the costats c, c, i this example somewhat mysterious Adequate values for these costats ca usually be obtaied by worig bacwards algebraically from the iequality to be proved Notice that i this example there are may valid choices For istace oe checs easily that c /, c 3/, ad wor equally well = Exercise Let a, b be real umbers with b > Prove directly from the defiitio (as above) that b b ( + a) ) (I what follows we lear a much easier way to prove this) Lemma If f ( h( for all sufficietly large, ad if h (, the f ( Proof: The above hypotheses say that there exist positive umbers c ad such that h( c for all Also there exists such that f ( h( for all (Recall f ( is assumed to be asymptotically o-egative) Defie = max(, ), so that if we have both ad Thus implies f ( c, ad therefore f ( /// Exercise Prove that if h ( f ( h ( for all sufficietly large, where h ( ad h ( )), the f ( + Example Let be a fixed iteger Prove that i ) + + Proof: Observe that i = = ), ad i i / / ( / ) = = + + + / ( / ) ( / )( / ) = (/ ) ) + By the result of the precedig exercise, we coclude i ) /// Whe asymptotic otatio appears i a formula such as T ( = T ( / ) + Θ( we iterpret Θ ( to 3 3 stad for some aoymous fuctio i the class Θ ( For example 3 + 4 + = 3 + Θ( ) Here Θ ( ) stads for 4 +, which belogs to the class Θ ( ) The expressio = Θ( i) ca be puzzlig O the surface it stads for Θ( ) + Θ() + Θ(3) + + Θ(, i which is meaigless sice Θ (costat) cosists of all fuctios which are bouded above by some costat We iterpret Θ (i) i this expressio to stad for a sigle fuctio f (i) i the class Θ (i), evaluated at i =,, 3,, Exercise Prove that = Θ( i) ) The left had side stads for a sigle fuctio f (i) summed i = ( i for i =,, 3,, By the previous exercise it is sufficiet to show that h f ( i) h ( ) for all sufficietly large, where h ( ) ad h ( ) 4
Defiitio o ( = { f ( c >, >, : f ( < c } We say that g ( is a strict Asymptotic upper boud for f ( ad write f ( as before f ( Lemma f ( if ad oly if lim = f ( Proof: Observe that f ( if ad oly if c >, >, : < c, which is the f ( very defiitio of the limit statemet lim = /// l Example l ) sice lim = (Apply l Hopitals rule) Example b ) for ay > ad b > sice lim = b other words, ay expoetial grows strictly faster tha ay polyomial (Apply l Hopitals rule times) I By comparig defiitios of o ( ad O( oe sees immediately that o( O( Also o fuctio ca belog to both o ( ad Ω (, as is easily verified (exercise) Thus o ( Ω( =, ad therefore o( O( Defiitio ω ( g ( = { f ( c >, >, : c < f ( } Here we say that g ( is a strict asymptotic lower boud for f ( ad write f ( = ω( f ( Exercise Prove that f ( = ω( if ad oly if lim = g ( ) Exercise Prove ω ( O( =, whece ω ( Ω( The followig picture emerges: O ( Ω ( o ( Θ ( ω ( 5
Lemma If f ( lim = L, where L <, the f ( Proof: The defiitio of the above limit is ε =, there exists a positive umber such that for all : f ( L < f ( < L < f ( < L + f ( < ( L + ) f ( ε >, >, : L < ε Thus if we let Now tae c = L + i the defiitio of O, so that f ( as claimed /// f ( Lemma If lim = L, where < L, the f ( Proof: The limit statemet implies lim = L, where L =/ L ad hece L < By the f ( previous lemma g ( f (, ad therefore f ( /// Exercise Prove that if f ( lim = L, where < L <, the f ( Although o (, ω (, ad a certai subset of Θ ( are characterized by limits, the full sets O (, Ω (, ad Θ ( have o such characterizatio as the followig examples show Example A Let g ( = ad f ( = ( + si( g ( f ( f ( Clearly f (, but = + si(, whose limit does ot exist This example shows that the cotaimet o( O( is i geeral strict sice f ( Ω( (exercise) Therefore f ( Θ(, so that f ( O( But f ( o( sice the limit does ot exist 6
Example B Let g ( = ad f ( = ( + si( 3g ( f ( g ( Sice ( + si( 3 for all, we have f (, but f ( = + si( whose limit does ot exist Exercise Fid fuctios f ( ad g ( such that f ( Ω(, but exist (eve i the sese of beig ifiite), so that f ( ω( f ( lim g ( ) does ot The precedig limit theorems ad couter-examples ca be summarized i the followig diagram f ( Here L deotes the limit L = lim, if it exists g ( ) O ( Ω ( Θ ( o ( ω ( L = < L < L = Ex A Ex B I spite of the above couter-examples, the precedig limit theorems are a very useful tool for establishig asymptotic comparisos betwee fuctios For istace recall the earlier exercise to b b show ( + a) ) for real umbers a, ad b with b > The result follows immediately from sice << b ( + a) lim = lim = = + a b, b 7 b
Exercise Use limits to prove the followig: a l ) (here l ) deotes the base logarithm of ) 5 b = ω( ) c If P ( is a polyomial of degree, the P( ) d f ( + o( f ( f ( (Oe ca always disregard lower order terms) ε e (log ) for ay > ad ε > (Polyomials grow faster tha logs) ε f b ) for ay ε > ad b > (Expoetials grow faster tha polyomials) There is a aalogy betwee the asymptotic compariso of fuctios f ( ad g (, ad the compariso of real umbers x ad y f ( ~ x y f ( ~ x = y f ( ~ x y f ( ~ x < y f ( = ω( ~ x > y Note however that this aalogy is ot exact sice there exist pairs of fuctios which are ot comparable, while ay two real umbers are comparable (See problem 3-c, p58) 8