SlideShare uma empresa Scribd logo
1 de 12
Dynamic Programming and the
Knapsack Problem
Paul Dohmen
Roshnika Fernando
What is Dynamic Programming
 Dynamic programming is a method of
solving complex problems by breaking
them down into sub-problems that can be
solved by working backwards from the last
stage.
 Coined by Richard Bellman who described
dynamic programming as the way of
solving problems where you need to find
the best decisions one after another
Dynamic Programming
Dynamic programming is a simple method
of solving complex real world problems,
such as
 Traveling salesman problem
 Fibonacci sequence
 Stagecoach problem
 Knapsack problem
Numerous other applications exist
Steps to Dynamic Programming
 Every problem is divided into stages
 Each stage requires a decision
 Decisions are made to determine the state of
the next stage
 The solution procedure is to find an optimal
solution at each stage for every possible
state
 This solution procedure often starts at the
last stage and works its way forward
Knapsack Problem
You are a mischievous child camping in the
woods. You would like to steal items from
other campers, but you can only carry so
much mass in your knapsack. You see seven
items worth stealing. Each
item has a certain mass and
monetary value. How do you
maximize your profit so you
can buy more video games
later?
Knapsack Problem
 Value and mass of
each item is given
 Maximize profit
 Subject to mass
constraint of
knapsack: 15 kg
 Being a smart kid,
you apply dynamic
programming
Smart Kids Write Equations
 There are potentially 7 stages to this dynamic
programming problem.
 When an item is placed in the knapsack, a decision,
F(m), is made to choose the next optimal item, i.
 Start at the end of the problem, assuming that the
knapsack has an unknown mass, m.
 Recurrence relation:
F(i,m) = max (F(i-1,m-mi) + fi, F(i-1, m))
 Use recursion and iterate through the problem,
eventually coming up with the optimal solution.
Smart Kids Use MatLab
 Now imagine you, the mischievous smart
thief kid, brought your laptop to the
camping trip. How would you solve the
equation? MATLAB!
 Matlab Solution:
 Profit: $21
 Mass: 15kg
 Not enough to buy a new video game
Solution
Sensitivity Analysis
 Valuables are not very valuable when camping,
pick richer people to steal from.
 Suddenly a valuable item of $15 that weighs
11kg is available, will the optimal solution
change?
Yes, the maximum profit becomes $23
 Using MatLab, it is easy to change the variables
on the program for specific sensitivity analysis
Questions?
Sources
 Petter. "MATLAB Central - File detail - 0-1 Knapsack." The
MathWorks - MATLAB and Simulink for Technical
Computing. Web. 03 Dec. 2009.
<http://www.mathworks.com/matlabcentral/fileexchang
e/22783-0-1-knapsack>.
 "Dynamic Programming Algorithms." Web. 03 Dec. 2009.
<http://www.personal.kent.edu/~rmuhamma/Algorithm
s/MyAlgorithms/Dynamic/knapsackdyn.htm>.
 "Dynamic programming ." Wikipedia, the free encyclopedia.
Web. 03 Dec. 2009.
<http://en.wikipedia.org/wiki/Dynamic_programming>.
 "Dynamic Programming: Definition and additional resources
from BNET." Glossary of Business Dictionary Terms | A |
BNET. Web. 02 Dec. 2009.
<http://dictionary.bnet.com/definition/dynamic+progra
mming.html>.

Mais conteúdo relacionado

Semelhante a (PAD_5)Dynamic_Programming.ppt (6)

Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Dynamicpgmming
DynamicpgmmingDynamicpgmming
Dynamicpgmming
 
Brief journey in the big world of Integer Programming with the Knapsack
Brief journey in the big world of Integer Programming with the KnapsackBrief journey in the big world of Integer Programming with the Knapsack
Brief journey in the big world of Integer Programming with the Knapsack
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 

Mais de mounikanarra3 (15)

unit-2.pdf
unit-2.pdfunit-2.pdf
unit-2.pdf
 
Unit - 4.pptx
Unit - 4.pptxUnit - 4.pptx
Unit - 4.pptx
 
UNIT-1 (4).pdf
UNIT-1 (4).pdfUNIT-1 (4).pdf
UNIT-1 (4).pdf
 
functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdf
 
travelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdftravelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdf
 
Space complexity-DAA.pptx
Space complexity-DAA.pptxSpace complexity-DAA.pptx
Space complexity-DAA.pptx
 
EEM MID2.PPT.pptx
EEM MID2.PPT.pptxEEM MID2.PPT.pptx
EEM MID2.PPT.pptx
 
MID2 UML (1).pptx
MID2 UML (1).pptxMID2 UML (1).pptx
MID2 UML (1).pptx
 
sequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdfsequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdf
 
UML.PPT.pptx
UML.PPT.pptxUML.PPT.pptx
UML.PPT.pptx
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
 
stephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdfstephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdf
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
routing.pptx
routing.pptxrouting.pptx
routing.pptx
 

Último

Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 

(PAD_5)Dynamic_Programming.ppt

  • 1. Dynamic Programming and the Knapsack Problem Paul Dohmen Roshnika Fernando
  • 2. What is Dynamic Programming  Dynamic programming is a method of solving complex problems by breaking them down into sub-problems that can be solved by working backwards from the last stage.  Coined by Richard Bellman who described dynamic programming as the way of solving problems where you need to find the best decisions one after another
  • 3. Dynamic Programming Dynamic programming is a simple method of solving complex real world problems, such as  Traveling salesman problem  Fibonacci sequence  Stagecoach problem  Knapsack problem Numerous other applications exist
  • 4. Steps to Dynamic Programming  Every problem is divided into stages  Each stage requires a decision  Decisions are made to determine the state of the next stage  The solution procedure is to find an optimal solution at each stage for every possible state  This solution procedure often starts at the last stage and works its way forward
  • 5. Knapsack Problem You are a mischievous child camping in the woods. You would like to steal items from other campers, but you can only carry so much mass in your knapsack. You see seven items worth stealing. Each item has a certain mass and monetary value. How do you maximize your profit so you can buy more video games later?
  • 6. Knapsack Problem  Value and mass of each item is given  Maximize profit  Subject to mass constraint of knapsack: 15 kg  Being a smart kid, you apply dynamic programming
  • 7. Smart Kids Write Equations  There are potentially 7 stages to this dynamic programming problem.  When an item is placed in the knapsack, a decision, F(m), is made to choose the next optimal item, i.  Start at the end of the problem, assuming that the knapsack has an unknown mass, m.  Recurrence relation: F(i,m) = max (F(i-1,m-mi) + fi, F(i-1, m))  Use recursion and iterate through the problem, eventually coming up with the optimal solution.
  • 8. Smart Kids Use MatLab  Now imagine you, the mischievous smart thief kid, brought your laptop to the camping trip. How would you solve the equation? MATLAB!  Matlab Solution:  Profit: $21  Mass: 15kg  Not enough to buy a new video game
  • 10. Sensitivity Analysis  Valuables are not very valuable when camping, pick richer people to steal from.  Suddenly a valuable item of $15 that weighs 11kg is available, will the optimal solution change? Yes, the maximum profit becomes $23  Using MatLab, it is easy to change the variables on the program for specific sensitivity analysis
  • 12. Sources  Petter. "MATLAB Central - File detail - 0-1 Knapsack." The MathWorks - MATLAB and Simulink for Technical Computing. Web. 03 Dec. 2009. <http://www.mathworks.com/matlabcentral/fileexchang e/22783-0-1-knapsack>.  "Dynamic Programming Algorithms." Web. 03 Dec. 2009. <http://www.personal.kent.edu/~rmuhamma/Algorithm s/MyAlgorithms/Dynamic/knapsackdyn.htm>.  "Dynamic programming ." Wikipedia, the free encyclopedia. Web. 03 Dec. 2009. <http://en.wikipedia.org/wiki/Dynamic_programming>.  "Dynamic Programming: Definition and additional resources from BNET." Glossary of Business Dictionary Terms | A | BNET. Web. 02 Dec. 2009. <http://dictionary.bnet.com/definition/dynamic+progra mming.html>.