SlideShare a Scribd company logo
2
Most read
3
Most read
9
Most read
ALGORITHM DESIGN AND
ANALYSIS
SWAPNA.C
Performance of a program:
• The performance of a program is the amount of computer memory and time
needed to run a program.
• We use two approaches to determine the performance of a program.
• One is analytical, and the other experimental. In performance analysis
we use analytical methods, while in performance measurement we conduct
experiments.
• Performance Analysis:
• Performance Analysis of an algorithm depends upon 2 factors that is
amount of memory used and amount computer time consumed on any
CPU.
• Space complexity, Time Complexity, Network ,Power, CPU Registers.
Time Complexity
• The time needed by an algorithm expressed as a function of the size of a
problem is called the time complexity of the algorithm. The time complexity
of a program is the amount of computer time it needs to run to completion.
• Time=Fixed Time +Instance time.
• Characteristics of compiler used to compile the program.{fixed}.
• Computer Machine on which the program is executed and physically
clocked.{variable}
• Multiuser execution system. {variable}
• Number of program steps. {variable}
• The limiting behaviour of the complexity as size increases is called the
asymptotic time complexity. It is the asymptotic complexity of an algorithm,
which ultimately determines the size of problems that can be solved by the
algorithm.
•Comments count as zero steps.
•As assignment statement which does not involve any calls to other
algorithm is counted as one step,
•For iterative statements we consider the steps count only for the
control part of the statement etc.
Calculate:
Total no. of program steps= no. of steps per execution of the statement
+ frequency of each statement executed.
Statement Steps for execution Frequen
cy
Total steps
Algorithm sum ( number, size) 0 - 0
{ 0 - 0
Result:=0.0 1 1 1
For count=1 to size do 1 size+1 size+1
result= result + number[count]; size size
Return result; 1 1 1
}
Total 2size+3
Time Complexity:
Step Table
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
Space Complexity
• The space complexity of a program is the amount of memory it needs to run to
completion i.e from start of execution to its termination. .
• The space need by a program has the following components:
• Fixed component + Variable component=space.
• Fixed Component: Instruction space+ space of sample variable + constant variable. This
is independent of input and output.
• Variable component: space needed by compound variable whose size depend on input
and output. EX: stack space, data structures like linked list, heap, trees graphs.
• Instruction space: Instruction space is the space needed to store the compiled
version of the program instructions.
• Data space: Data space is the space needed to store all constant and variable values.
Data space has two components:
• Space needed by constants and simple variables in program.
• Space needed by dynamically allocated objects such as arrays and class instances.
Environment stack space: The environment stack is used to save
information needed to resume execution of partially completed functions.
Instruction Space: The amount of instructions space that is needed
depends on factors such as:
The compiler used to complete the program into machine code.
The compiler options in effect at the time of compilation
The target computer.
To calculate:
1.Determine the variables which are instantiated by some default values.
2.Determine which instance characteristics should be used to measure the
space requirement and this will be problem specific.
3.Generally the choices are limited to quantities related to the number and
magnitudes of the inputs to and outputs from the algorithms.
4.Some times more complex measures of the inter realtionships among the
data items can used.
Ex:
Algorithm Sum(number[], size)
{
result:=0.0; result-------------------1 word
for count:=1 to size do count---------------1unit size------1 unit
result:=result + number[count]; number[]----------n
return result;
}
S(n)=3+n---------------O(n)
Constant space complexity:
Ex.
Algorithm square(int a) a variable -----1
{
return a*a;-------------s(n)=1}------------------O(1)
Linear space complexity:
Ex.int sum(int a[],int n) n variable ---1unit
int sum=0; a---n units
for(i=0;i<n;i++) i--------1 unit
sum=sum+a[i]; sum--- 1 unit
return sum } s(n)=n+3----------O(n)
Ex: Algorithm Swap(a,b) Space Time
{
Temp=a: ---------1word 1 unit of Time
a=b; ----------1 1
b=Temp; -------1 1
} s(n)=3 f(n)=3
Ex: Ex.int sum(int a[],int n) Space Time
{ n variable ---1unit
int sum=0; a---n units 1
for(i=0;i<n;i++) { i--------1 unit n+1
sum=sum+a[i]; } sum--- 1 unit n
return sum 1
} s(n)=n+3----------O(n) f(n)=2n+3-------O(n)
Frequency Count Method
Ex: Algorithm Add(A,B,n) Time Space
{
for(i=0;i<n;i++) n+1 A---n^2
{ B---n^2
for(j=0;j<n;j++) n*(n+1) C---n^2
{ n--1
C[i,j]=A[i,j]+B[i,j]; n*n i---1
} j---1
} f(n)=2n^2+2n+1 s(n)=3n^2+3
O(n^2) O(n^2)
Ex: Algoritihm Multiply(A,B,n) Frequency Count Method
{ Time Space
for(i0;i<n;i++) n+1 A----n^2
{ B-----n^2
For(j=0;j<n;j++) n*n+1 C-----n^2
{ n-----1
C[i,j]=0; n*n i-----1
for(k=0;k<n;k++) n*n*n+1 j----1
{ k----1
C[i,j]=C[i,j]+A[i,k]*B[k,j]; n*n*n s(n)=3n^2+4
} f(n)=2n^3+3n^2+2n+1 O(n^2)
} O(n^3)
}
}

More Related Content

What's hot (20)

PPTX
Code generation
Aparna Nayak
 
PPTX
Specification-of-tokens
Dattatray Gandhmal
 
PDF
Code optimization in compiler design
Kuppusamy P
 
PDF
Object oriented programming c++
Ankur Pandey
 
PPTX
Algorithm and pseudocode conventions
saranyatdr
 
PPTX
Input-Buffering
Dattatray Gandhmal
 
PPT
Complexity of Algorithm
Muhammad Muzammal
 
PPTX
Syntax-Directed Translation into Three Address Code
sanchi29
 
PPTX
1.10. pumping lemma for regular sets
Sampath Kumar S
 
PPTX
Unit iv(simple code generator)
Kalaimathi Vijayakumar
 
PPTX
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
PPTX
15 puzzle problem using branch and bound
Abhishek Singh
 
PPTX
Recognition-of-tokens
Dattatray Gandhmal
 
PPTX
Graph coloring using backtracking
shashidharPapishetty
 
PPTX
Critical section problem in operating system.
MOHIT DADU
 
PPTX
Non- Deterministic Algorithms
Dipankar Boruah
 
PPT
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
PPTX
8 queens problem using back tracking
Tech_MX
 
PPTX
Compiler Design Unit 4
Jena Catherine Bel D
 
PPTX
Three Address code
Pooja Dixit
 
Code generation
Aparna Nayak
 
Specification-of-tokens
Dattatray Gandhmal
 
Code optimization in compiler design
Kuppusamy P
 
Object oriented programming c++
Ankur Pandey
 
Algorithm and pseudocode conventions
saranyatdr
 
Input-Buffering
Dattatray Gandhmal
 
Complexity of Algorithm
Muhammad Muzammal
 
Syntax-Directed Translation into Three Address Code
sanchi29
 
1.10. pumping lemma for regular sets
Sampath Kumar S
 
Unit iv(simple code generator)
Kalaimathi Vijayakumar
 
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
15 puzzle problem using branch and bound
Abhishek Singh
 
Recognition-of-tokens
Dattatray Gandhmal
 
Graph coloring using backtracking
shashidharPapishetty
 
Critical section problem in operating system.
MOHIT DADU
 
Non- Deterministic Algorithms
Dipankar Boruah
 
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
8 queens problem using back tracking
Tech_MX
 
Compiler Design Unit 4
Jena Catherine Bel D
 
Three Address code
Pooja Dixit
 

Similar to Performance analysis(Time & Space Complexity) (20)

PPTX
Unit 1, ADA.pptx
jinkhatima
 
PPTX
Performance analysis and randamized agoritham
lilyMalar1
 
PPT
DAA-Introduction-Divide and Conquer Technique
sailaja156145
 
PPTX
Data structures algorithms basics
ayeshasafdar8
 
PPTX
2. Introduction to Algorithm.pptx
RahikAhmed1
 
PPT
Introduction to data structures and Algorithm
Dhaval Kaneria
 
PPTX
Analysis of algorithn class 2
Kumar
 
PPT
Introduction to data structures and Algorithm
Dhaval Kaneria
 
PPT
Cupdf.com introduction to-data-structures-and-algorithm
TarikuDabala1
 
PDF
Algorithms.pdf
OluwafolakeOjo
 
PPTX
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
PPTX
Chapter 1 Data structure.pptx
wondmhunegn
 
PPTX
Unit i basic concepts of algorithms
sangeetha s
 
PPTX
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
PPTX
Analysis of Algorithms_Under Graduate Class Slide
HanumatGSastry
 
PPTX
Module 1_ Introduction.pptx
nikshaikh786
 
PDF
DSA
rrupa2
 
PPT
Design and analysis of Algorithm By Dr. B. J. Mohite
Zeal Education Society, Pune
 
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
PPTX
Algorithm Basics sjkjsshsjsjkjskjsksjks.pptx
lkumar769
 
Unit 1, ADA.pptx
jinkhatima
 
Performance analysis and randamized agoritham
lilyMalar1
 
DAA-Introduction-Divide and Conquer Technique
sailaja156145
 
Data structures algorithms basics
ayeshasafdar8
 
2. Introduction to Algorithm.pptx
RahikAhmed1
 
Introduction to data structures and Algorithm
Dhaval Kaneria
 
Analysis of algorithn class 2
Kumar
 
Introduction to data structures and Algorithm
Dhaval Kaneria
 
Cupdf.com introduction to-data-structures-and-algorithm
TarikuDabala1
 
Algorithms.pdf
OluwafolakeOjo
 
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Chapter 1 Data structure.pptx
wondmhunegn
 
Unit i basic concepts of algorithms
sangeetha s
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
Analysis of Algorithms_Under Graduate Class Slide
HanumatGSastry
 
Module 1_ Introduction.pptx
nikshaikh786
 
DSA
rrupa2
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Zeal Education Society, Pune
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
Algorithm Basics sjkjsshsjsjkjskjsksjks.pptx
lkumar769
 
Ad

More from swapnac12 (20)

PPTX
Awt, Swing, Layout managers
swapnac12
 
PPTX
Applet
swapnac12
 
PPTX
Event handling
swapnac12
 
PPTX
Asymptotic notations(Big O, Omega, Theta )
swapnac12
 
PPTX
Introduction ,characteristics, properties,pseudo code conventions
swapnac12
 
PPTX
Inductive analytical approaches to learning
swapnac12
 
PPTX
Using prior knowledge to initialize the hypothesis,kbann
swapnac12
 
PPTX
Combining inductive and analytical learning
swapnac12
 
PPTX
Analytical learning
swapnac12
 
PPTX
Learning set of rules
swapnac12
 
PPTX
Learning rule of first order rules
swapnac12
 
PPTX
Genetic algorithms
swapnac12
 
PPTX
Instance based learning
swapnac12
 
PPTX
Computational learning theory
swapnac12
 
PPTX
Multilayer & Back propagation algorithm
swapnac12
 
PPTX
Artificial Neural Networks 1
swapnac12
 
PPTX
Evaluating hypothesis
swapnac12
 
PPTX
Advanced topics in artificial neural networks
swapnac12
 
PPTX
Introdution and designing a learning system
swapnac12
 
PPTX
Inductive bias
swapnac12
 
Awt, Swing, Layout managers
swapnac12
 
Applet
swapnac12
 
Event handling
swapnac12
 
Asymptotic notations(Big O, Omega, Theta )
swapnac12
 
Introduction ,characteristics, properties,pseudo code conventions
swapnac12
 
Inductive analytical approaches to learning
swapnac12
 
Using prior knowledge to initialize the hypothesis,kbann
swapnac12
 
Combining inductive and analytical learning
swapnac12
 
Analytical learning
swapnac12
 
Learning set of rules
swapnac12
 
Learning rule of first order rules
swapnac12
 
Genetic algorithms
swapnac12
 
Instance based learning
swapnac12
 
Computational learning theory
swapnac12
 
Multilayer & Back propagation algorithm
swapnac12
 
Artificial Neural Networks 1
swapnac12
 
Evaluating hypothesis
swapnac12
 
Advanced topics in artificial neural networks
swapnac12
 
Introdution and designing a learning system
swapnac12
 
Inductive bias
swapnac12
 
Ad

Recently uploaded (20)

PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
grade 5 lesson ENGLISH 5_Q1_PPT_WEEK3.pptx
SireQuinn
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
grade 5 lesson ENGLISH 5_Q1_PPT_WEEK3.pptx
SireQuinn
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 

Performance analysis(Time & Space Complexity)

  • 2. Performance of a program: • The performance of a program is the amount of computer memory and time needed to run a program. • We use two approaches to determine the performance of a program. • One is analytical, and the other experimental. In performance analysis we use analytical methods, while in performance measurement we conduct experiments. • Performance Analysis: • Performance Analysis of an algorithm depends upon 2 factors that is amount of memory used and amount computer time consumed on any CPU. • Space complexity, Time Complexity, Network ,Power, CPU Registers.
  • 3. Time Complexity • The time needed by an algorithm expressed as a function of the size of a problem is called the time complexity of the algorithm. The time complexity of a program is the amount of computer time it needs to run to completion. • Time=Fixed Time +Instance time. • Characteristics of compiler used to compile the program.{fixed}. • Computer Machine on which the program is executed and physically clocked.{variable} • Multiuser execution system. {variable} • Number of program steps. {variable} • The limiting behaviour of the complexity as size increases is called the asymptotic time complexity. It is the asymptotic complexity of an algorithm, which ultimately determines the size of problems that can be solved by the algorithm.
  • 4. •Comments count as zero steps. •As assignment statement which does not involve any calls to other algorithm is counted as one step, •For iterative statements we consider the steps count only for the control part of the statement etc. Calculate: Total no. of program steps= no. of steps per execution of the statement + frequency of each statement executed.
  • 5. Statement Steps for execution Frequen cy Total steps Algorithm sum ( number, size) 0 - 0 { 0 - 0 Result:=0.0 1 1 1 For count=1 to size do 1 size+1 size+1 result= result + number[count]; size size Return result; 1 1 1 } Total 2size+3 Time Complexity:
  • 9. Space Complexity • The space complexity of a program is the amount of memory it needs to run to completion i.e from start of execution to its termination. . • The space need by a program has the following components: • Fixed component + Variable component=space. • Fixed Component: Instruction space+ space of sample variable + constant variable. This is independent of input and output. • Variable component: space needed by compound variable whose size depend on input and output. EX: stack space, data structures like linked list, heap, trees graphs. • Instruction space: Instruction space is the space needed to store the compiled version of the program instructions. • Data space: Data space is the space needed to store all constant and variable values. Data space has two components: • Space needed by constants and simple variables in program. • Space needed by dynamically allocated objects such as arrays and class instances.
  • 10. Environment stack space: The environment stack is used to save information needed to resume execution of partially completed functions. Instruction Space: The amount of instructions space that is needed depends on factors such as: The compiler used to complete the program into machine code. The compiler options in effect at the time of compilation The target computer. To calculate: 1.Determine the variables which are instantiated by some default values. 2.Determine which instance characteristics should be used to measure the space requirement and this will be problem specific. 3.Generally the choices are limited to quantities related to the number and magnitudes of the inputs to and outputs from the algorithms. 4.Some times more complex measures of the inter realtionships among the data items can used.
  • 11. Ex: Algorithm Sum(number[], size) { result:=0.0; result-------------------1 word for count:=1 to size do count---------------1unit size------1 unit result:=result + number[count]; number[]----------n return result; } S(n)=3+n---------------O(n) Constant space complexity: Ex. Algorithm square(int a) a variable -----1 { return a*a;-------------s(n)=1}------------------O(1) Linear space complexity: Ex.int sum(int a[],int n) n variable ---1unit int sum=0; a---n units for(i=0;i<n;i++) i--------1 unit sum=sum+a[i]; sum--- 1 unit return sum } s(n)=n+3----------O(n)
  • 12. Ex: Algorithm Swap(a,b) Space Time { Temp=a: ---------1word 1 unit of Time a=b; ----------1 1 b=Temp; -------1 1 } s(n)=3 f(n)=3 Ex: Ex.int sum(int a[],int n) Space Time { n variable ---1unit int sum=0; a---n units 1 for(i=0;i<n;i++) { i--------1 unit n+1 sum=sum+a[i]; } sum--- 1 unit n return sum 1 } s(n)=n+3----------O(n) f(n)=2n+3-------O(n)
  • 13. Frequency Count Method Ex: Algorithm Add(A,B,n) Time Space { for(i=0;i<n;i++) n+1 A---n^2 { B---n^2 for(j=0;j<n;j++) n*(n+1) C---n^2 { n--1 C[i,j]=A[i,j]+B[i,j]; n*n i---1 } j---1 } f(n)=2n^2+2n+1 s(n)=3n^2+3 O(n^2) O(n^2)
  • 14. Ex: Algoritihm Multiply(A,B,n) Frequency Count Method { Time Space for(i0;i<n;i++) n+1 A----n^2 { B-----n^2 For(j=0;j<n;j++) n*n+1 C-----n^2 { n-----1 C[i,j]=0; n*n i-----1 for(k=0;k<n;k++) n*n*n+1 j----1 { k----1 C[i,j]=C[i,j]+A[i,k]*B[k,j]; n*n*n s(n)=3n^2+4 } f(n)=2n^3+3n^2+2n+1 O(n^2) } O(n^3) } }