growth of functions
play

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)


  1. Growth of Functions 16

  2. 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

  3. Growth of Functions g(n) f(n) 1 2 3 4 5 6 7 8 9 10 18

  4. O -notation โˆƒ๐‘‘ > 0 , ๐‘œ 0 > 0 0 โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘๐‘• ๐‘œ ๐‘œ โ‰ฅ ๐‘œ 0 g(n) is an asymptotic upper- bound for f(n) 19

  5. ฮฉ -notation โˆƒ๐‘‘ > 0, ๐‘œ 0 > 0 0 โ‰ค ๐‘‘๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ ๐‘œ โ‰ฅ ๐‘œ 0 g(n) is an asymptotic lower- bound for f(n) 20

  6. ฮ˜ -notation โˆƒ๐‘‘ 1 , ๐‘‘ 2 > 0, ๐‘œ 0 > 0 0 โ‰ค ๐‘‘ 1 ๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘ 2 ๐‘•(๐‘œ) ๐‘œ โ‰ฅ ๐‘œ 0 g(n) is an asymptotic tight- bound for f(n) 21

  7. o-notation โˆ€๐‘‘ > 0 โˆƒ๐‘œ 0 > 0 0 โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘๐‘• ๐‘œ ๐‘œ โ‰ฅ ๐‘œ 0 g(n) is a non-tight ๐‘” ๐‘œ = ๐‘(๐‘• ๐‘œ ) asymptotic upper- bound for f(n) 22

  8. ฯ‰ -notation โˆ€๐‘‘ > 0 โˆƒ๐‘œ 0 > 0 0 โ‰ค ๐‘‘๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ ๐‘œ โ‰ฅ ๐‘œ 0 g(n) is a non-tight asymptotic lower- bound for f(n) ๐‘” ๐‘œ = ๐œ•(๐‘• ๐‘œ ) 23

  9. Analogy to real numbers Functions Real numbers ๐‘ โ‰ค ๐‘ ๐’ˆ ๐’ = ๐‘ท ๐’‰ ๐’ ๐‘ โ‰ฅ ๐‘ ๐’ˆ ๐’ = ฮฉ ๐’‰ ๐’ ๐‘ = ๐‘ ๐’ˆ ๐’ = ฮ˜ ๐’‰ ๐’ ๐‘ < ๐‘ ๐’ˆ ๐’ = o ๐’‰ ๐’ ๐‘ > ๐‘ ๐’ˆ ๐’ = ฯ‰ ๐’‰ ๐’ 24

  10. 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

  11. Insertion Sort (Revisit) n-times j-times ฮ˜(๐‘œ 2 ) 26

  12. 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

  13. 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

  14. 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