Professional Documents
Culture Documents
Algorithms
(CSCE 2202)
n
Prof. Amr Goneid, AUC 4
Rules for Big O
The growth rate of a sum of terms of is the
growth rate of its fastest growing term
O(f(n)) + O(g(n)) = max(O(f(n)) ,O(g(n)))
e.g. f(n) = 2n = O(n), g(n) = 0.1 n3 = O(n3)
T(n) = max(O(n) , O(n3)) = O(n3)
2n
O(n3)
0.1 n3
Claim:
For all n ≥ 1, log n < n.
Prove by induction on n.
Proof:
n b logb n
loga n loga b logb n (loga b )logb n c logb n (logb n )
Proof:
log n k k log n and log b n n log b
Since log n n then
O( n k ) O( b n ) for all k 0 and b 1
n
S ( n) i n( n 1) / 2
i 1
f (n) f '(n )
then lim lim '
n g( n ) n g ( n )
d
where the prime means
dn
Example: Show that
f(n) = n(k+α) + nk (log n)2 and
g(n) = k n(k+α)
grow at the same rate.
12
10 O(n)
x
8
logx
4
O(log2n)
2
0
n
1 2 3 4 5 6 7 8 9 10 11 12 13 14
O(n2)
Log T(n)
O(n)
O(2n)
Log T(n)
O(n3)
O(n)
n
Amsterdam NY M ontreal
O(nn)
Log T(n)
O(n!)
O(2n)
NP (Non-Polynomial) Times:
O(2n) , O(en) , O(n!) , O(nn) , …..
Intractable Algorithms
Prof. Amr Goneid, AUC 29
P and NP – Times
Polynomial time is
GOOD
Try to reduce the polynomial
power
NP (e.g. Exponential) Time is
BAD
Prof. Amr Goneid, AUC 30