الگوریتم 2
CHAPTER 2: GROWTH OF FUNCTIONS
2.1 Asymptotic notation
-notation
(g(n)) = {â(n) : there exist positive constants c1, c2, and n0 such that
0
c1g(n)
â(n)
c2g(n) for all n
n0}.
for all n
n0. Dividing by n2 yields
Figure 2.1 Graphic examples of the
, O, and
notations. In each part, the value of n0 shown is the minimum possible value; any greater value would also work. (a)
-notation bounds a function to within constant factors. We write
(n) =
(g(n)) if there exist positive constants n0, c1, and c2 such that to the right of n0, the value of â(n) always lies between c1g(n) and c2g(n)
inclusive. (b) O-notation gives an upper bound for a function to within
a constant factor. We write â(n) = O(g(n)) if there are positive
constants n0 and c such that to the right of n0, the value of â(n) always lies on or below cg(n). (c)
-notation gives a lower bound for a function to within a constant factor. We write â(n) =
(g(n)) if there are positive constants n0 and c such that to the right of n0, the value of â(n) always lies on or above cg(n).
O-notation
O(g(n)) = {â(n) : there exist positive constants c and n0 such that
-notation
(g(n)) = {f(n): there exist positive constants c and n0 such that
For any two functions f(n) and g(n), f(n) =
(g(n)) if and only if f(n) = O(g(n)) and f(n) =
(g(n)).
Asymptotic notation in equations
T(n) = 2T(n/2) +(n).
In some cases, asymptotic notation appears on the left-hand side of an equation, as in
2n2 +(n) =
(n2).
A number of such relationships can be chained together, as in
2n2 + 3n + 1 = 2n2 +(n)
=(n2).
o-notation
o(g(n)) = {
(n): for any positive constant c > 0, there exists a constant
n0 > 0 such that 0
f(n) < cg(n) for all n
n0}.
For example, 2n = o(n2), but 2n2
o(n2).
(2.1)
-notation
(n)
![]()
(g(n)) if and only if g(n)
o(
(n)).
Formally, however, we define
(g(n)) ("little-omega of g of n") as the set
(g(n)) = {
(n): for any positive constant c > 0, there exists a constant
n0 > 0 such that 0
cg(n) <
(n) for all n
n0}.
For example, n2/2 =
(n), but n2/2
(n2). The relation
(n) =
(g(n)) implies that
Comparison of functions
â(n) =(g(n)) and g(n) =
(h(n)) imply â(n) =
(h(n)),
â(n) = O(g(n)) and g(n) = O(h(n)) imply â(n) = O(h(n)),
â(n) =(g(n)) and g(n) =
(h(n)) imply â(n) =
(h(n)),
â(n) = o(g(n)) and g(n) = o(h(n)) imply â(n) = o(h(n)),
â(n) =(g(n)) and g(n) =
(h(n)) imply â(n) =
(h(n)).
â(n) =(â(n)),
â(n) = O(â(n)),
â(n) =(â(n)),
â(n) =(g(n)) if and only if g(n) =
(â(n)).
(n) = O(g(n)) if and only if g(n) =
(f(n)),
(n) = o(g(n)) if and only if g(n) =
(
(n)).
(n) = O(g(n))
a
b,
(n) =
(g(n))
a
b,
(n) =
(g(n))
a = b,
(n) = o(g(n))
a < b,
(n) =
(g(n))
a > b.
One property of real numbers, however, does not carry over to asymptotic notation:
Exercises
Show that for any real constants a and b, where b > 0,
(n + a)b =(nb) .
(2.2)
Explain why the statement, "The running time of algorithm A is at least O(n2)," is content-free.
Is 2n+1 = O(2n)? Is 22n = O(2n)?
Prove that o(g(n))
(g(n)) is the empty set.
O(g(n, m)) = {
(n,m): there exist positive constants c, n0, and m0
Give corresponding definitions for
(g(n, m)) and
(g(n, m)).
2.2 Standard notations and common functions
Monotonicity
Floors and ceilings
x - 1 <x
![]()
x
![]()
x
< x +1.
n/2
+
n/2
= n,
and for any integer n and integers a
0 and b
0,
n/a
/b
=
n/ab
(2.3)
n/a
/b
=
n/ab
.
(2.4)
The floor and ceiling functions are monotonically increasing.
Polynomials
Given a positive integer d, a polynomial in n of degree d is a function p(n) of the form
Exponentials
For all real a
0, m, and n, we have the following identities:
a0 = 1,
a1 = a,
a-1 = 1/a,
(am)n = amn,
(am)n = (an)m,
aman = am+n.
(2.5)
from which we can conclude that
nb = 0(an).
Thus, any positive exponential function grows faster than any polynomial.
Using e to denote 2.71828 . . ., the base of the natural logarithm function, we have for all real x,
(2.6)
ex1 + x,
(2.7)
where equality holds only when x = 0. When |x|
1, we have the approximation
1 + xex
l + x +x2 .
(2.8)
When x
0, the approximation of ex by 1 + x is quite good:
ex = 1 + x +(x2).
Logarithms
We shall use the following notations:
lg n = log2 n (binary logarithm),
ln n = loge n (natural logarithm),
lgk n = (lg n)k (exponentiation),
lg lg n = lg(lg n) (composition).
For all real a > 0, b > 0, c > 0, and n,
(2.9)
There is a simple series expansion for ln(1 + x) when
x
< 1:
We also have the following inequalities for x > -1:
(2.10)
where equality holds only for x = 0.
From this limit, we can conclude that
lgb n = o(na)
Factorials
The notation n! (read "n factorial") is defined for integers n
0 as
(2.11)
n! = o(nn),
n! =(2n),
lg(n!) =(n lg n).
The following bounds also hold for all n:
(2.12)
The iterated logarithm function
The iterated logarithm is a very slowly growing function:
lg* 2 = 1,
lg* 4 = 2,
lg* 16 = 3,
lg* 65536 = 4,
lg*(265536) = 5.
Fibonacci numbers
The Fibonacci numbers are defined by the following recurrence:
F0 = 0,
F1 = 1,
Fi = Fi-1+Fi-2 for i2.
(2.13)
Thus, each Fibonacci number is the sum of the two previous ones, yielding the sequence
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ... .
(2.14)
(2.15)
Exercises
Prove that lg(n!) =
(n lg n) and that n! = o(nn).
Is the function [lg n]! polynomially bounded? Is the function [lg lg n]! polynomially bounded?
Which is asymptotically larger: lg(lg* n) or lg*(lg n)?
Prove that for i
0, the (i + 2)nd Fibonacci number satisfies Fi+2
i.
Problems
2-1 Asymptotic behavior of polynomials
c. If k = d, then p(n) =
(nk).
d. If k > d, then p(n) = o(nk).
e. If k < d, then p(n) =
(nk).
2-2 Relative asymptotic growths
2-3 Ordering by asymptotic growth rates
2-4 Asymptotic notation properties
a. f(n) = O(g(n)) implies g(n) = O(f(n)).
b. f(n) + g(n) =
(min(â(n), g(n))).
d. f(n) = O(g(n)) implies 2f(n) = O(2g(n)).
f. f(n) = O(g(n)) implies g(n) =
(f(n)).
c. What happens to each direction of the "if and only if" in Theorem 2.1 under this new definition?
Some authors define
(read "soft-oh") to mean O with logarithmic factors ignored:
(g(n)) = {f(n): there exist positive constants c, k, and n0 such that
0
f(n)
cg(n)1gk(n) for all n
n0}.
d. Define
in a similar manner. Prove the corresponding analog to Theorem 2.1.
For a given constant c
R, we define the iterated function
by
For each of the following functions f (n) and constants c, give as tight a bound as possible on
(n).
Chapter notes



.
Certainly, other choices for the constants exist, but the important
thing is that some choice exists. Note that these constants depend on
the function
a different function belonging to
. The reader may verify that 0
where the ai are constants and ad > 0, we have p(n) =
-calculus, the parameters to a function are clearly specified: the function n2 could be written as
O(g(n)). Thus, our proof that any quadratic function an2 + bn + c, where a > 0, is in 


a
x
(read "the floor of x") and the least integer greater than or equal to x by
x
(read "the ceiling of x"). For all real x,


.) We have for all x,









, which are given by the following formulas:

< 1, we have
, so that the ith Fibonacci number Fi is equal to
rounded to the nearest integer. Thus, Fibonacci numbers grow exponentially.
where
is its conjugate.


(read "omega infinity") for this alternative definition. We say that
if there exists a positive constant c such that f(n)
(g(n)) or both, whereas this is not true if we use 
instead of 

(n) is the number of iterated applications of the function â required to reduce its argument down to c or less.