SlideShare a Scribd company logo
Mathematical analysis for
Recursive algorithms
Dr.K.Muthumanickam
Associate Professor/IT
Kongunadu College of Engineering and Technology
Tholur Patti, Thottiam Taluk
Trichy District – 621215, Tamilnadu
General Plan for Analyzing the
Time Efficiency of Recursive
Algorithms
1. Decide on a parameter (or parameters)
indicating an input’s size.
2. Identify the algorithm’s basic operation.
3. Check whether the number of times the basic
operation is executed can vary on different
inputs of the same size; if it can, the worst-case,
average-case, and best-case efficiencies must be
investigated separately.
4. Set up a recurrence relation, with an
appropriate initial condition, for the number
of times the basic operation is executed.
5. Solve the recurrence or, at least, ascertain the
order of growth of its solution.
Examples
• EXAMPLE 1 Compute the factorial function
F (n) = n! for an arbitrary nonnegative integer
n.
Solution:
Since
n!= 1 . . . . . (n − 1) . n = (n − 1)! . n for n ≥ 1
and 0!= 1 by definition,
we can compute
F (n) = F (n − 1) . n with the following recursive
algorithm.
Analysis of Recursive Algorithms
ALGORITHM F(n)
// Output: n!
if n = 0
return 1
else
return n × F(n-1)
• For simplicity, we consider n itself as an
indicator of this algorithm’s input size.
• The basic operation of the algorithm is
multiplication, whose number of executions
we denote M(n)
• To determine a solution uniquely, we need an
initial condition that tells us the value with
which the sequence starts.
• We can obtain this value by inspecting the
condition that makes the algorithm stop its
recursive calls:
if n = 0 return 1
• This tells us two things.
(1) since the calls stop when n = 0, the smallest
value of n and hence M(n) defined is 0.
(2) when n = 0, the algorithm performs no
multiplications.
• Therefore, the initial condition we are after is
• The recurrence relation and initial condition
for the algorithm’s number of multiplications
M(n):
• For solving recurrence relations, we use the
method of backward substitutions.
• After ith iteration
• Since it is specified for n = 0, we have to substitute
i = n in the pattern’s formula to get the ultimate result
of our backward substitutions
Example 2 - Tower of Hanoi
• In this puzzle, we have n disks of different sizes
that can slide onto any of three pegs. Initially, all
the disks are on the first peg in order of size, the
largest on the bottom and the smallest on top.
The goal is to move all the disks to the third peg,
using the second one as an auxiliary, if necessary.
We can move only one disk at a time, and it is
forbidden to place a larger disk on top of a
smaller one.
Tower of Hanoi
Tower of Hanoi
• To move n > 1 disks from peg 1 to peg 3 (with peg
2 as auxiliary),
• we first move recursively n − 1 disks from peg 1
to peg 2 (with peg 3 as auxiliary),
• then move the largest disk directly from peg 1 to
peg 3, and,
• finally, move recursively n − 1 disks from peg 2 to
peg 3 (using peg 1 as auxiliary).
• If n = 1, we simply move the single disk directly
from the source peg to the destination peg.
• Let us apply the general plan outlined above to
the Tower of Hanoi problem.
• The number of disks n is the input’s size
• Moving one disk as the algorithm’s basic
operation.
• The number of moves M(n) depends on n only,
and we get the following recurrence equation
for it:
Tower of Hanoi (contd.)
1
Recurrence relation for the number of moves M(n):
M(n) = 2M(n − 1) + 1 for n > 1
M(1) = 1
• We solve this recurrence by the same method
of backward substitutions:
• After i substitutions, we get
Hint: 2n−1 + 2n-2+…+2+1 = 2n-1
Since the initial condition is specified for n = 1, which is
achieved for i = n − 1, we get the following formula for
the solution to recurrence
Tower of Hanoi (contd.)
• Recursion tree (# of function calls)
n
n-1 n-1
n-2 n-2 n-2 n-2
… … …
2
1
1
2
1
1
2
1
1
2
1
1
• Input Size is n = 2k
• Basic operation is addition
• The number of additions made in computing
plus one more addition is
made by the algorithm to increase the
returned value by 1. This leads to the
recurrence
• Since the recursive calls end when n is equal
to 1 and there are no additions made
then, the initial condition is A(1) = 0.
Home Work
Algorithm Visualization
• In addition to the mathematical and empirical
analyses of algorithms, there is yet a third way
to study algorithms. It is called algorithm
visualization and can be defined as the use of
images to convey some useful information
about algorithms.
• That information can be a visual illustration of
an algorithm’s operation, of its performance
on different kinds of inputs, or of its execution
speed versus that of other algorithms for the
same problem.
• To accomplish this goal, an algorithm
visualization uses graphic elements—points,
line segments, two- or three-dimensional
bars, and so on—to represent some
“interesting events” in the algorithm’s
operation.
• There are two principal variations of algorithm
visualization:
1. Static algorithm visualization
2. Dynamic algorithm visualization, also called
algorithm animation
• Static algorithm visualization shows an
algorithm’s progress through a series of still
images. Algorithm animation, on the other
hand, shows a continuous, movie-like
presentation of an algorithm’s operations.
• Initial and final screens of a typical
visualization of a sorting algorithm using
the bar representation.
• Sorting out Sorting - Animation

More Related Content

What's hot

P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Concept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmConcept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithm
swapnac12
 
Decision Trees
Decision TreesDecision Trees
Decision Trees
Student
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
MOHAN MOHAN
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
missstevenson01
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
Rabia Khalid
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
State space search and Problem Solving techniques
State space search and Problem Solving techniquesState space search and Problem Solving techniques
State space search and Problem Solving techniques
Kirti Verma
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 

What's hot (20)

P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Concept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmConcept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithm
 
Decision Trees
Decision TreesDecision Trees
Decision Trees
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
State space search and Problem Solving techniques
State space search and Problem Solving techniquesState space search and Problem Solving techniques
State space search and Problem Solving techniques
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 

Similar to CS8451 - Design and Analysis of Algorithms

CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
Monika Choudhery
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
2022cspaawan12556
 
Slide2
Slide2Slide2
(1) collections algorithms
(1) collections algorithms(1) collections algorithms
(1) collections algorithms
Nico Ludwig
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
ChSreenivasuluReddy
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
jayavignesh86
 
02 Notes Divide and Conquer
02 Notes Divide and Conquer02 Notes Divide and Conquer
02 Notes Divide and Conquer
Andres Mendez-Vazquez
 
Lecture 3 complexity
Lecture 3 complexityLecture 3 complexity
Lecture 3 complexity
Madhu Niket
 
Ch1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdfCh1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdf
zoric99
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
B.Kirron Reddi
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
SSE_AndyLi
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
nourhandardeer3
 
Lecture 4 (1).pptx
Lecture 4 (1).pptxLecture 4 (1).pptx
Lecture 4 (1).pptx
workwithiec
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slides
mpurkeypile
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdf
ASMAALWADEE2
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
iqbalphy1
 

Similar to CS8451 - Design and Analysis of Algorithms (20)

CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
 
Slide2
Slide2Slide2
Slide2
 
(1) collections algorithms
(1) collections algorithms(1) collections algorithms
(1) collections algorithms
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
02 Notes Divide and Conquer
02 Notes Divide and Conquer02 Notes Divide and Conquer
02 Notes Divide and Conquer
 
Lecture 3 complexity
Lecture 3 complexityLecture 3 complexity
Lecture 3 complexity
 
Ch1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdfCh1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdf
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
 
Lecture 4 (1).pptx
Lecture 4 (1).pptxLecture 4 (1).pptx
Lecture 4 (1).pptx
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slides
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdf
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 

Recently uploaded

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 

Recently uploaded (20)

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 

CS8451 - Design and Analysis of Algorithms

  • 1. Mathematical analysis for Recursive algorithms Dr.K.Muthumanickam Associate Professor/IT Kongunadu College of Engineering and Technology Tholur Patti, Thottiam Taluk Trichy District – 621215, Tamilnadu
  • 2. General Plan for Analyzing the Time Efficiency of Recursive Algorithms 1. Decide on a parameter (or parameters) indicating an input’s size. 2. Identify the algorithm’s basic operation. 3. Check whether the number of times the basic operation is executed can vary on different inputs of the same size; if it can, the worst-case, average-case, and best-case efficiencies must be investigated separately.
  • 3. 4. Set up a recurrence relation, with an appropriate initial condition, for the number of times the basic operation is executed. 5. Solve the recurrence or, at least, ascertain the order of growth of its solution.
  • 4. Examples • EXAMPLE 1 Compute the factorial function F (n) = n! for an arbitrary nonnegative integer n. Solution: Since n!= 1 . . . . . (n − 1) . n = (n − 1)! . n for n ≥ 1 and 0!= 1 by definition, we can compute F (n) = F (n − 1) . n with the following recursive algorithm.
  • 5. Analysis of Recursive Algorithms ALGORITHM F(n) // Output: n! if n = 0 return 1 else return n × F(n-1)
  • 6. • For simplicity, we consider n itself as an indicator of this algorithm’s input size. • The basic operation of the algorithm is multiplication, whose number of executions we denote M(n)
  • 7. • To determine a solution uniquely, we need an initial condition that tells us the value with which the sequence starts. • We can obtain this value by inspecting the condition that makes the algorithm stop its recursive calls: if n = 0 return 1 • This tells us two things. (1) since the calls stop when n = 0, the smallest value of n and hence M(n) defined is 0. (2) when n = 0, the algorithm performs no multiplications.
  • 8. • Therefore, the initial condition we are after is • The recurrence relation and initial condition for the algorithm’s number of multiplications M(n): • For solving recurrence relations, we use the method of backward substitutions.
  • 9. • After ith iteration • Since it is specified for n = 0, we have to substitute i = n in the pattern’s formula to get the ultimate result of our backward substitutions
  • 10. Example 2 - Tower of Hanoi • In this puzzle, we have n disks of different sizes that can slide onto any of three pegs. Initially, all the disks are on the first peg in order of size, the largest on the bottom and the smallest on top. The goal is to move all the disks to the third peg, using the second one as an auxiliary, if necessary. We can move only one disk at a time, and it is forbidden to place a larger disk on top of a smaller one.
  • 13. • To move n > 1 disks from peg 1 to peg 3 (with peg 2 as auxiliary), • we first move recursively n − 1 disks from peg 1 to peg 2 (with peg 3 as auxiliary), • then move the largest disk directly from peg 1 to peg 3, and, • finally, move recursively n − 1 disks from peg 2 to peg 3 (using peg 1 as auxiliary). • If n = 1, we simply move the single disk directly from the source peg to the destination peg.
  • 14. • Let us apply the general plan outlined above to the Tower of Hanoi problem. • The number of disks n is the input’s size • Moving one disk as the algorithm’s basic operation. • The number of moves M(n) depends on n only, and we get the following recurrence equation for it:
  • 15. Tower of Hanoi (contd.) 1 Recurrence relation for the number of moves M(n): M(n) = 2M(n − 1) + 1 for n > 1 M(1) = 1
  • 16. • We solve this recurrence by the same method of backward substitutions: • After i substitutions, we get Hint: 2n−1 + 2n-2+…+2+1 = 2n-1
  • 17. Since the initial condition is specified for n = 1, which is achieved for i = n − 1, we get the following formula for the solution to recurrence
  • 18. Tower of Hanoi (contd.) • Recursion tree (# of function calls) n n-1 n-1 n-2 n-2 n-2 n-2 … … … 2 1 1 2 1 1 2 1 1 2 1 1
  • 19.
  • 20. • Input Size is n = 2k • Basic operation is addition • The number of additions made in computing plus one more addition is made by the algorithm to increase the returned value by 1. This leads to the recurrence • Since the recursive calls end when n is equal to 1 and there are no additions made then, the initial condition is A(1) = 0.
  • 21.
  • 23.
  • 24. Algorithm Visualization • In addition to the mathematical and empirical analyses of algorithms, there is yet a third way to study algorithms. It is called algorithm visualization and can be defined as the use of images to convey some useful information about algorithms.
  • 25. • That information can be a visual illustration of an algorithm’s operation, of its performance on different kinds of inputs, or of its execution speed versus that of other algorithms for the same problem. • To accomplish this goal, an algorithm visualization uses graphic elements—points, line segments, two- or three-dimensional bars, and so on—to represent some “interesting events” in the algorithm’s operation.
  • 26. • There are two principal variations of algorithm visualization: 1. Static algorithm visualization 2. Dynamic algorithm visualization, also called algorithm animation • Static algorithm visualization shows an algorithm’s progress through a series of still images. Algorithm animation, on the other hand, shows a continuous, movie-like presentation of an algorithm’s operations.
  • 27. • Initial and final screens of a typical visualization of a sorting algorithm using the bar representation.
  • 28.
  • 29.
  • 30. • Sorting out Sorting - Animation