Professional Documents
Culture Documents
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
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))
( ) lim
e.g., 2n = o n but 2n ≠ o n .. n →∞ g (n )
2 2 2 = 0( )
g(n) is an upper bound for f(n), not asymptotically tight
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Examples
Examples
Example 1: Prove that 2n2 ∈ o(n3)
Proof:
Assume that f(n) = 2n2 , and g(n) = n3
f(n) ∈ o(g(n)) ?
Since
f(n) < c.g(n) n2 < c.n2 1 ≤ c,
( )
2 2
= ω (n ) but
n n
e.g., ≠ ω n ..
2
2 2
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Examples
Examples
Example 1: Prove that 5.n2 ∈ ω(n)
Proof:
Assume that f(n) = 5.n2 , and g(n) = n
f(n) ∈ Ω(g(n)) ?
We have to prove that for any c there exists n0 s.t.,
c.g(n) < f(n) n ≥ n0
c.n < 5.n2 c < 5.n
This is true for any c, because for any arbitrary c
e.g. c = 1000000, we can choose n0 = 1000000/5
= 200000 and the above inequality does hold.
And hence f(n) ∈ ω(g(n)),
Therefore
1. f(n) ≠ o(f(n)) and
2. f(n) ≠ ω(f(n))
Note :
Hence small o and small omega are not reflexive relations
Note
It is to be noted that all these algorithms complexity
measuring notations are in fact relations which satisfy
the transitive property.
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Transitivity Relation over Θ
Property 1
f(n) = Θ(g(n)) & g(n) = Θ(h(n)) ⇒ f(n) = Θ(h(n))
Proof
1. Since f(n) = Θ(g(n)) i.e. f(n) ∈ Θ(g(n)) ⇒
∃ constants c1, c2 > 0 and n01 ∈ N such that
0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) ∀ n ≥ n01 (1)
2. Now since g(n) = Θ(h(n)) i.e. g(n) ∈ Θ(h(n)) ⇒
∃ constants c3, c4 > 0 and n02 ∈ N such that
0 ≤ c3h(n) ≤ g(n) ≤ c4h(n) ∀ n ≥ n02 (2)
3. Now let us suppose that n0 = max (n01, n02)
Property 2
f(n) = O(g(n)) & g(n) = O(h(n)) ⇒ f(n) = O(h(n))
Proof
1. Since f(n) = O(g(n)) i.e. f(n) ∈ O(g(n)) ⇒
∃ constants c1 > 0 and n01 ∈ N such that
0 ≤ f(n) ≤ c1g(n) ∀ n ≥ n01 (1)
2. Now since g(n) = O(h(n)) i.e. g(n) ∈ O(h(n)) ⇒
∃ constants c2 > 0 and n02 ∈ N such that
0 ≤ g(n) ≤ c2h(n) ∀ n ≥ n02 (2)
3. Now let us suppose that n0 = max (n01, n02)
Property 3
f(n) = Ω(g(n)) & g(n) = Ω(h(n)) ⇒ f(n) = Ω(h(n))
Proof
1. Since f(n) = Ω(g(n)) ⇒
∃ constants c1 > 0 and n01 ∈ N such that
0 ≤ c1g(n) ≤ f(n) ∀ n ≥ n01 (1)
2. Now since g(n) = Ω(h(n)) ⇒
∃ constants c2 > 0 and n02 ∈ N such that
0 ≤ c2h(n) ≤ g(n) ∀ n ≥ n02 (2)
3. Suppose that n0 = max (n01, n02)
Property 4
f(n) = o(g(n)) & g(n) = o(h(n)) ⇒ f(n) = o(h(n))
Proof
• Since f(n) = o(g(n)) i.e. f(n) ∈ o(g(n)) ⇒
∃ constants c1 > 0 and n01 ∈ N such that
0 ≤ f(n) < c1g(n) ∀ n ≥ n01 (1)
2. Now since g(n) = o(h(n)) i.e. g(n) ∈ o(h(n)) ⇒
∃ constants c2 > 0 and n02 ∈ N such that
0 ≤ g(n) < c2h(n) ∀ n ≥ n02 (2)
3. Now let us suppose that n0 = max (n01, n02)
Property 5
f(n) = ω(g(n)) & g(n) = ω(h(n)) ⇒ f(n) = ω(h(n))
Proof
• Since f(n) = ω(g(n)) ⇒
∃ constants c1 > 0 and n01 ∈ N such that
0 ≤ c1g(n) < f(n) ∀ n ≥ n01 (1)
2. Now since g(n) = ω(h(n)) ⇒
∃ constants c2 > 0 and n02 ∈ N such that
0 ≤ c2h(n) < g(n) ∀ n ≥ n02 (2)
3. Suppose that n0 = max (n01, n02)