08-asymptotic_notation

08-asymptotic_notation - Computer Science 136 David R...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Science 136: David R. Cheriton School of Computer Science Elementary Algorithm Design and Data Abstraction Winter 2012 Lecture 8 – Asymptotic Notation We look at asymptotic notation for analyzing algorithms. This provides a tool for comparing the cost functions of algorithms (or any functions for that matter). We look at how to determine and to simplify these cost functions. CS 136 – Winter 2012 08 – Asymptotic Notation 1/1 Topics from Last Time Counting # presses in terms of game size for: simple-simon: ≈ n full-simon: ≈ n 2 # guesses for high-low-win guessing game: Dumb strategy: ≈ n Smart strategy: ≈ log n # “steps” for (len l ), list of length n : 8 n + 3 “Shorthand” hides constant factors, constant terms: O ( n ) Sneak peak: O ( n 2 ) hides constant factors, linear terms, constant terms CS 136 – Winter 2012 08 – Asymptotic Notation 2/1 Asymptotic Notation Also known as Order Notation or Big-Oh notation Formalizes a notion of “less-than-or-equal-to” for functions O ( g ( n )) is the set of functions whose “order” is equal to or less than that of g ( n ) “Order” captures of “how fast does g grow when n is large?”, ignoring constant factors CS 136 – Winter 2012 08 – Asymptotic Notation 3/1 Asymptotic Notation (2) Let f ( n ) , g ( n ) be functions from N to N (i.e., consume a positive number and produce a positive number). In increasing levels formality: f ( n ) ∈ O ( g ( n )) if for large enough n , f ( n ) grows no faster than g ( n ) if we ignore constant factors and “unimportant” (lower order) terms f ( n ) ∈ O ( g ( n )) if I can pick a constant c so that no matter how big n is, c · g ( n ) bigger than f ( n ) f ( n ) ∈ O ( g ( n )) if there exist positive constants c and n such that for all n > n we have f ( n ) 6 c · g ( n ) CS 136 – Winter 2012 08 – Asymptotic Notation 4/1 Showing f ( n ) ∈ O ( g ( n )) Suppose that f ( n ) , g ( n ) are functions from N → N . Want to establish that f ( n ) ∈ O ( g ( n )) Start with hypothesis n = , inequality f ( n ) 6 c · g ( n ) Simplify algebraically until you get simplefunction ( n ) 6 c , (possibly increasing n as you go to make life easier). Choose c to satisfy simplefunction ( n ) 6 c , choose n to be the n you ended up with. To prove , state your c and n and run the steps in reverse, i.e. Assume n = thing , c = otherthing and work backwards to get f ( n ) 6 c · g ( n ) for all n > n . Read the handout on order notation . CS 136 – Winter 2012 08 – Asymptotic Notation 5/1 Examples f ( n ) ∈ O ( g ( n )) if I can pick a constant c so that no matter how big n is, c · g ( n ) bigger than f ( n ) f ( n ) ∈ O ( g ( n )) if there exist constants c , n such that for all n > n we have f ( n ) 6 c · g ( n ) Is 2 n ∈ O ( 3 n ) ? Yes. c = 1 , n = Is 3 n ∈ O ( 2 n ) ? Yes. c = 2 , n = If f ( n ) ∈ O ( g ( n )) and g ( n ) ∈ O ( f ( n )) , we say f and g are of “the same order.” [Aside: We write f ( n ) ∈ Θ...
View Full Document

{[ snackBarMessage ]}

Page1 / 24

08-asymptotic_notation - Computer Science 136 David R...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online