Lecture-3_Complexity Analysis of Algorithms
Lecture-3_Complexity Analysis of Algorithms
Computational complexity
1
Today’s Contents
• How to find the Complexity of an Algorithm?
2
Let’s Find out the complexity of
Algorithms
3
Find the Complexity of the following Algorithm
Example-1:
a = 4; // This will be executed only once.
b = a + 7; // This will be executed only once
4
Find the Complexity of the following Algorithm
Example-1:
Example-2:
Example-3:
Self Practice
for i = 1 to n
for j = 1 to n
for k = 1 to n
SUM = a+b ;
7
Find the Complexity of the following Algorithm
Example-4:
\\ SUM = a+b ;
for j = 1 to n ---------------- O (n)
\\ SUM = a+b ;
Example-5:
Self Practice
Example-6:
Sum = 0
for i = 1 to n
SUM += A[i] ;
Print Sum
10
Find the Complexity of the following Algorithm
Self Practice
Example-6:
Sum = 0
for i = 1 to n
SUM += A[i] ;
Print Sum
11
Find the Complexity of the following Algorithm
Example-7:
Self Practice
flag = FALSE
for i = 1 to n
if A[i] == key
flag = TRUE;
if flag == TRUE
FOUND
else
NOT FOUND
13
Some common rates of growth
14
Rate of Growth
15
Time complexity (Worst Case) of
some data Structures
16
Thank you!
17