00:01
Let us solve this dynamic knapsack problem.
00:04
To solve the knapsack problem using bottom -up dynamic programming, we need to create a table to store the optimal values.
00:11
So, what we are doing is, we are maintaining a table, row -wise and column -wise.
00:23
And using this table, we will solve by dynamic programming knapsack.
00:45
So, this can be done by two types, bottom -up or top -down.
00:52
So, here we are using bottom -up approach.
00:57
So, first we have to create the table.
01:10
So, let us create this table.
01:13
0, 1, let me write it in different color.
01:20
0, 1, 2, 3, 4, 5, 6.
01:29
So, these are the weights.
01:36
1, 2, 3, 4.
01:41
So, these are our in the first row, all the values are initialized to 0 since there are no items to be considered in the first column.
01:59
So, all the values are also initialized to 0.
02:03
So, this is 0, 0, 0, 0, 0, 0, and this is also 0.
02:15
Now, we have to populate the table using bottom -up approach.
02:20
So, consider each item and weight combination.
02:24
For each row and each column, we will calculate the maximum value that can be achieved.
02:34
So, let's say we have to compare two cases.
02:38
Case 1, so exclude current item and take maximum value obtained from the previous row.
02:47
So, you will understand this while we will fill this table.
02:55
So, what we have to do is, so this will become 0, this will become 1, 1, this will become 1, 1, this will become 1, 1, this will become 1, 1.
03:13
Okay, cos in our table.
03:17
Now, after filling the table, here is some correction.
04:22
I forgot to write another 0 here.
04:25
So, this is 0.
04:34
There is some correction in the table.
04:38
I have by mistake written 0 of the column and 0 of row.
04:43
This is 0, 1, 2, 3, then 4.
04:47
So, these are total 5 elements.
04:51
So, instead of 0 here, the 0s will come here like this.
05:01
Now, we will populate the table.
05:11
So, what we have to do is, we are selecting the maximum value and filling this 2 to 11, then 17, 17, 17, 17.
05:26
Now, in this row, we will do 6.
05:29
Now, the maximum is 11.
05:30
Here maximum is 25, 31, 36, 36, 6, 40, 25, 31, 39, 30.
05:48
So, this is how we populated the table.
05:52
Now, what we have to do is, now we have to do, from this point, we will go back and we will calculate our weights going back...