22CS302_LM9
22CS302_LM9
✔ Consider function f(n) as time complexity of an algorithm and g(n) is the most
significant term.
✔ If f(n) <= C g(n) for all n >= n0, C > 0 and n0 >= 1. Then we can represent
f(n) as O(g(n)). f(n) = O(g(n))
● Consider the following graph drawn for the values of f(n) and C g(n) for input (n) value
on X-Axis and time required is on Y-Axis.
● In below graph after a particular input value n0, always C g(n) is greater than f(n)
which indicates the algorithm's upper bound.
Example:
Consider the following f(n) and g(n).
f(n) = 3n + 2
g(n) = n
If we want to represent f(n) as O(g(n)) then it must satisfy f(n) <= C g(n) for all values of C
> 0 and n0>= 1
f(n) <= C g(n)
⇒3n + 2 <= C n
Above condition is always TRUE for all values of C = 4 and n >= 2.
By using Big - Oh notation we can represent the time complexity as follows.
3n + 2 = O(n)
Omega notation (Ω - notation)
● This notation is used to define the lower bound of an algorithm in terms of Time
Complexity.
● That means Omega notation always indicates the minimum time required by an
algorithm for all input values.
● Omega notation describes the best case of an algorithm time complexity.
● Omega Notation can be defined as follows.
✔ Consider function f(n) as time complexity of an algorithm and g(n) is the most
significant term.
✔ If f(n) >= C g(n) for all n >= n0, C > 0 and n0 >= 1. Then we can represent
f(n) as Ω(g(n)). f(n) = Ω(g(n))
● Consider the following graph drawn for the values of f(n) and C g(n) for input (n) value
on X-Axis and time required is on Y-Axis.
● In below graph after a particular input value n0, always C g(n) is less than f(n) which
indicates the algorithm's lower bound.
Example:
Consider the following f(n) and g(n).
f(n) = 3n + 2
g(n) = n
If we want to represent f(n) as Ω(g(n)) then it must satisfy f(n) >= C g(n) for all values of C
> 0 and n0>= 1
f(n) >= C g(n)
⇒3n + 2 >= C n
Example:
Consider the following f(n) and g(n).
f(n) = 3n + 2
g(n) = n
If we want to represent f(n) as Θ(g(n)) then it must satisfy C1 g(n) <= f(n) <= C2 g(n) for all
values of C1 > 0, C2 > 0 and n0>= 1
C1 g(n) <= f(n) <= C2 g(n)
⇒C1 n <= 3n + 2 <= C2 n
Above condition is always TRUE for all values of C1 = 1, C2 = 4 and n >= 2.
By using Theta notation we can represent the time complexity as follows.
3n + 2 = Θ(n)
Which Complexity analysis is generally used?