SlideShare a Scribd company logo
3
Most read
6
Most read
10
Most read
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

PPT
Lecture 8 dynamic programming
PPTX
Binary search
PPT
Greedy algorithms
PPTX
Graph coloring using backtracking
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Breadth First Search & Depth First Search
PPTX
Single source Shortest path algorithm with example
PPT
Dynamic programming
Lecture 8 dynamic programming
Binary search
Greedy algorithms
Graph coloring using backtracking
SINGLE-SOURCE SHORTEST PATHS
Breadth First Search & Depth First Search
Single source Shortest path algorithm with example
Dynamic programming

What's hot (20)

PPTX
Unit 2 ai
DOC
Time and space complexity
PPTX
Analysis and Design of Algorithms
PPTX
heap Sort Algorithm
PDF
Binary Search - Design & Analysis of Algorithms
PPT
Sum of subsets problem by backtracking 
PDF
Heap and heapsort
PPTX
Rabin Karp ppt
PPTX
dynamic-programming
PPT
04 brute force
PPTX
PDF
Python programming : Arrays
PPTX
Galois field
PPTX
Binary Tree Traversal
PPTX
Join dependency
PPTX
Rabin Carp String Matching algorithm
PPT
Data Structures- Part5 recursion
PPTX
Packages In Python Tutorial
PPTX
NUMPY [Autosaved] .pptx
Unit 2 ai
Time and space complexity
Analysis and Design of Algorithms
heap Sort Algorithm
Binary Search - Design & Analysis of Algorithms
Sum of subsets problem by backtracking 
Heap and heapsort
Rabin Karp ppt
dynamic-programming
04 brute force
Python programming : Arrays
Galois field
Binary Tree Traversal
Join dependency
Rabin Carp String Matching algorithm
Data Structures- Part5 recursion
Packages In Python Tutorial
NUMPY [Autosaved] .pptx
Ad

Similar to Elements of Dynamic Programming (20)

PPTX
Module 2ppt.pptx divid and conquer method
PDF
L21_L27_Unit_5_Dynamic_Programming Computer Science
PPTX
Dynamic programming in Design Analysis and Algorithms
PPTX
Algorithm_Dynamic Programming
PDF
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
PPT
Dynamicpgmming
PPTX
Introduction to dynamic programming
PPTX
DYNAMIC_________________________PROGRAMMING.pptx
PPTX
ADA Unit 2.pptx
DOC
PROBLEM SOLVING TECHNIQUES
PPTX
Recursive Algorithms with their types and implementation
PPT
Dynamic programming 2
PPTX
CH-1.1 Introduction (1).pptx
PDF
Unit 4 of design and analysis of algorithms
PPTX
dinosourrrrrrrrrrrrrrrrrrrrrr formula .pptx
PPT
Dynamic pgmming
PPTX
Dynamic Programming.pptx
PPTX
Semi-Supervised (reinforcement) essentials
PPTX
Dynamic programming
PDF
Neural_Programmer_Interpreter
Module 2ppt.pptx divid and conquer method
L21_L27_Unit_5_Dynamic_Programming Computer Science
Dynamic programming in Design Analysis and Algorithms
Algorithm_Dynamic Programming
C users_mpk7_app_data_local_temp_plugtmp_plugin-week3recursive
Dynamicpgmming
Introduction to dynamic programming
DYNAMIC_________________________PROGRAMMING.pptx
ADA Unit 2.pptx
PROBLEM SOLVING TECHNIQUES
Recursive Algorithms with their types and implementation
Dynamic programming 2
CH-1.1 Introduction (1).pptx
Unit 4 of design and analysis of algorithms
dinosourrrrrrrrrrrrrrrrrrrrrr formula .pptx
Dynamic pgmming
Dynamic Programming.pptx
Semi-Supervised (reinforcement) essentials
Dynamic programming
Neural_Programmer_Interpreter
Ad

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Practice Questions on recent development part 1.pptx
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
DOCX
573137875-Attendance-Management-System-original
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPT
Project quality management in manufacturing
PPTX
Internship_Presentation_Final engineering.pptx
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PDF
Queuing formulas to evaluate throughputs and servers
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
OOP with Java - Java Introduction (Basics)
Practice Questions on recent development part 1.pptx
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Lesson 3_Tessellation.pptx finite Mathematics
573137875-Attendance-Management-System-original
Simulation of electric circuit laws using tinkercad.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
“Next-Gen AI: Trends Reshaping Our World”
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
ETO & MEO Certificate of Competency Questions and Answers
Project quality management in manufacturing
Internship_Presentation_Final engineering.pptx
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
Queuing formulas to evaluate throughputs and servers
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx

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