Asymptotic Notations GATE Bits in PDF
Asymptotic Notations GATE Bits in PDF
Asymptotic Notations
i) Big – O (O)
1|Page
After analysing an algorithm A, if one says
TA(n) = O(n2)
He means that algorithm will be completed within cn2 time for a sufficiently large n.
Hence big – O given upper bound but this upper bound may or may not be the tightest.
Hence
If TA = O(n2) then
TA = O(n3)
TA = O(n4)
In fact T = O n
Hence set O(g(n)) is the umbrella under which all asymptotically smaller functions will reside
2|Page
f(n) = O(g(n))
After n = n0 f(n) will never catch c.g(n) where c is a constant
By writing f(n) = O(g(n)) we mean that a function f(n) is a member of set O(g(n))
Since O notation describes an upper bound, it can be used to bound the worst case
running time of an algorithm.
Hence it is meaningful to say that running time of insertion sort is O(n2), though we can
also say O(n3), because again big –O need not provide tightest upper bound. [It may or
may not be tightest].
ii. Small–o
Big –O notation is like ≤
f(n) ≤ g(n) when f(n) = O(g(n))
small – o notation is like <
f(n) < g(n) when f(n) = o(g(n))
The asymptotic upper bound provided by O – notation may or may not be
asymptotically tight.
Small – o is used to denote an upper bound that is NOT asymptotically tight.
o(g(n)) = {f(n): for any positive constant c > 0, n0 > 0, 0 ≤ f(n) < cg(n) ∀ n>n0}
Example
3n = o(n2), but 2n2 ≠ o(n2)
3|Page
logn = o(n), but log n ≠ o(100 logn)
Therefore, when
f(n) = o(g(n)) and n approaches infinity
( )
→∝ =0
( )
f(n) = Ω(g(n))
As Ω notation describes a lower bound, it is used to bound the best case running time of
an algorithm.
Example:
If T(n)denotes the running time of the insertion sort on input – size n, then we can say
that T(n) = Ω(n) as insertion sort takes linear time in best case.
Remember in practice we use O and Ω notations to tight upper and lower bounds
respectively otherwise for any function T(n)both the following statements are TRUE.
T(n) = Ω(0)
T(n) = O(∞)
Which means any algorithm will take at least zero time and at most infinity time to
compute.
4|Page
iv. Little –Omega (ω)
ω –nation is used to denote a lower bound that is not asymptotically tight.
Hence ω(g(n)) is the set
ω(g(n)) = {f(n): ∃ positive C, n0 > 0 such that 0 ≤ C g(n) < f(n) for all n ≥n0}
Ω-notation is like ≥ where us ω notation is like >
Hence
√ = (lg ) √ ≠ √
v. Theta-Notation (θ)
If two functions f(n)and g(n)are of same order, then
f(n) = θ(g(n))
we say that g(n) is an asymptotically tight bound for f(n)
θ(g(n)) the set of functions θ(g(n)) = {f(n): ∃ c1 , c2 >0
and n0 s.t. 0 ≤ c1 g(n) ≤ f(n) ≤ c2 g(n) for all n ≥ n0}
which means
θ(g(n)) = O(g(n)) ∩ Ω(g(n))
Example:
As we know that no matter what the input is mergesort always takes c.nlogn time.
Assume T(n) represents T.C. of mergesort then
T(n) = O(nlogn)
T(n) = Ω(nlogn)
Hence
T(n) = θ(nlogn)
Hence depending upon the behaviour of the algorithm on different inputs we use the
most expressive and meaningful notation to represent complexity of an algorithm
Following statement about time complexity of mergesort are also correct but do not
make much sense:
T(n) = O(n2)
T(n) = o(n2)
T(n) = ω(n)
T(n) = Ω(n)
6|Page
(3) ( ) ( )
(4) ( ) ∩Ω ( )
2. Assume ( ) denotes the time complexity of merge sort algorithm which of the
following statements is/are correct?
(i) ( ) = ( log )
(ii) ( ) = ( log )
(iii) ( ) = ( log )
(iv) ( ) = ( )
(1) i and iii only
(2) ii and iii only
(3) i and iv only
(4) ii, iii and iv only
(1) ( ) = ( )=
(2) ( ) = ( ) lg ( ) = ( )
( ) ( )
(3) ( ) = ( ) 2 = 2
(4) ( ) + ( ) = ( ), ( )
6. Assume f(n) and g(n) are two functions such that f(n) = O (g(n)). Which of the
following will always hold?
(1) ( ) = ( )
7|Page
(2) ( ) = Ω ( )
(3) ( ) = ( )
(4) ( ) = Ω ( )
(3) √ , 2 , . (log ) ,
(4) 2 , √ , (log ) ,
Liked this article on Asymptotic Notations? Let us know in the comments. You may also
like...
Theory of Computation
Ans 2: 4
8|Page
Solution: we know that time complexity of Merge Sort is ( log ) hence all statements
are valid except i, because little-oh notation is used to give non-tightest upper bound.
Statement (iv) is true because of the fact that if merge sort can be performed in nlogn
time than it can definitely be performed in O(n2),this statement may not be very useful
though.
Remember: Upper bound means "cannot be asymptotically worse than". Therefore all
algorithms are O(∞). Lower bound means "cannot be asymptotically better than". So all
algorithms are Ω(0).
Ans 3: 3
. 3 = ( ) 2 ≠ (2 )
Ans 4: 3
Solution: Statement C can never hold because if tight bounds are Ω(n2) and O(n2) then
ω(n2) can never be the non-tightest lower bound.
Ans 5: 3
Solution: Statements A, B and D can hold but Statement C can never hold.
Ans 6: 4
Solution: Assume ( ) = then option ‘A’ will not hold.
Ans 7: 4
9|Page