SlideShare ist ein Scribd-Unternehmen logo
1 von 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>.

Weitere ähnliche Inhalte

Ähnlich wie (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
 

Mehr von 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
 

KĂźrzlich hochgeladen

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

KĂźrzlich hochgeladen (20)

Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system 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
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
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
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
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
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 

(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>.