SlideShare a Scribd company logo
DESIGN TECHNIQUE
Example / Problem
Algorithm Design
Technique
Dynamic Programing
0/1 Dynamic Programming
Knapsack Problem
Dynamic Programming
Technique
 Dynamic Programming is a technique in computer programming
that helps to efficiently solve a class of problems that have
overlapping subproblems and optimal substructure property.
 If any problem can be divided into subproblems, which in turn
are divided into smaller subproblems, and if there are overlapping
among these subproblems, then the solutions to these
subproblems can be saved for future reference. In this way,
efficiency of the CPU can be enhanced. This method of solving a
solution is referred to as dynamic programming.
0/1 DP KNAPSACK PROBLEM
• Knapsack is basically means bag. A bag of given capacity. We want to pack n
items in your luggage.
• Input:
Knapsack of capacity
List (Array) of weight and their corresponding value.
• Output: To maximize profit and minimize weight in capacity.
The knapsack problem where we have to pack the knapsack with
maximum value in such a manner that the total weight of the items should not
be greater than the capacity of the knapsack.
0/1 DP KNAPSACK PROBLEM
Weights
• Items –
Profit
Bag = Weight = ? Kg. W
1) 0/1 Problem
0 or 1 Suppose,
2 Kg
1Kg 2kg
DP Method
2) Fractional Problem
Suppose,
3 Kg
2 Kg 1 Kg
Greedy Method
Example of 0/1 DP Knapsack
Problem
• Consider the following instance of knapsack problem
N = 4 , Weights = { 3, 4, 6, 5}
W = 8 , Profits (Values) = { 2, 3, 1, 4}
Find out the optimal solution for the given
instance.
Given: Weights = { 3, 4, 6, 5},
Profits (Values) = { 2, 3, 1, 4},
W = 8 ,
N = 4 .
Solution:
N = 4 , WEIGHTS = { 3, 4, 6, 5}
W = 8 , PROFITS (VALUES) = { 2, 3, 1, 4}
W
I
Pi Wi
2 3
3 4
4 5
1 6
0
1
2
3
4
0 1 2 3 4 5 6 7 8
0 0 0 0 0 0 0 0 0
0
0
0
0
0
0
0
0
0
0
0
0
2 2
2
2
2
2 2 2 2
3
3
3
3
4
4
3
4
4
5 5
5 6
5 6
M
Algorithm of Knapsack Problem
Dynamic-0-1-knapsack (v, w, n, W)
{
for w = 0 to W do
c[0, w] = 0
for i = 1 to n do
c[i, 0] = 0
for w = 1 to W do
if wi ≤ w then
if vi + c[i-1, w-wi] then
c[i, w] = vi + c[i-1, w-wi]
else c[i, w] = c[i-1, w]
else
c[i, w] = c[i-1, w]
}
Python Program for 0/1 DP Knapsack Problem
Time Complexity of 0/1 DP Knapsack Problem
Complexity Analysis
Time Complexity: O(N*W).
where ‘N’ is the number of weight element and ‘W’ is capacity.
• As for every weight element we traverse through all weight
capacities 1<=w<=W.
• Auxiliary Space: O(N*W).
The use of 2-D array of size ‘N*W’.
Thank You

More Related Content

What's hot

knapsack problem
knapsack problemknapsack problem
knapsack problem
Adnan Malak
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programming
khush_boo31
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnewabhinav108
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
i i
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
Ridhima Chowdhury
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
NagajothiN1
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
Vikas Sharma
 
Job sequencing with Deadlines
Job sequencing with DeadlinesJob sequencing with Deadlines
Job sequencing with Deadlines
YashiUpadhyay3
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
harsh kothari
 
Greedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. MohiteGreedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
Amin Omi
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Automata theory
Automata theoryAutomata theory
Automata theory
Pardeep Vats
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
padmeshagrekar
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16Kumar
 

What's hot (20)

Backtracking
BacktrackingBacktracking
Backtracking
 
knapsack problem
knapsack problemknapsack problem
knapsack problem
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programming
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnew
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Job sequencing with Deadlines
Job sequencing with DeadlinesJob sequencing with Deadlines
Job sequencing with Deadlines
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Greedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. MohiteGreedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. Mohite
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
 

Similar to 0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM

Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
Paras Patel
 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptx
Akswant
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
RacksaviR
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
Abhishek Singh
 
Presentation of knapsack
Presentation of knapsackPresentation of knapsack
Presentation of knapsack
Gaurav Dubey
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
dakccse
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Melaku Bayih Demessie
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
Shiwani Gupta
 
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
🌳 Olivier Pirson — OPi 🇧🇪🇫🇷🇬🇧 🐧 👨‍💻 👨‍🔬
 
knapsack.pptx
knapsack.pptxknapsack.pptx
knapsack.pptx
RajeshRaju301414
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
Mohanlal Sukhadia University (MLSU)
 
OptimumEngineeringDesign-Day-1.pdf
OptimumEngineeringDesign-Day-1.pdfOptimumEngineeringDesign-Day-1.pdf
OptimumEngineeringDesign-Day-1.pdf
SantiagoGarridoBulln
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
BinayakMukherjee4
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
AnkitaVerma776806
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic Programming
Editor IJCTER
 
5617723.pptx
5617723.pptx5617723.pptx
5617723.pptx
MatthewMhlongo
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
David Hoen
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
Harry Potter
 

Similar to 0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM (20)

Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptx
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
 
Presentation of knapsack
Presentation of knapsackPresentation of knapsack
Presentation of knapsack
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
 
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
 
knapsack.pptx
knapsack.pptxknapsack.pptx
knapsack.pptx
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
OptimumEngineeringDesign-Day-1.pdf
OptimumEngineeringDesign-Day-1.pdfOptimumEngineeringDesign-Day-1.pdf
OptimumEngineeringDesign-Day-1.pdf
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic Programming
 
5617723.pptx
5617723.pptx5617723.pptx
5617723.pptx
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 
Prolog resume
Prolog resumeProlog resume
Prolog resume
 

Recently uploaded

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
ambekarshweta25
 
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
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
itech2017
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 

Recently uploaded (20)

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
 
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
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 

0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM

  • 1.
  • 2. DESIGN TECHNIQUE Example / Problem Algorithm Design Technique Dynamic Programing 0/1 Dynamic Programming Knapsack Problem
  • 3. Dynamic Programming Technique  Dynamic Programming is a technique in computer programming that helps to efficiently solve a class of problems that have overlapping subproblems and optimal substructure property.  If any problem can be divided into subproblems, which in turn are divided into smaller subproblems, and if there are overlapping among these subproblems, then the solutions to these subproblems can be saved for future reference. In this way, efficiency of the CPU can be enhanced. This method of solving a solution is referred to as dynamic programming.
  • 4. 0/1 DP KNAPSACK PROBLEM • Knapsack is basically means bag. A bag of given capacity. We want to pack n items in your luggage. • Input: Knapsack of capacity List (Array) of weight and their corresponding value. • Output: To maximize profit and minimize weight in capacity. The knapsack problem where we have to pack the knapsack with maximum value in such a manner that the total weight of the items should not be greater than the capacity of the knapsack.
  • 5. 0/1 DP KNAPSACK PROBLEM Weights • Items – Profit Bag = Weight = ? Kg. W 1) 0/1 Problem 0 or 1 Suppose, 2 Kg 1Kg 2kg DP Method 2) Fractional Problem Suppose, 3 Kg 2 Kg 1 Kg Greedy Method
  • 6. Example of 0/1 DP Knapsack Problem • Consider the following instance of knapsack problem N = 4 , Weights = { 3, 4, 6, 5} W = 8 , Profits (Values) = { 2, 3, 1, 4} Find out the optimal solution for the given instance. Given: Weights = { 3, 4, 6, 5}, Profits (Values) = { 2, 3, 1, 4}, W = 8 , N = 4 .
  • 7. Solution: N = 4 , WEIGHTS = { 3, 4, 6, 5} W = 8 , PROFITS (VALUES) = { 2, 3, 1, 4} W I Pi Wi 2 3 3 4 4 5 1 6 0 1 2 3 4 0 1 2 3 4 5 6 7 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 3 3 3 3 4 4 3 4 4 5 5 5 6 5 6 M
  • 8. Algorithm of Knapsack Problem Dynamic-0-1-knapsack (v, w, n, W) { for w = 0 to W do c[0, w] = 0 for i = 1 to n do c[i, 0] = 0 for w = 1 to W do if wi ≤ w then if vi + c[i-1, w-wi] then c[i, w] = vi + c[i-1, w-wi] else c[i, w] = c[i-1, w] else c[i, w] = c[i-1, w] }
  • 9. Python Program for 0/1 DP Knapsack Problem
  • 10. Time Complexity of 0/1 DP Knapsack Problem Complexity Analysis Time Complexity: O(N*W). where ‘N’ is the number of weight element and ‘W’ is capacity. • As for every weight element we traverse through all weight capacities 1<=w<=W. • Auxiliary Space: O(N*W). The use of 2-D array of size ‘N*W’.