Module 1 Part D
Module 1 Part D
Module-1
Analyzing Iterative (Non-Recursive)
Algorithms
1
Amity School of Engineering & Technology (CSE)
OBJECTIVES
After completing this section, you will be able to
Understand the concept of Step count or Operation Count for analyzing time
complexity of Iterative algorithm.
2
Amity School of Engineering & Technology (CSE)
3
Amity School of Engineering & Technology (CSE)
Step Count:
The idea is to count the instructions that are used by the given algorithm to
perform the given task.
The idea is to find the step count (called steps per execution s/e) of each
instruction.
Frequency is the number of times the instruction is executed. The total
count can be obtained by multiplying the frequency and steps per execution.
Time complexity=
5
Amity School of Engineering & Technology (CSE)
Operation Count:
The idea is to count all the operations like add, sub, multiplication and
division. Some of the operations that are typically used are assignment
operations, Comparison operations, Arithmetic operations and logical
operations. The time complexity is then given as the number of repetitions of
the basic operation as a function of input size.
Time complexity=
Amity School of Engineering & Technology (CSE)
7
Amity School of Engineering & Technology (CSE)
8
Amity School of Engineering & Technology (CSE)
Example3: Example4:
Assume n>=2 A()
A() {
{
While(n>1)
for(i=1; i<=n; i++)
{ for(i=1;i<=n,i=i*2)
n=n/2; {
} printf("Amity");
} }
}
9
Amity School of Engineering & Technology (CSE)
10
Amity School of Engineering & Technology (CSE)
Q.1)
Q.2)
Q.3)
Q.4)
11
Amity School of Engineering & Technology (CSE)
Q.5)
Q.6:
12