4. ASYMPTOTIC NOTATIONS
4. ASYMPTOTIC NOTATIONS
NOTATIONS
TYPES OF FUNCTIONS
• O(1) – Constant
• O(log n) – Logarithmic
• O(n) – Linear
• O(n2) – Quadratic
• O(n3) – Cubic
• O(2n) – Exponential
• When it comes to analyzing the complexity of any algorithm in terms of time and
space, we can never provide an exact number to define the time required and the
space required by the algorithm, instead we express it using some standard
notations, also known as Asymptotic Notations.
Asymptotic Notation
• Space and time required by a program is non-negative quantities so the assumption that
f(n) has non negative value for all values of n
• Asymptotic notation describes the behaviour of the time/space complexity for large
instance characteristics.
Big Oh(O)
Big Theta (Θ)
Big Omega (Ω)
Asymptotic Notation
• Upper Bounds: Big-Oh
• This notation is known as the upper bound of the algorithm, or a Worst Case of
an algorithm.
• It tells us that a certain function will never exceed a specified time for any value
of input n.
f(n)= 2n+3
Big Oh(O)
Big-Oh, commonly written as O, is an Asymptotic Notation for the worst case, or
ceiling of growth for a given function.
It provides us with an asymptotic upper bound for the growth rate of the runtime
of an algorithm.
Say f(n) is your algorithm runtime, and g(n) is an arbitrary time complexity you
are trying to relate to your algorithm. f(n) is O(g(n)), if for some real constants c
(c > 0) and n0, f(n) <= c g(n) for every input size n (n > n0).
O-notation
For function g(n), we define O(g(n)), big-O of n,
as the set:
O(g(n)) = {f(n) :
positive constants c and n0, such that n n0,
f(n)= 2n+3
C=5, g(n) =n
• We say that the running time is "big-Ω of f(n) f(n) f(n)f, left parenthesis, n,
right parenthesis." We use big-Ω notation for asymptotic lower bounds, since
it bounds the growth of the running time from below for large enough input
sizes.
Big-Ω (Big-Omega) notation
Example :
If, f(n)= 2n+3
f(n) >= c g(n) for all values of n>=n0
(2n+3) >= n for all n>=1
(2n+3) = 1*n
C=1, g(n) =n
C=9, g(n) = n 2
Therefore f(n) = O(n 2 )
1 n 2 <=2 n 2 +3n+4 Ω(n 2 )
1 n 2 <=2 n 2 +3n+4<= 9 n 2 (n 2 )