Growth of Functions
16
Growth of Functions 16 Learning Objectives Understand the meaning - - PowerPoint PPT Presentation
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)
16
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
1 2 3 4 5 6 7 8 9 10
g(n) f(n)
18
โ๐ > 0,๐0 > 0 0 โค ๐ ๐ โค ๐๐ ๐ ๐ โฅ ๐0
19
โ๐ > 0, ๐0 > 0 0 โค ๐๐ ๐ โค ๐ ๐ ๐ โฅ ๐0
20
โ๐1, ๐2 > 0, ๐0 > 0 0 โค ๐1๐ ๐ โค ๐ ๐ โค ๐2๐(๐) ๐ โฅ ๐0
21
โ๐ > 0 โ๐0 > 0 0 โค ๐ ๐ โค ๐๐ ๐ ๐ โฅ ๐0
22
โ๐ > 0 โ๐0 > 0 0 โค ๐๐ ๐ โค ๐ ๐ ๐ โฅ ๐0
23
24
Constant: ๐ ๐ = ฮ 1 Logarithmic: ๐ ๐ = ฮ(lg ๐ ) Sublinear: ๐ ๐ = ๐(๐) Linear: ๐ ๐ = ฮ ๐ Super-linear: ๐ ๐ = ๐(๐) Quadratic: ๐ ๐ = ฮ(๐2) Polynomial: ๐ ๐ = ฮ(๐๐); k is a constant Exponential: ๐ ๐ = ฮ(๐๐); k is a constant
25
n-times j-times
26
Determine the relative growth rates by using L'Hopital's rule compute if 0: f(N) = o(g(N)) if constant ๏น 0: f(N) = ๏(g(N)) if ๏ฅ: g(N) = o(f(N)) limit oscillates: no relation
) ( ) ( lim N g N f
n ๏ฅ ๏ฎ
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 Question: Who is the recursionโs worst enemy?
int fib(int number) { if (number == 0) return 0; if (number == 1) return 1; return fib(number-1) + fib(number-2); }
28
main() { F1(โฆ); } F1(โฆ) { F2(โฆ); } F2(โฆ) { F3(โฆ); }
Local variables Other things you do not want to know
F1 F2 F3
29