This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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: simplesimon: ≈ n fullsimon: ≈ n 2 # guesses for highlowwin 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 BigOh notation Formalizes a notion of “lessthanorequalto” 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
 Winter '10
 cormack
 Algorithms, Determinant, Big O notation, Asymptotic analysis, asymptotic notation

Click to edit the document details