Question: The KNAPSACK problem is defined as follows: You are given a collection of objects. Each object X has a value X.value and a weight

The KNAPSACK problem is defined as follows: You are given a collection of objects. Each object X has a value

The KNAPSACK problem is defined as follows: You are given a collection of objects. Each object X has a value X.value and a weight X.weight. You are packing a knapsack and there is a maximum weight W that you can carry. The problem is to choose the objects so that their total weight is at most W, and their total value is as large as possible. In general, if the weights are floating point numbers or large integers, then the problem is believed to be intractable (that is, there is no efficient solution.) However, if all the weights involved are small integers, then there is a solution which is polynomial time in W. Find an efficient dynamic programming solution to the problem, on the assumption that the weights and W are all small positive integers. State the running time of your algorithm as a function of n, the number of objects, and W. Write the algorithm so that the optimal set (not just the optimal value) can be easily recovered, and describe how the set is recovered. Hint: For k=1 to W, for j = 1 to n, find the most valuable subset of the first j objects whose total weight is exactly k.

Step by Step Solution

3.49 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Let us assume as follows Let n denotes the number of items W denotes the capacity of the bag w... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!