Selection (Xi) Steps
Okay,let’s have the capacity m=15
The first profitable item we have are item no.5, so we select is 15-1=14. Now the remaining knapsack capacity is 14 and our selection is 1(means selected)
Then we have the next profitable item is item no .7 so we select 14-6. Now the remaining knapsack capacity is 8 and our selection is 1(means selected)
Then we have the next profitable item is item no .1 so we select 8-2. Now the remaining knapsack capacity is 6 and our selection is 1(means selected)
Then we have the next profitable item is item no .3 so we select 6-2. Now the remaining knapsack capacity is 4 and our selection is 1(means selected)
Then we have the next profitable item is item no .2. Its weight is 5 and our knapsack remaining capacity is 4, so now we are dealing with a greedy approach and select 4/5 items. (like take as we can )
So our selection is 4/5.
Now we don’t have any remaining capacity so we can’t take any more items, so it’s selection is made 0 for other items.
Conclusion
Had the problem been a 0/1 knapsack problem, the knapsack would contain the following items- < 5,7,1,3,2 >.
Knapsack’s total profit would be 65 units.
Hence, we have solved the 0/1 knapsack problem through the greedy approach.