SlideShare a Scribd company logo
1 of 39
[object Object],[object Object],[object Object]
Review: Dynamic programming ,[object Object],[object Object],[object Object],[object Object],[object Object]
Properties of a problem that can be solved with dynamic programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Review:  Longest Common Subsequence (LCS) ,[object Object],[object Object],[object Object],[object Object]
Review:  Longest Common Subsequence (LCS) continued ,[object Object],[object Object],[object Object],[object Object],c[m,n] is the final solution
Review:  Longest Common Subsequence (LCS) ,[object Object],[object Object]
0-1 Knapsack problem ,[object Object],[object Object],[object Object]
0-1 Knapsack problem: a picture w i b i 10 9 8 5 5 4 4 3 3 2 Weight Benefit value This is a knapsack Max weight: W = 20 Items W = 20
0-1 Knapsack problem ,[object Object],[object Object],[object Object]
0-1 Knapsack problem: brute-force approach ,[object Object],[object Object],[object Object],[object Object]
0-1 Knapsack problem: brute-force approach ,[object Object],[object Object],[object Object],Let’s try this: If items are labeled  1..n , then a subproblem  would be to find an optimal solution for  S k  = {items labeled 1, 2, .. k}
Defining a Subproblem  ,[object Object],[object Object],[object Object],[object Object]
Defining a Subproblem Max weight: W = 20 For S 4 : Total weight: 14; total benefit: 20 w i b i 10 8 5 5 4 4 3 3 2 Weight Benefit 9 Item # 4 3 2 1 5 S 4 S 5 For S 5 : Total weight: 20 total benefit: 26 Solution for S 4  is not part of the solution for S 5 !!! ? w 1  =2 b 1  =3 w 2  =4 b 2  =5 w 3  =5 b 3  =8 w 4  =3 b 4  =4 w 1  =2 b 1  =3 w 2  =4 b 2  =5 w 3  =5 b 3  =8 w 4  =9 b 4  =10
Defining a Subproblem (continued) ,[object Object],[object Object],[object Object],[object Object]
Recursive Formula for subproblems ,[object Object],[object Object],[object Object],[object Object]
Recursive Formula ,[object Object],[object Object],[object Object]
0-1 Knapsack Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Running time ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What is the running time of this algorithm? O(W) O(W) Repeat  n  times O(n*W) Remember that the brute-force algorithm  takes O(2 n )
Example Let’s run our algorithm on the  following data: n = 4 (# of elements) W = 5 (max weight) Elements (weight, benefit): (2,3), (3,4), (4,5), (5,6)
Example (2) for w = 0 to W B[0,w] = 0 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 4
Example (3) for i = 0 to n B[i,0] = 0 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 4
Example (4) if w i  <= w  // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else  B[i,w] = B[i-1,w]   // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 1 w-w i  =-1 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0
Example (5) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 2 w-w i  =0 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3
Example (6) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 3 w-w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3
Example (7) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 4 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3
Example (8) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 5 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3
Example (9) if w i  <= w  // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else   B[i,w] = B[i-1,w]   // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 1 w-w i =-2 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0
Example (10) if w i  <= w  // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else   B[i,w] = B[i-1,w]   // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 2 w-w i =-1 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0 3
Example (11) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 3 w-w i =0 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0 3 4
Example (12) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 4 w-w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0 3 4 4
Example (13) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 5 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0 3 4 4 7
Example (14) if w i  <= w  // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else   B[i,w] = B[i-1,w]   // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 1..3 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 3 3 3 3 0 0 3 4 4 7 0 3 4
Example (15) if  w i  <= w   // item i can be part of the solution if  b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 4 w- w i =0 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 3 3 3 3
Example (15) if  w i  <= w   // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 5 w- w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 3 3 3 3
Example (16) if w i  <= w  // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else  B[i,w] = B[i-1,w]   // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 1..4 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 0 3 4 5 3 3 3 3
Example (17) if  w i  <= w   // item i can be part of the solution if b i  + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i  + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w]  // w i  > w  0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 5 Items: 1: (2,3) 2: (3,4) 3: (4,5)  4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 0 3 4 5 7 3 3 3 3
Comments ,[object Object],[object Object],[object Object]
Conclusion ,[object Object],[object Object],[object Object],[object Object],[object Object]
The End

More Related Content

What's hot

Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack DynamicParas Patel
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEMi i
 
Presentation of knapsack
Presentation of knapsackPresentation of knapsack
Presentation of knapsackGaurav Dubey
 
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...IOSR Journals
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups mathsjournal
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.Alexander Decker
 
Neutrosophic Soft Topological Spaces on New Operations
Neutrosophic Soft Topological Spaces on New OperationsNeutrosophic Soft Topological Spaces on New Operations
Neutrosophic Soft Topological Spaces on New OperationsIJSRED
 
Integration 2 elur niahc
Integration 2 elur niahcIntegration 2 elur niahc
Integration 2 elur niahcShaun Wilson
 
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDFACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDZac Darcy
 
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEMMrunal Patil
 
On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems ijcax
 

What's hot (20)

Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
Presentation of knapsack
Presentation of knapsackPresentation of knapsack
Presentation of knapsack
 
Knapsack dp
Knapsack dpKnapsack dp
Knapsack dp
 
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
Simultaneous Triple Series Equations Involving Konhauser Biorthogonal Polynom...
 
0-1 knapsack problem
0-1 knapsack problem0-1 knapsack problem
0-1 knapsack problem
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.
 
Neutrosophic Soft Topological Spaces on New Operations
Neutrosophic Soft Topological Spaces on New OperationsNeutrosophic Soft Topological Spaces on New Operations
Neutrosophic Soft Topological Spaces on New Operations
 
Indefinite Integral 18
Indefinite Integral 18Indefinite Integral 18
Indefinite Integral 18
 
Integration 2 elur niahc
Integration 2 elur niahcIntegration 2 elur niahc
Integration 2 elur niahc
 
redes neuronais
redes neuronaisredes neuronais
redes neuronais
 
Spherical interval-valued fuzzy bi-ideals of gamma near-rings
Spherical interval-valued fuzzy bi-ideals of gamma near-ringsSpherical interval-valued fuzzy bi-ideals of gamma near-rings
Spherical interval-valued fuzzy bi-ideals of gamma near-rings
 
Alg1 lesson 7-2
Alg1 lesson 7-2Alg1 lesson 7-2
Alg1 lesson 7-2
 
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDFACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
 
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
 
50320140501001
5032014050100150320140501001
50320140501001
 
Chapter002math
Chapter002mathChapter002math
Chapter002math
 
On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems On Fuzzy Soft Multi Set and Its Application in Information Systems
On Fuzzy Soft Multi Set and Its Application in Information Systems
 

Similar to lecture 25

DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.pptRuchika Sinha
 
Dynamic Programming knapsack 0 1
Dynamic Programming knapsack 0 1Dynamic Programming knapsack 0 1
Dynamic Programming knapsack 0 1Amit Kumar Rathi
 
Longest common sub sequence & 0/1 Knapsack
Longest common sub sequence & 0/1 KnapsackLongest common sub sequence & 0/1 Knapsack
Longest common sub sequence & 0/1 KnapsackAsif Shahriar
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDeepakGowda357858
 
Greedy algo revision 2
Greedy algo revision 2Greedy algo revision 2
Greedy algo revision 2maamir farooq
 

Similar to lecture 25 (6)

DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
 
0-1 knapsack.ppt
0-1 knapsack.ppt0-1 knapsack.ppt
0-1 knapsack.ppt
 
Dynamic Programming knapsack 0 1
Dynamic Programming knapsack 0 1Dynamic Programming knapsack 0 1
Dynamic Programming knapsack 0 1
 
Longest common sub sequence & 0/1 Knapsack
Longest common sub sequence & 0/1 KnapsackLongest common sub sequence & 0/1 Knapsack
Longest common sub sequence & 0/1 Knapsack
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse students
 
Greedy algo revision 2
Greedy algo revision 2Greedy algo revision 2
Greedy algo revision 2
 

More from sajinsc

lecture 30
lecture 30lecture 30
lecture 30sajinsc
 
lecture 29
lecture 29lecture 29
lecture 29sajinsc
 
lecture 28
lecture 28lecture 28
lecture 28sajinsc
 
lecture 27
lecture 27lecture 27
lecture 27sajinsc
 
lecture 26
lecture 26lecture 26
lecture 26sajinsc
 
lecture 24
lecture 24lecture 24
lecture 24sajinsc
 
lecture 23
lecture 23lecture 23
lecture 23sajinsc
 
lecture 22
lecture 22lecture 22
lecture 22sajinsc
 
lecture 21
lecture 21lecture 21
lecture 21sajinsc
 
lecture 20
lecture 20lecture 20
lecture 20sajinsc
 
lecture 19
lecture 19lecture 19
lecture 19sajinsc
 
lecture 18
lecture 18lecture 18
lecture 18sajinsc
 
lecture 17
lecture 17lecture 17
lecture 17sajinsc
 
lecture 16
lecture 16lecture 16
lecture 16sajinsc
 
lecture 15
lecture 15lecture 15
lecture 15sajinsc
 
lecture 14
lecture 14lecture 14
lecture 14sajinsc
 
lecture 13
lecture 13lecture 13
lecture 13sajinsc
 
lecture 12
lecture 12lecture 12
lecture 12sajinsc
 
lecture 11
lecture 11lecture 11
lecture 11sajinsc
 
lecture 10
lecture 10lecture 10
lecture 10sajinsc
 

More from sajinsc (20)

lecture 30
lecture 30lecture 30
lecture 30
 
lecture 29
lecture 29lecture 29
lecture 29
 
lecture 28
lecture 28lecture 28
lecture 28
 
lecture 27
lecture 27lecture 27
lecture 27
 
lecture 26
lecture 26lecture 26
lecture 26
 
lecture 24
lecture 24lecture 24
lecture 24
 
lecture 23
lecture 23lecture 23
lecture 23
 
lecture 22
lecture 22lecture 22
lecture 22
 
lecture 21
lecture 21lecture 21
lecture 21
 
lecture 20
lecture 20lecture 20
lecture 20
 
lecture 19
lecture 19lecture 19
lecture 19
 
lecture 18
lecture 18lecture 18
lecture 18
 
lecture 17
lecture 17lecture 17
lecture 17
 
lecture 16
lecture 16lecture 16
lecture 16
 
lecture 15
lecture 15lecture 15
lecture 15
 
lecture 14
lecture 14lecture 14
lecture 14
 
lecture 13
lecture 13lecture 13
lecture 13
 
lecture 12
lecture 12lecture 12
lecture 12
 
lecture 11
lecture 11lecture 11
lecture 11
 
lecture 10
lecture 10lecture 10
lecture 10
 

Recently uploaded

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Recently uploaded (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

lecture 25

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. 0-1 Knapsack problem: a picture w i b i 10 9 8 5 5 4 4 3 3 2 Weight Benefit value This is a knapsack Max weight: W = 20 Items W = 20
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. Defining a Subproblem Max weight: W = 20 For S 4 : Total weight: 14; total benefit: 20 w i b i 10 8 5 5 4 4 3 3 2 Weight Benefit 9 Item # 4 3 2 1 5 S 4 S 5 For S 5 : Total weight: 20 total benefit: 26 Solution for S 4 is not part of the solution for S 5 !!! ? w 1 =2 b 1 =3 w 2 =4 b 2 =5 w 3 =5 b 3 =8 w 4 =3 b 4 =4 w 1 =2 b 1 =3 w 2 =4 b 2 =5 w 3 =5 b 3 =8 w 4 =9 b 4 =10
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Example Let’s run our algorithm on the following data: n = 4 (# of elements) W = 5 (max weight) Elements (weight, benefit): (2,3), (3,4), (4,5), (5,6)
  • 20. Example (2) for w = 0 to W B[0,w] = 0 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 4
  • 21. Example (3) for i = 0 to n B[i,0] = 0 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 4
  • 22. Example (4) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 1 w-w i =-1 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0
  • 23. Example (5) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 2 w-w i =0 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3
  • 24. Example (6) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 3 w-w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3
  • 25. Example (7) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 4 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3
  • 26. Example (8) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=1 b i =3 w i =2 w= 5 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3
  • 27. Example (9) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 1 w-w i =-2 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0
  • 28. Example (10) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 2 w-w i =-1 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0 3
  • 29. Example (11) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 3 w-w i =0 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0 3 4
  • 30. Example (12) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 4 w-w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0 3 4 4
  • 31. Example (13) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=2 b i =4 w i =3 w= 5 w-w i =2 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0 3 4 4 7
  • 32. Example (14) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 1..3 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 3 3 3 3 0 0 3 4 4 7 0 3 4
  • 33. Example (15) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 4 w- w i =0 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 3 3 3 3
  • 34. Example (15) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 5 w- w i =1 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 3 3 3 3
  • 35. Example (16) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 1..4 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 0 3 4 5 3 3 3 3
  • 36. Example (17) if w i <= w // item i can be part of the solution if b i + B[i-1,w-w i ] > B[i-1,w] B[i,w] = b i + B[i-1,w- w i ] else B[i,w] = B[i-1,w] else B[i,w] = B[i-1,w] // w i > w 0 0 0 0 0 0 W 0 1 2 3 4 5 i 0 1 2 3 0 0 0 0 i=3 b i =5 w i =4 w= 5 Items: 1: (2,3) 2: (3,4) 3: (4,5) 4: (5,6) 4 0 0 0 3 4 4 7 0 3 4 5 7 0 3 4 5 7 3 3 3 3
  • 37.
  • 38.