Question: Dynamic Programming ( DP ) can provide optimal solution of the knapsack problem. In DP , we compute the solutions to the smaller problems and
Dynamic Programming DP can provide optimal solution of the knapsack problem. In DP we compute the solutions to the smaller problems and store them in a table, to be reused later repeatedly to solve a larger problem.
For the knapsack problem given in Fig. a typical DP table is shown below. We start with items and capacity of the knapsack and keep increasing them along rows and columns respectively. The first nonzero row is constructed assuming that only item is available, while the next row assumes that items and are available, and so on Similarly, the first nonzero column is filled assuming that the knapsack capacity is only Kg and so on
Construct the DP table for the problem given in Fig. Then use backtracking technique learned in the class, starting from the last cell, to determine which items shall be placed in the knapsack.
Solution:
Capacity Kg
Number of items
solve in java
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
