 Hello, everyone. Myself, Mr. F. R. Syed. I work as an assistant professor in the department of computer science and engineering at Walsh Institute of Technology, Singapore. The topic for my today's lecture is 0-1 knapsack problem. Now, at the end of the session, the students will be able to solve the 0-1 knapsack problem using dynamic programming. As we know dynamic programming is one of the problem solving approaches for algorithms. First of all, let us try to understand what the 0-1 knapsack problem is. A solution to the knapsack problem can be obtained by making a sequence of decision on the variables x1, x2, x3 up to xn. A decision on the variable xk involves determining whether a value of 0 or 1 is to be assigned to it. That is, xk could either take the value of 0 or 1. The following a decision on xk, either of the two states are possible. That is, first one, the capacity remaining equal to m and no profit is earned. In this case, xk value is equal to 0. And if xk value is equal to 1, in that case, the capacity remaining would be equal to m minus wk and the profit earn would be equal to pk. Now, wk and pk are the weight and profit associated with the object number k. Now, the remaining decisions on the variables x size other than xk need to be optimal with respect to the problem state resulting from the decision on xk. Otherwise, the remaining decisions on xi will not be optimal. This needs to be taken care of. Thus, the principle of optimality holds. Now, the ordered set si is used where each member is a pair p, w, where p stands for profit and w stands for weight. I will first assume that s0 equal to the set consisting of a tuple 0 comma 0, where profit and weight values are 0 comma 0. Now, si plus 1 can be computed from si by first of all computing si1. Now, what is si1? Si1 is a set of all pairs p comma w such that p minus pi plus 1 comma w minus w i plus 1 would belong to si. Now, pi plus 1 and w i plus 1 are the profit and weight of the object number i plus 1. Then, si plus 1 can be computed by merging the pairs in si and si1 together that is by taking a union of the pairs in si and si1 respectively. Now, let us first see now the dominance rule. If si plus 1 contains two pairs that is first pair is pj comma wj and the other pair is pk comma wk such that pj is less than equal to pk and wj is greater than equal to wk. In that case the pair pj comma wj can be discarded. Now, this is because of the fact that since pj value is less than pk value and wj value is greater than wk. So, it means that profit is less and weight is more. So, such kind of a tuple pj comma wj is discarded. Now, discarding or purging rules such as this are called as dominance rules. So, with the help of dominance rules such tuples would be eliminated. Actually, we can say that dominated tuples get purged. Now, here pk wk dominates pj wj. We will take an example of it. Let us suppose we have s2 containing the tuples 4 comma 6, 5 comma 8 and 6 comma 7. Then, in that case we can discard 5 comma 8 and make the set s2 contain as 4 comma 6 and 6 comma 7. Now, why does this happen? When we compare these 2 tuples 5, 8 and 6, 7 in that case 5 is less than 6 and 8 is greater than 7 meaning the tuple 5, 8 consists of the profit which is less and weight which is more. So, tuple with less profit and more weight is discarded. Hence, we can say 6, 7 dominates 5, 8. Now, we are going to compare the knapsack and the 0 and knapsack problem that is the knapsack problem solved using greedy method and then knapsack problem solved using dynamic programming. The first one, it is a fractional knapsack problem that is the one which is solved using greedy method. Whereas, the one that is solved using dynamic programming it is a 0 and knapsack problem. In case of the greedy approach, the items are arranged in decreasing order of p upon w ratio that is profit as to w ratio, weight ratio and then the items are selected to maximize the profit. Whereas, in case of dynamic programming approach every item is either wholly taken or not taken at all. So, as to maximize the profit and find the optimal solution. The last point is for a particular problem instance the profit earned is comparatively higher whereas, in case of 0 and knapsack problem for the particular problem instance the profit earned may be comparatively lower. Now, we take an example where n equal to 3 p 1, p 2, p 3 are 1, 2, 5 respectively and w 1, w 2, w 3 have the values of 2, 3 and 4 and m equal to 6 meaning the maximum capacity of the knapsack is 6. As we know s 0 would consist of the pair 0 comma 0 and will consider the first p w tuple that is p 1 comma w 1 which is equal to 1, 2. Now, this 1, 2 needs to be added to 0, 0. So, hence we get s 0 1 as 1 comma 2. Now, the next step is to find s 1. Now, for s 1 we are going to merge the tuples in s 0 and s 0 1. So, therefore, s 1 would consist of the tuples 0, 0 and 1, 2. After this we are going to find out s 1 1. To find s 1 1 we first of all require the next p 2 comma w tuple that is p 2 comma w 2 equal to 2 comma 3. Now, this 2 comma 3 would be added to each and every tuple of s 1 and we get s 1 1. So, 2 comma 3 when added to 0 comma 0 gives 2 comma 3 and 2 comma 3 when added to 1 comma 2 gives 3 5. Next step we get s 2 and the tuples in s 2 are as usual found out by merging the tuples in s 1 and s 1 1. Now, one thing to be noted that as in case of s 1 and s 2 even by applying the dominance tools none of the tuples get eliminated. Now, when we are finding out the tuples for s 2 we are going to merge the tuples in s 1 and s 1 1 and after making a union of this these are the 4 tuples and none of the tuples get pushed or are none of the tuples are eliminated. Our next step is to find out s 2 1, but for s 2 1 we need p 3 comma w 3. So, p 3 comma w 3 is now 5 comma 4. So, this 5 comma 4 is now added to every tuple of s 2 and hence we get s tuples in s 2 1. So, this is how 5 comma 4 when added to 0 comma 0 gives 5 comma 4, then 5 comma 4 added to 1 comma 2 gives 6 comma 6, then 5 comma 4 added to 2 comma 3 gives 7 comma 7 and when 5 4 added to 3 5 gives 8 comma 9. In this way we get s 2 1. Now, what about s 3? We need to find out what are the contents of s 3. Now, the students are expected to think and write the answer to the following question. Are any tuples eliminated from s 3 because of the dominance rule? If yes, mention those tuples. So, now pause the video and write your answer. As we know this was s 2 and this was s 2 1. Now, for finding out s 3 we need to merge the tuples in s 2 and s 2 1 and while merging we come across that there are 2 tuples 3 5 and 5 4 to which we can apply the dominance rule and hence the answer given is as the tuple 3 comma 5 would be eliminated. The reason being the profit 3 of this tuple and the profit 5 of this tuple. When we compare it 3 is less than equal to 5, but 5 is greater than equal to 4 meaning the weight of this tuple is greater than equal to this tuple and we know the profit is comparatively less. So, because of this the tuple 3 comma 5 would be eliminated and hence we get in s 3 the 7 tuples that is the 3 tuples from s 2 that is 0 0 1 2 2 3 and the remaining 4 tuples from s 2 1 that is 5 4 6 6 7 7 and 8 9. Now, one more question are any more tuples eliminated from s 3? Now, if he has mentioned those tuples, pause the video and write the answer. Now, this is s 3 consisting of 7 tuples 0 0 1 2 2 3 5 4 6 6 7 7 and 8 9. Now, we are interested to find out which tuples could be eliminated and the answer is these 2 tuples 7 7 and 8 9 are eliminated. Now, what could be the reason? Now, when we have started this problem we said that the maximum NAPSA capacity is 6. So, if 6 is the maximum capacity we are going to consider only those tuples whose weight would come up to 6. So, hence the tuples with weight value greater than 6 that is this one and this one would be eliminated that is we can say that tuples with W greater than 6 are eliminated. Now, this was our example where we found out this s 3 from s 2 and s 2 1 and after deleting this tuples 7 7 and 8 9 this is what we have in s 3. Now, once again summarize this s 0 s 1 s 2 and s 3 in one slide. Now, with m equal to 6 the tuples 6 comma 6 in s 3 gives the final result. The tuples 6 6 it does not belong to s 2. So, this concludes that x 3 value equal to 1 meaning the third object is selected. The pair 6 comma 6 came from the pair 6 minus p 3 comma 6 minus w 3 where p 3 w 3 equal to 5 4 and this 6 minus p 3 comma 6 minus w 3 gives 1 comma 2 and hence 1 comma 2 should belong to s 2 1 comma 2 it also belongs to s 1. Hence, we conclude that this 1 comma 2 came from s 1 and therefore, x 2 is equal to 0 that is the second object is not taken and since 1 comma 2 does not belong to s 0 we conclude that x 1 equal to 1 meaning the first object is selected and thus we summarize the values of x 1 x 2 x 3 equal to 1 0 1 meaning the first and the third object are selected to be put into the napsack whereas, the second object is not taken. Now, this is the reference for the video lecture. Thank you.