Data Structures CSCI 262, Spring 2002 Lecture 2 Classes and

advertisement
Data Structures
CSCI 132, Spring 2014
Lecture 26
Asymptotic Analysis II
1
Big-Oh Notation
f(n) is
Say:
Meaning
limn f(n)/g(n)
o(g(n))
little-oh of g(n)
<
0
O(g(n))
Big-oh of g(n)
<=
finite
Q(g(n))
Big-theta of g(n)
=
non-zero, finite
W(g(n))
Big-omega of g(n)
>=
non-zero
w(g(n))
little-omega of g(n)
>
infinite
2
Relationships between
O,o,Q,W,w
is a subset of
w (g)  W(g)
w(g)
W(g)
bigger
growth of f
Q(g)

smaller
growth of
f
O(g)
o(g)
o(g)  O(g)
3
It follows that:
if f = w(g) then f = W(g)
if f = o(g) then f = O(g)
Symmetric relationships:
f = w(g) if and only if g = o(f)
f = W(g) if and only if g = O(f)
f = Q(g) if and only if g = Q(f)
4
Rules For O-notation
•If f(n) is a polynomial of degree r, then f(n) = Q(nr)
•If r < s, then nr is o(ns)
•If a > 1, b> 1 then loga(n) is Q(logb(n))
•loga(n) is o(nr) for r > 0, real valued a
•nr is o(an) for a >1, real valued r
•If 0 <= a < b then an is o(bn)
5
Hints for comparing functions
1) When comparing functions, first look for the dominant term
in each function. You can ignore lower order terms.
E.g. f(n) = 3lg(n) + 20n + n2
Dominant term = ?
2) It may be easier to compare the functions to a known function
to find the relative rates of growth.
E.g. Compare f1 (n)  n lg n with f 2 (n)  n
3) When in doubt, graph the functions. This will give you an idea of
which grows faster. (However you must support your answer by
finding the limit of f/g).
6
Examples
Compare the following pairs of functions:
1.
f(n) = 5n6 + n2 - 2
g(n) = 100 n4 - 3n2 + 5n + 7
2.
f(n) = 3 log (n)
g(n) = n2 - 7n + 2
3.
f(n) = 100 log(n) + 1000
g(n) = log2(n)
4.
f(n) = n2 + 3n - log n
g(n) = 5n2
7
Useful Exponential facts
an = product of n copies of a
a-n = 1/an
Key identities:
a0 = 1
aman = am+n
(am)n = amn
Examples:
(22)3 = ?
2223 = ?
253/2 = ?
8
Useful logarithm facts
logba = x, the power to which b must be raised to equal a
bx = a
Example: log28 = 3, because 23 = 8
Logarithm facts:
logb(1/a) = -logb(a)
logc(ab) = logc(a) + logc(b)
Special case: logc(an) = nlogc(a)
logc(1) = 0
clogc(b) = b = logc(cb)
logc(a) = logc(b) logb(a)
9

Useful derivative facts
1. Derivatives of polynomials
f (x)  ax r
f '(x)  rax r1
2. Derivatives of logarithms
f (x)  ln(x)  log e (x)
1 
f '(x)   
x 
g(x)  lg( x)  log 2 (x)  log 2 e log e x  c log e x
1 
g '(x)  c 
x 
10
More Derivative facts
Chain rule example:
f (x)  (lg x) 3
f '(x)  ?
3. Chain rule:
f (x)  u(v(x))
f '(x)  u '(v(x))v '(x)
u(x)  x 3
v(x)  lg x

f '(x)  3(lg x) 2 (lg( e) / x)
4. Multiplying functions
( f (x)g(x)) ' f '(x)g(x)  g '(x) f (x)

Example: f (x)  x lg x
f '(x)  ?
lg e 

f '(x)  lg x  x  lg x  lg e
 x 
11
More Examples
Compare the following functions:
5) f(n) = lg(lg(n))
g(n) = lg(n)
6) f(n) = lg(n)
g(n) = n0.5
7) f(n) = lg3(n) = (lg(n))3
g(n) = n0.5
12
Download