Documente Academic
Documente Profesional
Documente Cultură
Asymptotic Notation,
Notation,
Review
Review of
of Functions
Functions &
&
Summations
Summations
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.
Notation
, O, , o,Asymptotic
-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)
}
Intuitively: Set of all functions that
have the same rate of growth as g(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)).
Ill accept either
f(n) and g(n) are nonnegative, for large n.
University Institute of Engineering (UIE)
Example
(g(n)) = {f(n) : positive
constants c1, c2, and n0,
Example
(g(n)) = {f(n) : positive
constants c1, c2, and n0,
Examples
O(g(n)) = {f(n) : positive
constants c and n0,
such that n n0, we have 0 f(n) cg(n) }
Any linear function an + b is in O(n2). How?
Show that 3n3=O(n4) for appropriate c and n0.
-notation
For function g(n), we define (g(n)),
big-Omega of n, as the set:
(g(n)) = {f(n) :
positive constants c and n0,
such that n n0,
we have 0 cg(n) f(n)}
Example
(g(n)) = {f(n) : positive
constants c and n0, such
that n n0, we have 0 cg(n) f(n)}
n = (lg n). Choose c and n0.
Relations Between , O,
Relations
Betweeng(n)
, ,
Of(n),
Theorem
:
For
any
two
functions
and
Theorem : For any two functions g(n) and f(n),
f(n)
f(n) == (g(n))
(g(n)) iff
iff
f(n)
f(n) == O(g(n))
O(g(n)) and
and f(n)
f(n) == (g(n)).
(g(n)).
Running
Running time is O(f(n))
Times
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)).
For example,
4n3 + 3n2 + 2n + 1 = 4n3 + 3n2 + (n)
= 4n3 + (n2) = (n3). How to interpret?
Comparison
f g ofaFunctions
b
f (n) = O(g(n))
f (n) = (g(n))
f (n) = (g(n))
f (n) = o(g(n))
f (n) = (g(n))
a
a
a
a
a
=
<
>
b
b
b
b
b
Transitivity
Reflexivity
f(n) = (f(n))
f(n) = O(f(n))
f(n) = (f(n))
Symmetry
Properties
f(n) = (g(n)) if g(n) = (f(n))
Complementarity
f(n) = O(g(n)) if g(n) = (f(n))
f(n) = o(g(n)) if g(n) = ((f(n))
Common Functions
Monotonicity
f(n) is
Exponentials
Useful Identities:
1
1
a
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 )
University Institute of Engineering (UIE)
Logarithms
a b logb a
x = logba is the
exponent for a = bx. log c ( ab) log c a log c b
n
log b a n log b a
Natural log: ln a = logea
log c a
Binary log: lg a = log2a log b a
log c b
lg a = (lg a)
lg lg a = lg (lg a)
2
log b (1 / a) log b a
1
log b a
log a b
a logb c c logb 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.
Polylogarithms
lg(n!) = (n lg n)
Prove using Stirlings approximation (in the
text) for lg(n!).
5n2 + 100n
3n2 + 2
A (B)
log3(n2)
log2(n3)
A (B)
Summations Review
Why do we Review
need summation
formulas?
on Summations
For computing the running times of iterative
constructs (loops). (CLRS Appendix A)
Example: Maximum Subvector
Given an array A[1n] of numeric values (can be
positive, zero, and negative) determine the
subvector A[ij] (1 i j n) whose sum of elements
is maximum over all subvectors.
-2
Review on Summations
MaxSubvector(A, n)
maxsum 0;
for i 1 to n
do for j = i to n
sum 0
for k i to j
do sum += A[k]
maxsum max(sum, maxsum)
return maxsum
n
T(n) = 1
i=1 j=i k=i
Review on Summations
Constant Series: For integers a and b, a b,
b
1 b a 1
i a
n(n 1)
i 1 2 n
2
i 1
n
i 2 12 22 n 2
i 1
n(n 1)(2n 1)
6
on Summations
Cubic Series:Review
For n 0,
2
2
n
(
n
1
)
3
3
3
3
i
4
i 1
n
x 1
k 0
n
1
x
1 x
k 0
k
Review on Summations
Linear-Geometric Series: For n 0, real c
1,
n 1
(n 1)c nc
ic c 2c nc
2
(
c
1
)
i 1
n
n2
1
ln(n) O (1)
k 1 k
University Institute of Engineering (UIE)
Review on Summations
Telescoping
Series:
n
ak ak 1 an a0
k 1
x
kx
k 0
k
Review on Summations
Approximation by integrals:
For monotonically increasing f(n)
n
m1
n1
k m
f ( x)dx f (k )
f ( x)dx
f ( x)dx f (k ) f ( x)dx
k m
m
m 1
How?
Review on Summations
nth harmonic number
n1
n
1
dx
ln(n 1)
x
k 1 k
1
n
1
dx
ln n
x
k 2 k
1
n
1
ln n 1
k 1 k
Reading Assignment
Chapter 4 of CLRS.