Design a local search algorithm for the 0-1 knapsack problem. Assume there are n items x1 ... xn each with weight wi and value vi. The knapsack can have at most one of each item and the total weight cannot exceed W. You want to maximize the total value in the knapsack.
Question 1: (7 points) Show the psuedocode/explanation for your algorithm.
Question 2. (3 points) Is it guaranteed to find an optimal solution? Justify your answer.
// v CONTAINS THE VALUES OF THE ITEMS
// w CONTAINS THE WEIGHT OF THE ITEMS
// n NUMBER OF ITEMS /
/ W TOTAL WEIGHT CAPACITY
// r stores the result
DP_0-1_knapsack (v, w, n, W)
for w from 0 to W do
r[0, w] = 0
end for
for j from 1 to n do
for k from 0 to W do
if k >= w[j] then
r[j, k] = max(r[j-1, k-w[j]] + v[j], r[j-1, k] )
else
r[j, k] = r[j-1, k]
The above-given pseudocode is the pseudocode for the dynamic programming (DP) based solution of the 0-1 knapsack problem. In the DP-based approach, a 2D array of sizes (n+1) and (W+1) is created and is filled for each n and W value. The result of the previous computation is used in the next computation. This ultimately leads to the final cell of our 2D array which will be the required solution for our problem.
The dynamic programming-based solution is guaranteed to find the optimal solution. This is not the case with the Greedy approach which is used to solve the fractional knapsack problem. The greedy approach cannot be used to solve the 0-1 knapsack problem because it doesn't always guarantee optimality in the case of a 0-1 knapsack.
Example:
Suppose we have 3 items A, B, and C, and a knapsack with a weight capacity of W=4.
The weight and values for the items are given below,
w=[3, 2, 2]
v=[1.8 , 1 , 1]
If the greedy approach is used then it will select the first element A and terminate the program with a value of 1.8 as no more space is left in a knapsack to accommodate more items. Whereas the most optimal solution will be the itmes B and C in the Knapsack as they will lead to a total value of 2 in the knapsack. The dynamic programming is able to get this optimal solution whereas the greedy-based solution fails.
1) Use the Breadth-First-Search with Branch-and-Bound Pruning algorithm for the 0–1 Knapsack problem to maximize the profit for the following problem instance. Show the actions step by step. 2) Use the Best-First Search with Branch-and-Bound Pruning algorithm for the 0–1 Knapsack problem to maximize the profit for the following problem instance. Show the actions step by step. i PiPi 1 $20 210 2 $30 5 6 3 $35 75 4 $12 3 4 5 $3 13 wi Wー13
Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights W1..n), all greater than 0 and one needs to maximize the total value of the subset of the items placed in the knapsack limited by a weight capacity of W In the 0-1 Knapsack Problem, each item must be either be included or excluded in its entirety, in light of the fact that this problem is to be "NP-Complete", how can one solve the...
"Greedy, but Better": Given a knapsack problem with a weight capacity C, and n items, and each item has a weight W[1:n] and monetary value P[1:n]. You have to determine which items to take so that the total weight is C, and the total value (profit) is maximized. In this case we are considering an integer problem, so you can either take an item, or not take an item, you cannot take it fractionally. If you recall, the greedy algorithm...
There are n items in a store. For each item i=1,2,...,n the weight of the item is wi and the value of the item is vi. A thief is carrying a knapsack of weight W. In this version of a problem the items can be broken into smaller pieces, so the thief may decide to carry only a fraction xi of object i, where 0≤xi ≤1. Item i contributes xiwi to the total weight in the knapsack, and xivi to...
(2) (15 points) Use the Best-First Search with Branch-and-Bound Pruning algorithm for the 0-1 Knapsack problem to maximize the profit for the following problem instance. Show the actions step by step. Pi wi 1 $20 2 10 2 $30 5 6 3 S35 7 5 4 $12 3 4 5 $3 3 wi W 13
Consider the following greedy algorithm for the knapsack problem: each time we pick the item with the highest value to weight ratio to the bag. Skip items that will make the total weight exceeded the capacity of the bag. Find a counterexample to show that this approach will not work, and the result could be 100 times worse than the optimal solution. That is, construct a table of set of items with weight and values and find a bag capacity...
solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . . . 1"} with weight {w1·W2. . . . . ux) and value (n 2, .., nJ, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity In this question, we will consider two different ways to represent a solution to the...
1. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (10 points) a. Show the completed table. b. Which items are included in the final configuration of the knapsack? c. What is the maximum value that can fit in the knapsack using a configuration of these items? item 1 2. 3 4 weight 3 2 value $25 $20 $15 1 capacity W = 6. 4 5 $40 $50 5
In 0-1 Knapsack Problem, what is maximized in the optimal solution? A.) Total Value B.) Total Weight C.) Total number of Items D.) Total Volume of Items E.) Total Value/ Total Weight
1. Fractional Knapsack Problem Algorithm Which best describes the tightest range of the number of items with only fractional inclusion (i.e. not entirely included or excluded) in the knapsack? (Let n denote the number of items for possible inclusion.) A) At least 0 items and at most n items B) At least 1 items and at most n items C) Exactly n items D) At least 0 items and at most n-1 items E) At least 1 items and at...