1.1.1 Dsa
1.1.1 Dsa
Asymptotic
Asymptotic Notation
Notation
(g(n)) = {f(n) :
positive constants c1, c2, and n0,
such that n n0,
we have 0 c1g(n) f(n) c2g(n)
}
Intuitively: Set of all functions that
have the same rate of growth as g(n).
g(n) is an asymptotically tight bound for f(n).
-notation
For function g(n), we define (g(n)),
big-Theta of n, as the set:
(g(n)) = {f(n) :
positive constants c1, c2, and n0,
such that n n0,
we have 0 c1g(n) f(n) c2g(n)
}
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.
Exercise
Express functions in A in asymptotic notation using functions in B.
A B
A (B)
1. 5n2 + 100n 3n2 + 2
A (n2), n2 (B) A (B)
2. log3(n2) log2(n3) A (B)
logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3)
A (B)
3. nlg4 3lg n
alog b = blog a; B =3lg n=nlg 3; A/B =nlg(4/3) as n
4. lg2n n1/2 A o (B)
lim ( lga n / nb ) = 0 (here a = 2 and b = 1/2) A o (B)
n
Example
(g(n)) = {f(n) : positive constants c1, c2, and n0, such
that n n0, 0 c1g(n) f(n) c2g(n)}
What constants for n0, c1, and c2 will work?
10n2 - 3n = Q(n2)
Make c1 a little smaller than the leading coefficient, and c2 a little bigger.
To compare orders of growth, look at the leading term.
O(g(n)) = {f(n) :
positive constants c and n0, such
that n n0,
we have 0 f(n) cg(n) }
Intuitively: Set of all functions whose rate of
growth is the same as or lower than that of g(n).
g(n) is an asymptotic upper bound for f(n).
f(n) = (g(n)) f(n) = O(g(n)).
(g(n)) O(g(n)).
Examples
(g(n)) = {f(n) :
positive constants c and
n0, such that n n0,
we have 0 cg(n) f(n)}
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) = w (g(n)) a > b
Limits
lim [f(n) / g(n)] = 0 Þ f(n) Î o(g(n))
n
Reflexivity
f(n) = (f(n))
f(n) = O(f(n))
f(n) = (f(n))
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) = w((f(n))
Practice Question
Common Functions :
Important Theorems
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).
◦ Monotonically increasing means when a function is said to be monotonically increasing if its graph is
only increasing with increasing values of the equation.
◦ If f′(x)>0 for all x in the interval, then the function f is strictly increasing. If f′(x)<0 for all x in the interval,
then the function f is strictly decreasing.
Exponentials
Useful Identities:
1
a 1
a
( a m ) n a mn
a m a n a m n
Exponentials and polynomials
nb
lim n 0
n a
n b o( a n )
Logarithms a b log b a
log c ( ab) log c a log c b
x = logba is the
exponent for a = bx. log b a n n log b a
log c a
log b a
Natural log: ln a = log a e log c b
Binary log: lg a = log a2 log b (1 / a ) log b a
1
lg a = (lg a)
2 2 log b a
lg lg a = lg (lg a)
log a b
a log b c c log b a
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: log10 n * log210 = log2 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: 2n = (2/3)n*3n.
Polylogarithms
lg(n!) = (n lg n)