Growth of Functions 16
Learning Objectives Understand the meaning of growth of functions. Measure the growth of the running time of an algorithm. Use the Big-Oh notation to compare the growth of two functions. 17
Growth of Functions g(n) f(n) 1 2 3 4 5 6 7 8 9 10 18
O -notation โ๐ > 0 , ๐ 0 > 0 0 โค ๐ ๐ โค ๐๐ ๐ ๐ โฅ ๐ 0 g(n) is an asymptotic upper- bound for f(n) 19
ฮฉ -notation โ๐ > 0, ๐ 0 > 0 0 โค ๐๐ ๐ โค ๐ ๐ ๐ โฅ ๐ 0 g(n) is an asymptotic lower- bound for f(n) 20
ฮ -notation โ๐ 1 , ๐ 2 > 0, ๐ 0 > 0 0 โค ๐ 1 ๐ ๐ โค ๐ ๐ โค ๐ 2 ๐(๐) ๐ โฅ ๐ 0 g(n) is an asymptotic tight- bound for f(n) 21
o-notation โ๐ > 0 โ๐ 0 > 0 0 โค ๐ ๐ โค ๐๐ ๐ ๐ โฅ ๐ 0 g(n) is a non-tight ๐ ๐ = ๐(๐ ๐ ) asymptotic upper- bound for f(n) 22
ฯ -notation โ๐ > 0 โ๐ 0 > 0 0 โค ๐๐ ๐ โค ๐ ๐ ๐ โฅ ๐ 0 g(n) is a non-tight asymptotic lower- bound for f(n) ๐ ๐ = ๐(๐ ๐ ) 23
Analogy to real numbers Functions Real numbers ๐ โค ๐ ๐ ๐ = ๐ท ๐ ๐ ๐ โฅ ๐ ๐ ๐ = ฮฉ ๐ ๐ ๐ = ๐ ๐ ๐ = ฮ ๐ ๐ ๐ < ๐ ๐ ๐ = o ๐ ๐ ๐ > ๐ ๐ ๐ = ฯ ๐ ๐ 24
Standard Classes of Functions ๐ ๐ = ฮ 1 Constant: Logarithmic: ๐ ๐ = ฮ(lg ๐ ) ๐ ๐ = ๐(๐) Sublinear: ๐ ๐ = ฮ ๐ Linear: Super-linear: ๐ ๐ = ๐(๐) ๐ ๐ = ฮ(๐ 2 ) Quadratic: ๐ ๐ = ฮ(๐ ๐ ) ; k is a constant Polynomial: Exponential: ๐ ๐ = ฮ(๐ ๐ ) ; k is a constant 25
Insertion Sort (Revisit) n-times j-times ฮ(๐ 2 ) 26
Using L'Hopitalโs rule Determine the relative growth rates by using L'Hopital's rule f ( N ) compute lim ๏ฎ ๏ฅ g ( N ) n if 0: f(N) = o(g(N)) if constant ๏น 0: f(N) = ๏ (g(N)) if ๏ฅ : g(N) = o(f(N)) limit oscillates: no relation
Recursion In math: A function is defined based on itself Factorial: ๐! = (๐ โ 1)! โ ๐ , 0! = 1 Fibonacci: ๐บ(๐) = ๐บ(๐ โ 1) + ๐บ(๐ โ 2) , ๐บ(0) = ๐บ(1) = 1 In programming: A function calls itself int fib(int number) { if (number == 0) return 0; if (number == 1) return 1; return fib(number-1) + fib(number-2); } Question: Who is the recursionโs worst enemy? 28
Function calls main() { F1(โฆ); } F3 F1(โฆ) { F2(โฆ); F2 } F2(โฆ) { Other things you do not want to know F3(โฆ); F1 } Local variables Stack 29
Recommend
More recommend