Growth of Functions 16 Learning Objectives Understand the meaning - - PowerPoint PPT Presentation

โ–ถ
growth of functions
SMART_READER_LITE
LIVE PREVIEW

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)


slide-1
SLIDE 1

Growth of Functions

16

slide-2
SLIDE 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

slide-3
SLIDE 3

Growth of Functions

1 2 3 4 5 6 7 8 9 10

g(n) f(n)

18

slide-4
SLIDE 4

O-notation

โˆƒ๐‘‘ > 0,๐‘œ0 > 0 0 โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘๐‘• ๐‘œ ๐‘œ โ‰ฅ ๐‘œ0

g(n) is an asymptotic upper- bound for f(n)

19

slide-5
SLIDE 5

ฮฉ-notation

โˆƒ๐‘‘ > 0, ๐‘œ0 > 0 0 โ‰ค ๐‘‘๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ ๐‘œ โ‰ฅ ๐‘œ0

g(n) is an asymptotic lower- bound for f(n)

20

slide-6
SLIDE 6

ฮ˜-notation

โˆƒ๐‘‘1, ๐‘‘2 > 0, ๐‘œ0 > 0 0 โ‰ค ๐‘‘1๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘2๐‘•(๐‘œ) ๐‘œ โ‰ฅ ๐‘œ0

g(n) is an asymptotic tight- bound for f(n)

21

slide-7
SLIDE 7
  • -notation

โˆ€๐‘‘ > 0 โˆƒ๐‘œ0 > 0 0 โ‰ค ๐‘” ๐‘œ โ‰ค ๐‘‘๐‘• ๐‘œ ๐‘œ โ‰ฅ ๐‘œ0

g(n) is a non-tight asymptotic upper- bound for f(n) ๐‘” ๐‘œ = ๐‘(๐‘• ๐‘œ )

22

slide-8
SLIDE 8

ฯ‰-notation

โˆ€๐‘‘ > 0 โˆƒ๐‘œ0 > 0 0 โ‰ค ๐‘‘๐‘• ๐‘œ โ‰ค ๐‘” ๐‘œ ๐‘œ โ‰ฅ ๐‘œ0

g(n) is a non-tight asymptotic lower- bound for f(n) ๐‘” ๐‘œ = ๐œ•(๐‘• ๐‘œ )

23

slide-9
SLIDE 9

Analogy to real numbers

Functions Real numbers ๐’ˆ ๐’ = ๐‘ท ๐’‰ ๐’ ๐‘ โ‰ค ๐‘ ๐’ˆ ๐’ = ฮฉ ๐’‰ ๐’ ๐‘ โ‰ฅ ๐‘ ๐’ˆ ๐’ = ฮ˜ ๐’‰ ๐’ ๐‘ = ๐‘ ๐’ˆ ๐’ = o ๐’‰ ๐’ ๐‘ < ๐‘ ๐’ˆ ๐’ = ฯ‰ ๐’‰ ๐’ ๐‘ > ๐‘

24

slide-10
SLIDE 10

Standard Classes of Functions

Constant: ๐‘” ๐‘œ = ฮ˜ 1 Logarithmic: ๐‘” ๐‘œ = ฮ˜(lg ๐‘œ ) Sublinear: ๐‘” ๐‘œ = ๐‘(๐‘œ) Linear: ๐‘” ๐‘œ = ฮ˜ ๐‘œ Super-linear: ๐‘” ๐‘œ = ๐œ•(๐‘œ) Quadratic: ๐‘” ๐‘œ = ฮ˜(๐‘œ2) Polynomial: ๐‘” ๐‘œ = ฮ˜(๐‘œ๐‘™); k is a constant Exponential: ๐‘” ๐‘œ = ฮ˜(๐‘™๐‘œ); k is a constant

25

slide-11
SLIDE 11

Insertion Sort (Revisit)

n-times j-times

ฮ˜(๐‘œ2)

26

slide-12
SLIDE 12

Using L'Hopitalโ€™s rule

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 ๏‚ฅ ๏‚ฎ

slide-13
SLIDE 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 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

slide-14
SLIDE 14

Function calls

main() { F1(โ€ฆ); } F1(โ€ฆ) { F2(โ€ฆ); } F2(โ€ฆ) { F3(โ€ฆ); }

Stack

Local variables Other things you do not want to know

F1 F2 F3

29