Advanced Algorithms Analysis and Design: by Dr. Nazir Ahmad Zafar
Advanced Algorithms Analysis and Design: by Dr. Nazir Ahmad Zafar
and Design
By
f(n) O(g(n))
Since
f(n) ≤ c.g(n) n2 ≤ c.n2 1 ≤ c, take, c = 1, n0= 1
Then
n2 ≤ c.n2 for c = 1 and n 1
Hence, 2n2 O(n2), where c = 1 and n0= 1
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Examples
Examples
Example 3: Prove that 1000.n2 + 1000.n O(n2)
Proof:
Assume that f(n) = 1000.n2 + 1000.n, and g(n) = n2
We have to find existence of c and n0 such that
0 ≤ f(n) ≤ c.g(n) n n0
1000.n2 + 1000.n ≤ c.n2 = 1001.n2, for c = 1001
1000.n2 + 1000.n ≤ 1001.n2
1000.n ≤ n2 n2 1000.n n2 - 1000.n 0
n (n-1000) 0, this true for n 1000
f(n) ≤ c.g(n) n n0 and c = 1001
Intuitively:
Set of all functions whose rate of growth is the same as or higher
than that of g(n).
f(n) (g(n))
Intuitively: Set of all functions that have same rate of growth as g(n).
f(n) (g(n))
n0 2. max(( b / a ), ( c / a ))
Then it can be easily verified that
0 ≤ c1.g(n) ≤ f(n) ≤ c2.g(n),n ≥ n0, c1= ¼.a, c2 = 7/4.a
Since
f(n) < c.g(n) n2 < c.n2 1 ≤ c,
2 2
n n
e.g., n but n ..
2
2 2
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Examples
Examples