SlideShare a Scribd company logo
University Visvesvaraya College Of Engineering,
Bengaluru-01
TOPIC
ON
ELEMENTS OF DYNAMIC PROGRAMMING
Presented by
VISHWAJEET SHABADI
20GACS2014,
Branch: Information Technology,
UVCE, Bengaluru.
Under The Guidance of
Dr. Venkatesh
Professor,
Dept. of CSE,
UVCE, Bengaluru.
INTRODUCTION OF DYNAMIC PROGRAMMING
• Dynamic Programming is the most powerful design technique
for solving optimization problems. Example: Matrix Chain
Multiplication.
• Dynamic Programming is a Bottom-up approach.
• We typically apply dynamic programming to optimization
problems.
CHARACTERISTICS OF DYNAMIC PROGRAMMING
• Optimal Substructure: If an optimal solution contains
optimal sub solutions then a problem exhibits optimal
substructure. Example: Bellman-Ford
• Overlapping subproblems: When a recursive algorithm
would visit the same subproblems repeatedly, then a
has overlapping subproblems. Example: Fibonacci
Series
OPTIMAL SUBSTRUCTURE
• A given problems has Optimal Substructure Property if optimal
solution of the given problem can be obtained by using optimal
solutions of its subproblems.
• The Shortest Path problem has following Optimal Substructure
property:
If a node x lies in the shortest path from source node u to destination
node v then, the shortest path from u to v is the combination of shortest
path from u to x and shortest path from x to v.
• All Pair Shortest Path
ON THE OTHER HAND
• The Longest path problem doesn’t have the Optimal Substructure
property.
• Here, by Longest Path we mean longest simple path(path without
cycle) between two nodes.
• Longest paths from q to t:
q -> r -> t
q -> s -> t
• Longest path from q to r:
q -> s -> t -> r
• Longest path from r to t:
OVERLAPPING SUBPROBLEMS
• Dynamic Programming is mainly used when solutions of same
subproblems are needed again and again.
• If we take an example of following recursive program for Fibonacci
Numbers, there are many subproblems which are solved again and
again.
USE MEMORY
• “Remember the results.”
• Do not solve the same problem again, just recall it from
• Two methods of storing the results in memory:
Memoization
Tabulation
MEMOIZATION
• Initialize a lookup array/table with all its elements as NIL.
NIL is simply a constant value, that signifies absence of a solution.
• Call the recursive function f(n) to solve for ‘n’ using memoization.
MEMOIZATION
• At every step i, f(i) performs the following steps:
1. Checks whether table[i] is NIL or not.
2. If it’s not NIL, f(i) returns the value ‘table[i]’.
3. If it’s NIL and ‘i’ satisfies the base condition, we update the lookup table with
the base value and return the same.
4. If it’s NIL and ‘i’ does not satisfy the base condition, then f(i) splits the
problem ‘i’ into subproblems and recursively calls itself to solve them.
5. After the recursive calls return, f(i) combines the solution to subproblems,
update the lookup table and returns the solution for problem ‘i’.
MEMOIZATION
MEMOIZATION
MEMOIZATION
MEMOIZATION
MEMOIZATION
MEMOIZATION
MEMOIZATION
TABULATION
• STEPS
a. We begin with initializing the base values of ‘i’.
b. Next, we run a loop that iterates over the remaining
c. At every iteration i, f(n) updates the ith entry in the
by combining the solutions to previously solved
d. Finally, f(n) returns table[n].
TABULATION
int fib(int n){
if(n <= 1)
return n;
f[0] = 0; f[1] = 1;
for(int i = 2; I <= n; i++){
f[i] = f[i-2] + f[i-1];
}
return n;
}
PERFORMANCE
• Time taken for calculating the 40th Fibonacci number:
1. Recursive: 14 seconds
2. Memoization: 0.17 seconds
3. Tabulation: 0.30 seconds
THANK
YOU!

More Related Content

What's hot

simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
kanikkk
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
Brute force method
Brute force methodBrute force method
Brute force method
priyankabhansali217
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
Abhimanyu Mishra
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Self-Employed
 
Knowledge based agents
Knowledge based agentsKnowledge based agents
Knowledge based agents
Dr. C.V. Suresh Babu
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
vikas dhakane
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
vikas dhakane
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
Mohammad Ilyas Malik
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
Harry Potter
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
Divya Ks
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
Alokeparna Choudhury
 

What's hot (20)

simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Brute force method
Brute force methodBrute force method
Brute force method
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Knowledge based agents
Knowledge based agentsKnowledge based agents
Knowledge based agents
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
 

Similar to Elements of Dynamic Programming

Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursiveC  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
rokiah64
 
Dynamicpgmming
DynamicpgmmingDynamicpgmming
Dynamicpgmming
Muhammad Wasif
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
Amisha Narsingani
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
AmanKumar879992
 
PROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUESPROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUES
sudhanagarajan5
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2
Roy Thomas
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
Dr. C.V. Suresh Babu
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
MuktarHossain13
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
Neural_Programmer_Interpreter
Neural_Programmer_InterpreterNeural_Programmer_Interpreter
Neural_Programmer_Interpreter
Katy Lee
 
QA CHAPTER II.pptx
QA CHAPTER II.pptxQA CHAPTER II.pptx
QA CHAPTER II.pptx
Teshome48
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
Kumar
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
SURBHI SAROHA
 
DP Project Report
DP Project ReportDP Project Report
DP Project Report
Chawal Ukesh
 
EssentialsOfMachineLearning.pdf
EssentialsOfMachineLearning.pdfEssentialsOfMachineLearning.pdf
EssentialsOfMachineLearning.pdf
Ankita Tiwari
 
Derivative Free Optimization and Robust Optimization
Derivative Free Optimization and Robust OptimizationDerivative Free Optimization and Robust Optimization
Derivative Free Optimization and Robust Optimization
SSA KPI
 

Similar to Elements of Dynamic Programming (20)

Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
 
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursiveC  users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
 
Dynamicpgmming
DynamicpgmmingDynamicpgmming
Dynamicpgmming
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
 
PROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUESPROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUES
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Neural_Programmer_Interpreter
Neural_Programmer_InterpreterNeural_Programmer_Interpreter
Neural_Programmer_Interpreter
 
QA CHAPTER II.pptx
QA CHAPTER II.pptxQA CHAPTER II.pptx
QA CHAPTER II.pptx
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
 
DP Project Report
DP Project ReportDP Project Report
DP Project Report
 
EssentialsOfMachineLearning.pdf
EssentialsOfMachineLearning.pdfEssentialsOfMachineLearning.pdf
EssentialsOfMachineLearning.pdf
 
Derivative Free Optimization and Robust Optimization
Derivative Free Optimization and Robust OptimizationDerivative Free Optimization and Robust Optimization
Derivative Free Optimization and Robust Optimization
 

Recently uploaded

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
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
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
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
 
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
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 

Recently uploaded (20)

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
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...
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
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...
 
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
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 

Elements of Dynamic Programming

  • 1. University Visvesvaraya College Of Engineering, Bengaluru-01 TOPIC ON ELEMENTS OF DYNAMIC PROGRAMMING Presented by VISHWAJEET SHABADI 20GACS2014, Branch: Information Technology, UVCE, Bengaluru. Under The Guidance of Dr. Venkatesh Professor, Dept. of CSE, UVCE, Bengaluru.
  • 2. INTRODUCTION OF DYNAMIC PROGRAMMING • Dynamic Programming is the most powerful design technique for solving optimization problems. Example: Matrix Chain Multiplication. • Dynamic Programming is a Bottom-up approach. • We typically apply dynamic programming to optimization problems.
  • 3. CHARACTERISTICS OF DYNAMIC PROGRAMMING • Optimal Substructure: If an optimal solution contains optimal sub solutions then a problem exhibits optimal substructure. Example: Bellman-Ford • Overlapping subproblems: When a recursive algorithm would visit the same subproblems repeatedly, then a has overlapping subproblems. Example: Fibonacci Series
  • 4. OPTIMAL SUBSTRUCTURE • A given problems has Optimal Substructure Property if optimal solution of the given problem can be obtained by using optimal solutions of its subproblems. • The Shortest Path problem has following Optimal Substructure property: If a node x lies in the shortest path from source node u to destination node v then, the shortest path from u to v is the combination of shortest path from u to x and shortest path from x to v. • All Pair Shortest Path
  • 5. ON THE OTHER HAND • The Longest path problem doesn’t have the Optimal Substructure property. • Here, by Longest Path we mean longest simple path(path without cycle) between two nodes. • Longest paths from q to t: q -> r -> t q -> s -> t • Longest path from q to r: q -> s -> t -> r • Longest path from r to t:
  • 6. OVERLAPPING SUBPROBLEMS • Dynamic Programming is mainly used when solutions of same subproblems are needed again and again. • If we take an example of following recursive program for Fibonacci Numbers, there are many subproblems which are solved again and again.
  • 7. USE MEMORY • “Remember the results.” • Do not solve the same problem again, just recall it from • Two methods of storing the results in memory: Memoization Tabulation
  • 8. MEMOIZATION • Initialize a lookup array/table with all its elements as NIL. NIL is simply a constant value, that signifies absence of a solution. • Call the recursive function f(n) to solve for ‘n’ using memoization.
  • 9. MEMOIZATION • At every step i, f(i) performs the following steps: 1. Checks whether table[i] is NIL or not. 2. If it’s not NIL, f(i) returns the value ‘table[i]’. 3. If it’s NIL and ‘i’ satisfies the base condition, we update the lookup table with the base value and return the same. 4. If it’s NIL and ‘i’ does not satisfy the base condition, then f(i) splits the problem ‘i’ into subproblems and recursively calls itself to solve them. 5. After the recursive calls return, f(i) combines the solution to subproblems, update the lookup table and returns the solution for problem ‘i’.
  • 17. TABULATION • STEPS a. We begin with initializing the base values of ‘i’. b. Next, we run a loop that iterates over the remaining c. At every iteration i, f(n) updates the ith entry in the by combining the solutions to previously solved d. Finally, f(n) returns table[n].
  • 18. TABULATION int fib(int n){ if(n <= 1) return n; f[0] = 0; f[1] = 1; for(int i = 2; I <= n; i++){ f[i] = f[i-2] + f[i-1]; } return n; }
  • 19. PERFORMANCE • Time taken for calculating the 40th Fibonacci number: 1. Recursive: 14 seconds 2. Memoization: 0.17 seconds 3. Tabulation: 0.30 seconds