Class2 Asymptotic
Class2 Asymptotic
Dr J P Patra
Associate Professor
Computer Science & Engineering
UTD, CSVTU, Bhilai
1
Outline:
• What is Asymptotic Notation?
2
What is Asymptotic Notation?
• Asymptotic notation is used to categorize algorithms into
complexity classes, such as polynomial time (P), exponential
time (EXP), or logarithmic space (L).
Or
3
Why Asymptotic Notation is important?
Algorithm Analysis: Asymptotic notation is crucial for analyzing algorithms and
understanding their efficiency. This analysis is essential for selecting the most
efficient algorithm for a given problem.
5
Types of Asymptotic Notations
• Big O Notation (O)
6
Big O Notation (O)
Big O notation represents the upper bound of the running time of
an algorithm. Thus, it provides the worst case complexity of an
algorithm.
Definition :
The function f(n) is Big O of g(n) written as f(n)= O(g(n)), if there
exist two positive constants C and n0 such that f(n) ≤ C.g(n) , for
all n ≥ n0
7
Example: Prove that f(n)=2n2+3n+5 = O(n2)
or
Solution: As the above problem deals with Big O Notation we must have to
satisfy the condition f(n) ≤ cg(n) for n ≥ n0
10
Example:
(i) f(n)=2n2+3n+5 = Ω (n2) is True
(ii) f(n)=2n2+3n+5 = Ω (n) is True
(iii) f(n)=2n2+3n+5 = Ω (√n) is True
(iv) f(n)=2n2+3n+5 = Ω (logn) is True
11
Big Theta Notation (Θ)
Theta notation encloses the function from above and below.
Since it represents the upper and the lower bound of the running
time of an algorithm, it is used for analyzing the average-case
complexity of an algorithm.
Definition :
The function f(n) is Big Theta of g(n) written as f(n)= ϴ (g(n)), if
there exist three positive constants C1 ,C2 and n0 such that C1 *
g(n) ≤ f(n) ≤ C2 * g(n), for all n ≥ n0
12
Big O Notation
Omega Notation
13
Example:
(i) f(n)=2n+5 = ϴ (n) is True
then
14
Properties of Asymptotic Notations
General Properties:
Example:
f(n) = 2n²+5 is O(n²)
then, 7*f(n) = 7(2n²+5) = 14n²+35 is also O(n²).
15
Transitive Properties:
Example:
16
Symmetric Properties:
If f(n) is Θ(g(n)) then g(n) is Θ(f(n)).
Example:
17
Transpose Symmetric Properties:
Example:
If(n) = n , g(n) = n²
then n is O(n²) and n² is Ω (n)
18
Advantages of Asymptotic Notations
• Asymptotic analysis provides a high-level understanding of how an
algorithm performs with respect to input size.
19
Disadvantages of Asymptotic Notations
• Asymptotic analysis does not provide an accurate running time or
space usage of an algorithm.
• It assumes that the input size is the only factor that affects an
algorithm’s performance, which is not always the case in practice.