![]() |
VOOZH | about |
In mathematics, asymptotic analysis, also known as asymptotics, is a method of describing the limiting behavior of a function. In computing, asymptotic analysis of an algorithm refers to defining the mathematical boundation of its run-time performance based on the input size. For example, the running time of one operation is computed as f(n), and maybe for another operation, it is computed as g(n2). This means the first operation running time will increase linearly with the increase in n and the running time of the second operation will increase exponentially when n increases. Similarly, the running time of both operations will be nearly the same if n is small in value.
Usually, the analysis of an algorithm is done based on three cases:
All of these notations are discussed below in detail:
Omega (Ω) Notation:
Omega (Ω) notation specifies the asymptotic lower bound for a function f(n). For a given function g(n), Ω(g(n)) is denoted by:
Ω (g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ c*g(n) ≤ f(n) for all n ≥ n0}.
This means that, f(n) = Ω(g(n)), If there are positive constants n0 and c such that, to the right of n0 the f(n) always lies on or above c*g(n).
Follow the steps below to calculate Ω for a program:
For example, consider the below pseudo code.
The time taken by the above code can be written as a*n^2 + b*n + c where are a, b and c are some machine specific constants. In this case, the highest growing term is a*n^2. So we can say that the time complexity of the code is either Ω(n^2) or Ω(n) or Ω(Log n) or Ω(1)
Omega notation doesn't really help to analyze an algorithm because it is bogus to evaluate an algorithm for the best cases of inputs.
Theta (Θ) Notation:
Big-Theta(Θ) notation specifies a bound for a function f(n). For a given function g(n), Θ(g(n)) is denoted by:
Θ (g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1*g(n) ≤ f(n) ≤ c2*g(n) for all n ≥ n0}.
This means that, f(n) = Θ(g(n)), If there are positive constants n0 and c such that, to the right of n0 the f(n) always lies on or above c1*g(n) and below c2*g(n).
As an example. let us consider the above pseudo code only. In this case, the highest growing term is a*n^2. So the time complexity of the code is Θ(n^2)
Big - O Notation:
Big - O (O) notation specifies the asymptotic upper bound for a function f(n). For a given function g(n), O(g(n)) is denoted by:
O (g(n)) = {f(n): there exist positive constants c and n0 such that f(n) ≤ c*g(n) for all n ≥ n0}.
This means that, f(n) = O(g(n)), If there are positive constants n0 and c such that, to the right of n0 the f(n) always lies on or below c*g(n).
Follow the steps below to calculate O for a program:
As an example. let us consider the above pseudo code only. In this case, the highest growing term is a*n^2. So the time complexity of the code is O(n^2) or O(n^3) or O(n Log n) or any other term can be put inside O that has higher growth than n^2.
It is the most widely used notation as it is easier to calculate since there is no need to check for every type of input as it was in the case of theta notation, also since the worst case of input is taken into account it pretty much gives the upper bound of the time the program will take to execute.