Download presentation
Presentation is loading. Please wait.
Published byRandell Kelley Modified over 8 years ago
1
13 February 2016 Asymptotic Notation, Review of Functions & Summations
2
asymp - 1 Asymptotic Complexity Running time of an algorithm as a function of input size n for large n. Expressed using only the highest-order term in the expression for the exact running time. Instead of exact running time, say (n 2 ). Describes behavior of function in the limit. Written using Asymptotic Notation.
3
asymp - 2 Asymptotic Notation , O, , o, Defined for functions over the natural numbers. Ex: f(n) = (n 2 ). Describes how f(n) grows in comparison to n 2. Define a set of functions; in practice used to compare two function sizes. The notations describe different rate-of-growth relations between the defining function and the defined set of functions.
4
asymp - 3 -notation (g(n)) = { f(n) : positive constants c 1, c 2, and n 0, such that n n 0, we have 0 c 1 g(n) f(n) c 2 g(n) } For function g(n), we define (g(n)), big-Theta of n, as the set: g(n) is an asymptotically tight bound for f(n). Intuitively: Set of all functions that have the same rate of growth as g(n).
5
asymp - 4 -notation (g(n)) = { f(n) : positive constants c 1, c 2, and n 0, such that n n 0, we have 0 c 1 g(n) f(n) c 2 g(n) } For function g(n), we define (g(n)), big-Theta of n, as the set: Technically, f(n) (g(n)). Older usage, f(n) = (g(n)). I’ll accept either… f(n) and g(n) are nonnegative, for large n.
6
asymp - 5 Example 10n 2 - 3n = (n 2 ) What constants for n 0, c 1, and c 2 will work? Make c 1 a little smaller than the leading coefficient, and c 2 a little bigger. To compare orders of growth, look at the leading term. Exercise: Prove that n 2 /2-3n= (n 2 ) (g(n)) = { f(n) : positive constants c 1, c 2, and n 0, such that n n 0, 0 c 1 g(n) f(n) c 2 g(n) }
7
asymp - 6 Example Is 3n 3 (n 4 ) ?? How about 2 2n (2 n )?? (g(n)) = { f(n) : positive constants c 1, c 2, and n 0, such that n n 0, 0 c 1 g(n) f(n) c 2 g(n) }
8
asymp - 7 O-notation O(g(n)) = { f(n) : positive constants c and n 0, such that n n 0, we have 0 f(n) cg(n) } For function g(n), we define O(g(n)), big-O of n, as the set: g(n) is an asymptotic upper bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or lower than that of g(n). f(n) = (g(n)) f(n) = O(g(n)). (g(n)) O(g(n)).
9
asymp - 8 Examples Any linear function an + b is in O(n 2 ). How? Show that 3n 3 =O(n 4 ) for appropriate c and n 0. O(g(n)) = {f(n) : positive constants c and n 0, such that n n 0, we have 0 f(n) cg(n) }
10
asymp - 9 -notation g(n) is an asymptotic lower bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). f(n) = (g(n)) f(n) = (g(n)). (g(n)) (g(n)). (g(n)) = { f(n) : positive constants c and n 0, such that n n 0, we have 0 cg(n) f(n) } For function g(n), we define (g(n)), big-Omega of n, as the set:
11
asymp - 10 Example n = (lg n). Choose c and n 0. (g(n)) = {f(n) : positive constants c and n 0, such that n n 0, we have 0 cg(n) f(n)}
12
asymp - 11 Relations Between , O,
13
asymp - 12 Relations Between , , O I.e., (g(n)) = O(g(n)) (g(n)) In practice, asymptotically tight bounds are obtained from asymptotic upper and lower bounds. Theorem : For any two functions g(n) and f(n), f(n) = (g(n)) iff f(n) = O(g(n)) and f(n) = (g(n)). Theorem : For any two functions g(n) and f(n), f(n) = (g(n)) iff f(n) = O(g(n)) and f(n) = (g(n)).
14
asymp - 13 Running Times “Running time is O(f(n))” Worst case is O(f(n)) O(f(n)) bound on the worst-case running time O(f(n)) bound on the running time of every input. (f(n)) bound on the worst-case running time (f(n)) bound on the running time of every input. “Running time is (f(n))” Best case is (f(n)) Can still say “Worst-case running time is (f(n))” Means worst-case running time is given by some unspecified function g(n) (f(n)).
15
asymp - 14 Example Insertion sort takes (n 2 ) in the worst case, so sorting (as a problem) is O(n 2 ). Why? Any sort algorithm must look at each item, so sorting is (n). In fact, using (e.g.) merge sort, sorting is (n lg n) in the worst case. Later, we will prove that we cannot hope that any comparison sort to do better in the worst case.
16
asymp - 15 Asymptotic Notation in Equations Can use asymptotic notation in equations to replace expressions containing lower-order terms. For example, 4n 3 + 3n 2 + 2n + 1 = 4n 3 + 3n 2 + (n) = 4n 3 + (n 2 ) = (n 3 ). How to interpret? In equations, (f(n)) always stands for an anonymous function g(n) (f(n)) In the example above, (n 2 ) stands for 3n 2 + 2n + 1.
17
asymp - 16 o-notation f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n g(n) is an upper bound for f(n) that is not asymptotically tight. Observe the difference in this definition from previous ones. Why? o(g(n)) = {f(n): c > 0, n 0 > 0 such that n n 0, we have 0 f(n) < cg(n)}. For a given function g(n), the set little-o:
18
asymp - 17 (g(n)) = {f(n): c > 0, n 0 > 0 such that n n 0, we have 0 cg(n) < f(n)}. -notation f(n) becomes arbitrarily large relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = . n g(n) is a lower bound for f(n) that is not asymptotically tight. For a given function g(n), the set little-omega:
19
asymp - 18 Comparison of Functions f g a b f (n) = O(g(n)) a b f (n) = (g(n)) a b f (n) = (g(n)) a = b f (n) = o(g(n)) a < b f (n) = (g(n)) a > b
20
asymp - 19 Limits lim [f(n) / g(n)] = 0 f(n) (g(n)) n lim [f(n) / g(n)] < f(n) (g(n)) n 0 < lim [f(n) / g(n)] < f(n) (g(n)) n 0 < lim [f(n) / g(n)] f(n) (g(n)) n lim [f(n) / g(n)] = f(n) (g(n)) n lim [f(n) / g(n)] undefined can’t say n
21
asymp - 20 Properties Transitivity f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) f(n) = O(g(n)) & g(n) = O(h(n)) f(n) = O(h(n)) f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) f(n) = o (g(n)) & g(n) = o (h(n)) f(n) = o (h(n)) f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) Reflexivity f(n) = (f(n)) f(n) = O(f(n)) f(n) = (f(n))
22
asymp - 21 Properties Symmetry f(n) = (g(n)) iff g(n) = (f(n)) Complementarity f(n) = O(g(n)) iff g(n) = (f(n)) f(n) = o(g(n)) iff g(n) = ((f(n))
23
13 February 2016 Common Functions
24
asymp - 23 Monotonicity f(n) is monotonically increasing if m n f(m) f(n). monotonically decreasing if m n f(m) f(n). strictly increasing if m < n f(m) < f(n). strictly decreasing if m > n f(m) > f(n).
25
asymp - 24 Exponentials Useful Identities: Exponentials and polynomials
26
asymp - 25 Logarithms x = log b a is the exponent for a = b x. Natural log: ln a = log e a Binary log: lg a = log 2 a lg 2 a = (lg a) 2 lg lg a = lg (lg a)
27
asymp - 26 Logarithms and exponentials – Bases If the base of a logarithm is changed from one constant to another, the value is altered by a constant factor. Ex: log 10 n * log 2 10 = log 2 n. Base of logarithm is not an issue in asymptotic notation. Exponentials with different bases differ by a exponential factor (not a constant factor). Ex: 2 n = (2/3) n *3 n.
28
asymp - 27 Polylogarithms For a 0, b > 0, lim n ( lg a n / n b ) = 0, so lg a n = o(n b ), and n b = (lg a n ) Prove using L’Hopital’s rule repeatedly lg(n!) = (n lg n) Prove using Stirling’s approximation (in the text) for lg(n!).
29
asymp - 28 Exercise Express functions in A in asymptotic notation using functions in B. A B 5n 2 + 100n 3n 2 + 2 A (n 2 ), n 2 (B) A (B) log 3 (n 2 ) log 2 (n 3 ) log b a = log c a / log c b; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3) n lg4 3 lg n a log b = b log a ; B =3 lg n =n lg 3 ; A/B =n lg(4/3) as n lg 2 n n 1/2 lim ( lg a n / n b ) = 0 (here a = 2 and b = 1/2) A (B) n A (B) A (B) A (B)
30
asymp - 29 THETOPPERSWAY.COM
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.