Professional Documents
Culture Documents
Analysis of Algorithm - Lecture 1
Analysis of Algorithm - Lecture 1
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.
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
Ω (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!