Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Analysis Of Algorithm

Asymptotic Notations
By
Prof. Chhaya Narvekar
Big Oh (O) (Upper Bound)

Time t

Input Size n
Definition of (Big Oh) O
• f (n) <= C *g(n) for all values of n >= n0 where C and n are real numbers such that c > 0 and
n0 >= 1, then f (n)= O(g(n))

• Example:
f (n)= 3n+2 g (n) = n
Can we say f (n)=O(g(n))?
Solution->
f(n) <= C* g(n), C>0, n0 >=1
3n+2 <=C*n Find the value of C.

If C=4
3n+2 <= 4n
2 <= 4n-3n,
n>=2
Therefore for C=4 and n0=2, 3n+2 <=4n is true always, so f (n)=O(g(n))
Big Omega (Ω) (Lower Bound)

Time t
Definition of (Omega) Ω
• f (n) >= C *g(n) for all values of n >= n0 where C and n are real numbers where c > 0 and n0 >= 1,
then f (n)= O(g(n))

• Example:
f (n)= 3n+2 g (n) = n
Can we say f (n)=Ω(g(n))?
Solution->
f(n) >= C* g(n), C>0, n0 >=1
3n+2 >=C*n Find the value of C.

If C=1 and no>=1


3n+2 >= n
for all values of n>=1, 3n+2>=n is true always
Therefore f (n)= Ω(g(n))
Big Theta (Ѳ)

Time t

Input Size n
Definition of (Theta) Ѳ
• C1*g(n)<= f (n) <= C2 *g(n) for all values of n >= n0 where C1, C2 and n are real numbers such
that C1> 0, C2>0 and n0 >= 1, then f (n)= Ѳ(g(n))

• Example:
f (n)= 3n+2 g (n) = n
Can we say f (n)=Ѳ(g(n))?
Solution->
f(n)=3n+2, g(n)=n
f(n)<=C2*g(n) where C=4
3n+2 <= 4n therefor C2=4 for all n0>=1

f(n) >= C1*g(n)


3n+2 >=n therefor C1=1 for all n0 >=1
Therefor 3n+2 is bounded by g(n) both in upper bound and lower bound, for upper bound C2=4 and
lower bound C1=1 where n0>=0 3n+2
Therefor 3n+2=Ѳ(n)
Practical Significance
O (Big Oh) Upper Bound Worst Case In any case your time will not be
exceeding this.

Ω (Big Omega) Lower Bound Best Case In any case you can never achieve better
than this.

Ѳ (Theta) Tight Bound Average Case When both worst case and best case are
same we go for average case.
• Problem is to search a key element in the array.
5 7 1 2 4 10 20 11 15

Explanation:
Best Case search key is 5 Minimum One Can never go down
comparison beyond Ω(1)
Worst Case search key is 15 or Maximum N Can never go up
100 comparisons beyond O(n)
Average Search key is 4 N/2 Comparisons Ѳ(n/2)=Ѳ(n)
Case

Order:
1< Log(n)< < n< n*logn< < n!

You might also like