Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The 0-1 knapsack problem is the following: a thief robbing a store finds n items. The ith item is worth v_i dollars and weighs w_i
The 0-1 knapsack problem is the following: a thief robbing a store finds n items. The ith item is worth v_i dollars and weighs w_i kilos with i and w_i positive integers. The thief wants to take as valuable a load as possible, but he can carry at most W kilos in his knapsack with W > 0. Which items should he take to maximize his loot? This is called the 0-1 knapsack problem because for each item, the thief must either take it or leave it behind, lie cannot take a fractional amount of an item or take an item more than once. In the fractional knapsack problem, the setup is the same, but the thief can take fractions of items, rather than having to make a binary (0-1) choice for each item. After some deep thinking the lecturer of COMP333 proposes the following modelling for the fractional knapsack problem: let S = {1, 2, ..., n} Opt(S, W) = max_1 lessthanorequalto j lessthanorequalto n, 0 lessthanorequalto p lessthanorequalto 1 p middot v_j + Opt(S\{j}, W - p_j middot w_j) and Opt(Y) = 0. Notice that the 0-1 knapsack problem is a particular case where p must be either 0 or 1. Prove that the fractional knapsack problem recursive solution defined by Equation 1 has optimal sub-structure. Can you re-use your previous proof to prove that the 0-1 knapsack problem has optimal sub-structure? [If yes, you should show why, if not, provide an alternative proof.] A greedy strategy for the fractional knapsack problem is to pick up as much as we can of the item that has greatest possible value per kilo. Assume we first compute the value per kilo for each item. i.e., v_i = v_i/w_i. The greedy choice for Opt(S, W) is to take as much as we can of item i elementof S where v_i is maximal. Show that the previous greedy choice yields an optimal solution for the fractional knapsack problem. Consider the following concrete instance of the knapsack problem: the maximum capacity of the knapsack is 80 and the 4 items are as follows Compute the optimal value for the fractional version using the greedy algorithm
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started