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
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problemRacksaviR
 

Similar to lecture 25 (7)

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
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 

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

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 

Recently uploaded (20)

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 

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.