Mathematical Notation - Big Oh, Omega and Theta
Mathematical Notation - Big Oh, Omega and Theta
Algorithm DoSomething(…)
begin
x = f(input size);
for i := 1 to x do
Do_processing(); /* Each execution takes C time*/
end /* DoSomething */
For n = 10
f(10) = 10⁶ x 0.01 = 10⁴ secs
g(10) = 2 x 0.1024 = 0.205 secs
So, g(n) = 2 x 2ⁿ provides better performance than f(n) = 10⁶ x n² for n = 10
For n = 50
f(50) = 10⁶ x 0.25 = 250,000 secs
g(50) = 2 x 35.702 = 71.4 cen
So, f(n) = 10⁶ x n² beat g(n) = 2 x 2ⁿ
even for a small input of n = 50 despite the large constant of 10⁶ in f(n)
*Figure from
Medium.com
(Alejandro Ito
Aramendia)
Points to Note Regarding Big-Oh Notation
● Provides an asymptotic upper bound for the order of growth
○ If g(n) has higher or same order of growth as f(n) than f(n) = O(g(n))
● For example
○ nb = O(na) for a ≥ b
○ lg n = O(na) for a > 0
○ lg n = O(lga n) for a ≥ 1
○ n lg n = O(n2)
*Figure from
geeksforgeeks.org
Points to Note Regarding Big-Omega Notation
● For example
○ nb = Ω(na) for b ≥ a
○ na = Ω(lg n) for a > 0
○ lga n = Ω(lg n) for a ≥ 1
○ n2 = Ω(n lg n)
*Figure from
geeksforgeeks.org
Points to Note Regarding Theta Notation
● For example
○ nb = Θ(na) only for b = a
○ lg n ≠ Θ(na) for any a ∈ R
○ lg n = Θ(lga n) only for a = 1
○ n lg n ≠ Θ(n2)
Example 1
Prove that n2 + 2n + 3 ∈ O(n2)
Proof
So,
⇒ n2 + 2n + 3 ∈ O(n2)
Example 2
Prove that n2 + 4n + 5 ∈ Ω(n2)
Proof
⇒ n2 + 4n + 5 ∈ Ω(n2)