Asymptotic Notations
Asymptotic Notations
NOTATIONS
Understanding Algorithms Efficiency
Team
Asymptotic Notations 2
Asymptotic Notations
Big Oh (O)
Agenda Big Omega (Ω)
Theta (Θ)
Asymptotic Notations 3
Asymptotic Complexity
Running time of an algorithm as a function
of input size n for large n.
Expressed using only the highest-order
term in the expression for the exact
running time.
Instead of exact running time, say Θ(n2).
Written using Asymptotic Notation.
Asymptotic Notations 4
Asymptotic Notations
Θ , Ω, O, o, ω
Defined for functions over the natural numbers.
o Ex: f(n) = O(n2).
o Describes how f(n) grows in comparison to n2.
Asymptotic Notations 5
Algorithm
Growth Rate
Asymptotic Notations 6
Big Oh
(0)
Big-oh Notation (O)
If f, g: N → R+, then we can define Big-Oh as
For a given function g(n), denoted by O(g(n)) the set of functions,
O(g(n)) = {f(n): there exist positive constants c and n o such that
0≤ f(n) ≤ cg(n), for all n ≥ no}
f(n) = O(g(n)) means functions g(n) is an asymptotically upper
bound for f(n).
We may write f(n) = O(g(n)) OR f(n) ∈ O(g(n))
Big-oh Notation (O)
f(n) =
Example 2n + n log n O(2 )
n
Example
Prove that 2n2 ∈ O(n3)
Assume that f(n) = 2n2, and g(n) = n3
f(n) ∈ O(g(n))?
Now we must find the existence of c and n0 f(n) ≤ cg(n)
2n2 ≤ c.n3
2 ≤ c.n
if we take, c = 1 and n0= 2 OR c = 2 and n0= 1 then 2n2 ≤ c.n3 Hence
f(n) ∈ O(g(n)), c = 1 and n0= 2
Example n f(n) = 2n2 g(n) = n3
Prove that 1
2
2
8
1
2n ∈ O(n )
2 3 3 18 27
4 32 64
5 50 125
6 72 216
Asymptotic Notations 12
Big Omega
(Ω)
Big-omega Notation (Ω)
If f, g: N → R+, then we can define Big-omega as
For a given function g(n), denoted by Ω(g(n)) the set of functions,
Ω(g(n)) = {f(n): there exist positive constants c and n o such that
0≤ cg(n) ≤ f(n), for all n ≥ no}
f(n) = Ω(g(n)) means functions g(n) is an asymptotically lower
bound for f(n).
We may write f(n) = Ω(g(n)) OR f(n) ∈ Ω(g(n))
Big-omega Notation (Ω)
f(n) =
Example 2n + n log n Ω(nlogn)
Example
Prove that 5n2 ∈ Ω(n)
Assume that f(n) = 5n2, and g(n) = n
f(n) ∈ Ω(g(n))?
Now we must find the existence of c and n0 cg(n) ≤ f(n)
c.n ≤ 5n2
c ≤ 5n
if we take, c = 5 and n0= 1 then 5n2 ≤ c.n Hence f(n) ∈ O(g(n)), c =5
and n0= 1
Example n f(n) = 5n2 g(n) = n
Prove that 1
2
5
20
1
5n ∈ Ω(n)
2 3 45 3
4 80 4
5 125 5
6 180 6
Asymptotic Notations 18
Theta
(Θ)
Theta Notation (Θ)
If f, g: N → R+, then we can define theta as
For a given function g(n), denoted by Θ(g(n)) the set of functions,
Θ(g(n)) = {f(n): there exist positive constants c 1, c2 and no such that
0≤ c1g(n) ≤ f(n) ≤ c2g(n) , for all n ≥ no}
f(n) = Θ(g(n)) means functions f(n) is equal to g(n) to within a
constant factor, and g(n)is an asymptotically tight bound for f(n).
We may write f(n) = Θ(g(n)) OR f(n) ∈ Θ(g(n))
Theta Notation (Θ)
Example
Prove that 2n2 – 5n + 10 ∈ Θ(n2)
Assume that f(n) = 2n2 – 5n + 10 , and g(n) = n2
f(n) ∈ Θ(g(n))?
Now we must find the existence of c1, c2 and n0 c1g(n)
≤ f(n) ≤ c2g(n)
if we take, c1 = 1, c2 = 2 and n0= 2 then c1n2 ≤ 2n2 – 5n + 10 ≤ c2n2
Hence f(n) ∈ Θ(g(n)), c1 = 1, c2 = 2 and n0= 2
Example
Prove that 2n2 – 5n + 10 ∈ Θ(n2)
Asymptotic Notations 24