SlideShare a Scribd company logo
Dynamic Programming
• Is a powerful design technique that can be
used to solve problems of a computational
nature
• Is typically applied to optimization
problems
• Note:- Programming in these term refers to a
tabular method.
Dynamic Programming
• Problem:
– The Palmia country is divided by a river into the north and south
bank. There are N towns on both the north and south bank.
Each town on the north bank has its unique friend town on the
south bank. No two towns have the same friend. Each pair of
friend towns would like to have a ship line connecting them.
They applied for permission to the government. Because it is
often foggy on the river the government decided to prohibit
intersection of ship lines (if two lines intersect there is a high
probability of ship crash).
Dynamic Programming
• Problem (in mathematical terms)
– There exists a sequences a1,, a2,… an and
b1,,b2,… bn such that
as < aj if s<j
bs < bj if s<j
for each s, there exists a s’ such that as and bs’
connected.
- Find the maximum value m such that there exist x1
<x2<x3 <… xm. m<=n such that
Dynamic Programming
• Example Problem
a: 2 4 9 10 15 17 22
b: 2 3 4 6 8 12 17
Dynamic Programming
• Example Problem
a: 2 4 9 10 15 17 22
b: 2 3 4 6 8 12 17
Dynamic Programming
• Simple Brute Force Algorithm
• Pick all possible sets of routes.
• Check if selection of routes is valid
Dynamic Programming
• Simple Brute Force Algorithm
(Analysis)
• Pick all possible sets of routes. …. O(2n)
possible routes
• Check if selection of routes is valid… O(n) time to check
• In total will take O(2n
* n) time.
• EXPONENTIAL TIME = SLOW!!!!!
Dynamic Programming
• Elegant Solution
• Let c(i,j) be the maximum possible routes
using the first i sequences in a, and j
sequences in b.
• We notice that c(I,j) is connected to c(i-
1,j), c(i,j-1) and c(i-1,j-1).
Dynamic Programming
RULE 1 of Dynamic Programing
We notice that if a[i] = b[j] (connected), then we can use them in our solution and
optimal solution becomes c[i-1,j-1]+1(because we just used a new route).
In all other cases, we just consider the case where we do not use b[j] (i.e c[i,j-1])
or we do not use a[i] (i.e c[i-1,j]
Dynamic Programming
Dynamic Programming
Dynamic Programming
Dynamic Programming
Dynamic Programming
RULE 2 of Dynamic Programing
Dynamic Programming
Dynamic Programming
RULE 3 of Dynamic Programing

More Related Content

PDF
Traffic congestion2
PPTX
Past 120 2[1]
PDF
MIMO Capacity and Duality Between MAC and BC
PDF
PPTX
L channel qmf bank
PPT
Math(F5) Gradient And Area Under A Graph 6.2
PDF
Research_Presentation
PDF
[Question Paper] Computer Graphics (Old Course) [September / 2013]
Traffic congestion2
Past 120 2[1]
MIMO Capacity and Duality Between MAC and BC
L channel qmf bank
Math(F5) Gradient And Area Under A Graph 6.2
Research_Presentation
[Question Paper] Computer Graphics (Old Course) [September / 2013]

Similar to Dynamic programming (20)

PPTX
Dynamic programming
PPTX
Module 2ppt.pptx divid and conquer method
PPT
Dynamic pgmming
PPTX
Dynamic Programing.pptx good for understanding
PPTX
Dynamic programming class 16
PDF
L21_L27_Unit_5_Dynamic_Programming Computer Science
PPT
Dynamicpgmming
PPT
5.3 dynamic programming 03
PPTX
Dynamic programming prasintation eaisy
PPTX
Dynamic Programming - Part 1
PPTX
ADA Unit 2.pptx
PDF
Unit 4 of design and analysis of algorithms
PDF
Lecture+9+-+Dynamic+Programming+I.pdf
PPTX
Introduction to Dynamic Programming, Principle of Optimality
PPT
Algorithm lecture Dynamic programming
PPT
dynamic-programming unit 3 power point presentation
PPTX
Dynamic programmng2
PDF
Unit 4 DSA along with DATA Science And it's logical reasoning.
PPTX
DynamicProgramming.pptx
PPTX
Introduction to dynamic programming
Dynamic programming
Module 2ppt.pptx divid and conquer method
Dynamic pgmming
Dynamic Programing.pptx good for understanding
Dynamic programming class 16
L21_L27_Unit_5_Dynamic_Programming Computer Science
Dynamicpgmming
5.3 dynamic programming 03
Dynamic programming prasintation eaisy
Dynamic Programming - Part 1
ADA Unit 2.pptx
Unit 4 of design and analysis of algorithms
Lecture+9+-+Dynamic+Programming+I.pdf
Introduction to Dynamic Programming, Principle of Optimality
Algorithm lecture Dynamic programming
dynamic-programming unit 3 power point presentation
Dynamic programmng2
Unit 4 DSA along with DATA Science And it's logical reasoning.
DynamicProgramming.pptx
Introduction to dynamic programming
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Classroom Observation Tools for Teachers
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
GDM (1) (1).pptx small presentation for students
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Cell Structure & Organelles in detailed.
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
A systematic review of self-coping strategies used by university students to ...
Classroom Observation Tools for Teachers
Abdominal Access Techniques with Prof. Dr. R K Mishra
GDM (1) (1).pptx small presentation for students
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Cell Structure & Organelles in detailed.
Ad

Dynamic programming

  • 1. Dynamic Programming • Is a powerful design technique that can be used to solve problems of a computational nature • Is typically applied to optimization problems • Note:- Programming in these term refers to a tabular method.
  • 2. Dynamic Programming • Problem: – The Palmia country is divided by a river into the north and south bank. There are N towns on both the north and south bank. Each town on the north bank has its unique friend town on the south bank. No two towns have the same friend. Each pair of friend towns would like to have a ship line connecting them. They applied for permission to the government. Because it is often foggy on the river the government decided to prohibit intersection of ship lines (if two lines intersect there is a high probability of ship crash).
  • 3. Dynamic Programming • Problem (in mathematical terms) – There exists a sequences a1,, a2,… an and b1,,b2,… bn such that as < aj if s<j bs < bj if s<j for each s, there exists a s’ such that as and bs’ connected. - Find the maximum value m such that there exist x1 <x2<x3 <… xm. m<=n such that
  • 4. Dynamic Programming • Example Problem a: 2 4 9 10 15 17 22 b: 2 3 4 6 8 12 17
  • 5. Dynamic Programming • Example Problem a: 2 4 9 10 15 17 22 b: 2 3 4 6 8 12 17
  • 6. Dynamic Programming • Simple Brute Force Algorithm • Pick all possible sets of routes. • Check if selection of routes is valid
  • 7. Dynamic Programming • Simple Brute Force Algorithm (Analysis) • Pick all possible sets of routes. …. O(2n) possible routes • Check if selection of routes is valid… O(n) time to check • In total will take O(2n * n) time. • EXPONENTIAL TIME = SLOW!!!!!
  • 8. Dynamic Programming • Elegant Solution • Let c(i,j) be the maximum possible routes using the first i sequences in a, and j sequences in b. • We notice that c(I,j) is connected to c(i- 1,j), c(i,j-1) and c(i-1,j-1).
  • 9. Dynamic Programming RULE 1 of Dynamic Programing
  • 10. We notice that if a[i] = b[j] (connected), then we can use them in our solution and optimal solution becomes c[i-1,j-1]+1(because we just used a new route). In all other cases, we just consider the case where we do not use b[j] (i.e c[i,j-1]) or we do not use a[i] (i.e c[i-1,j] Dynamic Programming
  • 14. Dynamic Programming RULE 2 of Dynamic Programing
  • 16. Dynamic Programming RULE 3 of Dynamic Programing