Professional Documents
Culture Documents
Introduction to Algorithms
Da Nang University of Science and Technology
- notation (theta)
(g(n)) = {f(n) : there exist positive constants c1, c2, and
n0 such that
0 c1 g (n) f (n) c2 g (n) for all n n0}
(g(n)) is the set of functions
f(n) = (g(n)) really means that f(n) belongs to (g(n))
g(n) is called an asymptotically tight bound for f(n)
- notation
- notation
If f(n) is a polynomial of degree d, then f(n) = (nd)
Example:
n2 - 2n = (n2)
200n2 - 100n = (n2)
Some choice for c1, c2, and n0 exists, the functions are (n2)
(n0) ?
Intelligent Networking Laboratory Dang Thien Binh 6/20
- Notation (4/5)
n2 - 2n = (n2)
O - notation (big-oh)
f(n) = O(g(n)): g(n) is an asymptotic upper bound for f(n)
O(g(n)) = {f(n): there exist positive constants c and n0
such that 0 f (n) cg(n) for all n n0 }
f(n) = (g(n)) implies f(n) = O(g(n)),
but f(n) = O(g(n)) does NOT imply f(n) = (g(n))
Example:
n2 - 2n = O(n2)
200n2 - 100n = O(n2) = O(n3) = ...
n = O(n2)
O is good for describing the worst-case running time of an
algorithm
O - notation
- notation (omega)
f(n) = (g(n)): g(n) is an asymptotic lower bound for f(n)
(g(n)) = {f(n): there exist positive constants c and n0 such that 0
0 cg(n) f (n) for all n n0 }
f(n) = (g(n)) implies f(n) = (g(n)),
but f(n) = (g(n)) does NOT imply f(n) = (g(n))
Example:
n2 - 2n = (n2)
200n2 - 100n = (n2) = (n) = (1)
n2 = (n)
is good for describing the best case running time of an
algorithm
Theorem
f(n) = (g(n)) if and only if f(n) = O(g(n)) and f(n) = (g(n))
- notation (omega)
- notation (little-omega)
2n2 = (n2) is asymptotically tight, but 2n3 = (n2) is not
f(n) = (g(n)): g(n) is a lower bound of f(n) that is not
asymptotically tight
(g(n)) = {f(n): for any positive constant c > 0, there exists a
constant n0 > 0 such that 0 cg(n) f (n) for all n n0}
2n2 = (n), but 2n2 (n2)
In the -notation, the function f(n) becomes arbitrarily
large relative to g(n) as n approaches infinity
f ( n)
i.e., lim =
n → g ( n)
Logarithms
𝑙𝑜𝑔𝑏 𝑛: logarithm of n base b
lg 𝑛 = log2 𝑛 (binary logarithm)
ln 𝑛 = 𝑙𝑜𝑔𝑒 𝑛 (natural logarithm, e = 2.7182...)
Factorials
1 𝑖𝑓 𝑛 = 0
𝑛 =ቊ
𝑛 𝑛 − 1 ! 𝑖𝑓 𝑛 > 0
𝑛 = 1 * 2 * 3 * ... * n
𝑛 𝑛𝑛, thus O(𝑛𝑛)
Stirling’s Approximation
𝑛 𝑛 1
𝑛! = 2𝜋𝑛 1+Θ
𝑒 𝑛
From Stirling’s approximation, the followings hold:
𝑛! = 𝒐(𝑛𝑛 )
𝑛! = (2𝑛)
lg(𝑛!) = (𝑛 lg 𝑛)
c. 2 = O(2 )
2n n