You are on page 1of 21

Asymptotic Analysis

• Using asymptotic analysis, we can get an idea


about the performance of the algorithm based on
the input size. We should not calculate the exact
running time, but we should find the relation
between the running time and the input size. We
should follow the running time when the size of
the input is increased.

• For the space complexity, our goal is to get the


relation or function that how much space in the
main memory is occupied to complete the
algorithm.
Asymptotic Behavior
• For a function f(n) the asymptotic behavior is the
growth of f(n) as n gets large. Small input values are
not considered. Our task is to find how much time it
will take for a large value of the input.

• For example: f(n) = c * n + k as linear time complexity.


f(n) = c *(n*n) + k is quadratic time complexity.

• The analysis of algorithms can be divided into three


different cases. The cases are as follows:
Best Case
Average Case
Worst Case
• Best Case − Here the lower bound of the running
time is calculated. It describes the behavior of an
algorithm under optimal conditions.

• Average Case − In this case, we calculate the


region between the upper and lower bound of
the running time of algorithms. In this case, the
number of executed operations are not minimum
and not maximum.

• Worst Case − In this case we calculate the upper


bound of the running time of algorithms. In this
case, a maximum number of operations are
executed.
Asymptotic Notations
Asymptotic notations are used to represent the complexities of algorithms for
asymptotic analysis. These notations are mathematical tools to represent the
complexities. There are three notations that are commonly used.

Big Oh Notation
Big-Oh (O) notation gives an upper bound for a function f(n) to within a constant
factor.

Little o Notations
There are some other notations present except the Big-Oh, Big-Omega and Big-Theta
notations. The little o notation is one of them.
Little o notation is used to describe an upper bound that cannot be tight. In other
words, loose upper bound of f(n).

Big Omega Notation


Big-Omega (Ω) notation gives a lower bound for a function f(n) to within a constant
factor.

Little ω Notations
Another asymptotic notation is little omega notation. it is denoted by (ω).
Little omega (ω) notation is used to describe a loose lower bound of f(n).

Big Theta Notation


Big-Theta(Θ) notation gives bound for a function f(n) to within a constant factor.
Big O Notation
• Assume that you wrote
an algorithm and
execute it and find out
that when the size of
your input increases,
the time it takes to
execute the algorithm is
increasing as shown in
the following graph.
Refer Graph_01.
The Y-axis denotes the time
where X-axis denotes the
input size. The
function f(n) represents your
algorithm time-input
relationship. Now let's try to
understand what is the worst
case or the upper bound of
this function f(n). In order to
analyze this, let's create
another
function cg(n) where cg(n) is
greater than f(n) after a
particular input value which
is n0 as per the Graph_01
below. In here n0 should be
greater than or equal to 1
because the input cannot be
0.
• In other words, after a
given input value n0, for
any n value which is greater
than n0 ,cg(n) is greater
than or equal to f(n).

• Thus, we say that if


 f(n) ≤ cg(n) for any n ≥ n0
where c, n are real numbers
and c > 0 and n0 ≥ 1
 then f(n) = O(g(n)) .
Example
• Go through the following example where I have taken a sample
function:
• f(n) = 4n + 3 and
• g(n) = n
• Now we need to see whether we can say f(n) = O(g(n)) . How we
can check that?
• We have to try and see whether we can find values
for c and n0 where it will fulfill the condition
• if f(n) ≤ cg(n) for any n ≥ n0 where c, n are real numbers and c > 0
and n0 ≥ 1
• then we say f(n) = O(g(n)).
• If we are successful then we can say f(n) = O(g(n)) when f(n) = 4n +
3 and g(n) = n .
4n+3 ≤ cn
Find value of n and c for which above condition
always follow.
• for any n ≥ n0
• where c, n are real numbers and
• c > 0 and n0 ≥ 1
Big Omega (Ω) Notation
Let's assume that the
following graph
(Graph_02) represent
your algorithm's time-
number of inputs
relationship. That
means f(n) below shows
how the time of
execution depends on
the length of the input
of the algorithm.
Big Omega (Ω) Notation
Again the Y-axis denotes the
time where X-axis denotes the
input size. The
function f(n) represents your
algorithm time-input
relationship. Now let's try to
understand what is the best
case or the lower bound of
this function f(n). In order to
analyze this scenario, let’s
create another
function cg(n) where cg(n) is
less than f(n) after a particular
input value (which is n0 as per
the Graph_02 below). In here
again n 0 should be greater
than or equal to 1 (n ≥
1) because the input cannot
be 0.
Big Omega (Ω) Notation
Thus, we say that if
• f(n) ≥ cg(n) for any
• n ≥ n0
• where c, n are real
numbers and
• c > 0 and n0 ≥ 1 then
• f(n) = Ω(g(n)) .
Example
Let's take the same function
f(n) = 4n + 3and g(n) = n .
Now we need to see whether we can say f(n) = Ω(g(n)) .
For that, we have to try and see whether we can find
values for c and n0 where it will fulfil the condition if
f(n) ≥ cg(n) for any n ≥ n0 where c, n are real numbers
and c > 0 and n0 ≥ 1 then
f(n) = Ω(g(n)).
If we are successful then we can say f(n) = Ω(g(n))
when f(n) = 4n + 3 and g(n) = n .
Big Theta (Ө) Notation
• In Big O definition we found
the upper bound of the
function f(n) and in Big Omega
we found the lower bound of
the function f(n) . In here we
are looking at both upper
bound and lower bound of the
function f(n) by changing
the c value of
the cg(n) function. If the
function f(n) bounded
by c1g(n) and c2g(n) after a
given value of n (let's say n0)
for all n ≥ n0 then we say f(n) =
Ө(g(n)) . These
constants c1 and c2 could be
different.
Big Theta (Ө) Notation
• Here also Y-axis denotes
the time where X-axis
denotes the input size.
The
function f(n) represents
your algorithm time-
input relationship. In
here, any n value which
is greater than n0 , will
satisfy
• c1g(n) ≤ f(n) and c2g(n)
≥ f(n) .
Big Theta (Ө) Notation
• Thus, we say that if
• c1g(n) ≤ f(n) ≤ c2g(n)
• for any n ≥ n0
• where c1, c2, n are real
numbers and
• c1,c2 > 0 and n0 ≥ 1
then
• f(n) = Ө(g(n)) .
Example
Let’s take the same function
f(n) = 4n + 3 and g(n) = n .
Now we need to see whether we can say
f(n) = Ө(g(n)) .
For that, we have to try and see whether we can
find values for c1, c2and n0 where it will fulfil the
condition
if c1g(n) ≤ f(n) ≤ c2g(n) for any n ≥ n0 where c1,
c2, n are real numbers and c1,c2 > 0 and n0 ≥ 1
then
f(n) = Ө(g(n)) .

You might also like