Question: Consider the 0/1 Knapsack problem with two knapsacks having capacities m1 and m2 respectively. We have n items x1, . . . , xn. Item

Consider the 0/1 Knapsack problem with two knapsacks having capacities m1 and m2 respectively. We have n items x1, . . . , xn. Item xi has an associated weight wi and profit pi . The goal is to fill as many items as possible in the two knapsacks so that we maximize the total profit. An item can be chosen to be put in either of the two knapsacks (if possible) or not chosen at all. Assume that weights, profits, m1, and m2 are all positive integers. (i) Show that the optimal substructure property holds for the problem. (ii) Let fi(y1, y2) be the optimal solution for the subproblem restricted to the first i items x1, . . . , xi such that the two knapsacks have capacities y1 and y2 respectively. Give a recursive formulation for computing fi(y1, y2). (iii) Give the pseudo-code of the resulting algorithm. You can give either a DP algorithm or a memoized algorithm. Analyze the running time of your algorithm. (iv) Describe how to change the algorithm so that it also generates the optimum solution (i.e., which items are chosen and in which knapsack)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!