0% found this document useful (0 votes)
3 views12 pages

Module 1 Part D

The document outlines the objectives and concepts related to the analysis and design of algorithms, specifically focusing on iterative (non-recursive) algorithms. It explains time complexity, step count, and operation count as methods for analyzing the efficiency of algorithms, along with examples for practical understanding. Additionally, it includes exercises for assessing the time complexity of various iterative algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

Module 1 Part D

The document outlines the objectives and concepts related to the analysis and design of algorithms, specifically focusing on iterative (non-recursive) algorithms. It explains time complexity, step count, and operation count as methods for analyzing the efficiency of algorithms, along with examples for practical understanding. Additionally, it includes exercises for assessing the time complexity of various iterative algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Amity School of Engineering & Technology (CSE)

Analysis and Design of Algorithm(ADA)

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.

 Analyse Iterative algorithms

 Check the progress for analysing Iterative algorithms

2
Amity School of Engineering & Technology (CSE)

3
Amity School of Engineering & Technology (CSE)

Time complexity is expressed as a function of input size, T(n) ,


where ‘n’ is the input size.
Time complexity can be estimated using step count or operation
count. Thus, T(n) can be estimated using two types of analysis :
Apriori (or Mathematical analysis) Posteriori (or Empirical
analysis)
Apriori analysis (or Mathematical analysis)
is done before the algorithm is translated posteriori analysis is done by
to a program. The step count or the
number of executed count of the dominant
executing the program using
operations is used to estimate the running standard datasets to estimate time
time. and space.
Step count: T(n) is obtained using the step count
of the instructions.
Operation Count :
Another popular school represented by Donald E
Knuth prefer the determination of running time
based on the count of basic operations. The idea
is to use dominant operator and expressing the
complexity as the number of times the basic (or
dominant) operator is executed
4
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)

Some Important formulae:

7
Amity School of Engineering & Technology (CSE)

Some Important formulae…

8
Amity School of Engineering & Technology (CSE)

Check your progress1


Example1: Example2:
A() A()
{ {
int i,j;
for(i=1; i<=n, i++)
for(i=1;i<=n,i=i*2)
for(j=1; j<=n; j++) printf("Amity");
printf("Amity"); }
}

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)

Check your progress1


Example5: Example6:
A() A()
{
int i,j,k;
{
for(i=1; i<=n; i++) int i,j,k,n
{ for(i=1; i<=n;i++)
for(j=1; j<=i; j++) {
{ for(j=1; j<=i2;j++)
for(k=1;k<=500;k++) {
{ for(k=1;k<=n/2;k++)
printf("Amity"); {
}
} printf("Amity");
} }
}
}
}

10
Amity School of Engineering & Technology (CSE)

Check your progress2


Find the time complexity for the following iterative algorithm:

Q.1)

Q.2)

Q.3)

Q.4)

11
Amity School of Engineering & Technology (CSE)

Find the time complexity for the following iterative algorithm:

Q.5)

Q.6:

12

You might also like