Lecture-2 - Computational Complexity and Asymptotic Notation
Lecture-2 - Computational Complexity and Asymptotic Notation
Computational complexity
1
Today’s Contents
• Computational complexity
• Asymptotic Notation
• Why Complexity Analysis is needed?
2
Computational complexity
▪ In computer science, the computational complexity or
simply complexity of an algorithm is the amount of
resources required to run it.
1. Time Complexity
2. Space Complexity
4
Complexity Analysis of Algorithm
1. Time Complexity
Time complexity is generally expressed as the number of
required elementary operations on an input of size n, where
elementary operations are assumed to take a constant amount of
time on a given computer and change only by a constant factor
when run on a different computer.
2. Space Complexity
Space complexity is generally expressed as the amount of
memory required by an algorithm on an input of size n.
5
Understanding of Time and Space Complexity
Design an algorithm to add two numbers and display the result
Algo-1: Algo-2:
1. START 1. START
2. declare three integers a, b & c 2. declare three integers a & b
3. Input in a & b 3. Input in a & b
4. c a+b 4. print a+b
5. print c 5. STOP
6. STOP
7
Asymptotic Notations
Following are the commonly used asymptotic notations to
calculate the running time complexity of an algorithm.
8
Understanding of Three cases
and Asymptotic Notation
▪ Example: 01
Search an element in an Array.
5 6 3 8 1 31
▪ Example: 02
Sort the element in an Array.
5 6 7 8 10 31
▪ Example: 02
Sort the element in an Array.
5 6 3 8 1 31
13
Thank you!
14