algorithm SOS (i, weight, total) {
// i is the number considered,
// weight the accumulated weight,
// total the leftover weight
// the n numbers are stored in the array w
// the array 'include' contains a solution
if promising (i) then
if weight = W then
write (include) //we found a solution
else
include[i+1] := 'yes'
SOS (i+1, weight + w[i+1], total - w[i+1]
include[i+1] := 'no'
SOS (i+1, weight , total - w[i+1]
}
function promising(i){
// A node is not promising (and therefore will not be expanded) if
// adding any remaining number will make weight exceed W, or
// adding all remaining numbers will not bring weight up to W
// to facilitate the detection of the first case, it is best to order
// the numbers in a nondecreasing order
promising = (weight+total >=W) && (weight =W || weight+w[i+1] <=W)
}
The algorithm is called with SOS (0, 0, total), where total is the sum of all w's.
Assume n = 5, W = 21, and w = [5, 16, 11, 10, 6]
Draw the state space tree resulting from the above algorithm, and indicate the solution.
We represent each node as:
( current index , accumulated weight )
The state space tree can be represented as follows:
( Note that pruned nodes are further not expanded since they do not constitute the solution)
( Also, some nodes in the right subtree are shown as dots since they would get pruned and are avoided to reduce the comlpexity of the state space tree )
Solution: ( 5, 6, 10 ) and ( 5, 16 )
A problem that can be solved by the Backtracking technique is the 'Sum-of-Subsets' problem. Given n...
Use the Backtracking algorithm for the Sum-of-Subsets problem (Algorithm 5.4) to find all combinations of the following numbers that sum to W = 52: w1=42 w2=22 w3=17 w4=13 w5=10 w6= 2 Use State space tree- largest value first
Solve 01 Knapsack problem using 1) Backtracking 2) Breath first search with branch and bound 3) Best fit search with branch bound. Find out maxprofit and solution vector X=(x1,x2,x3,x4,x5). You need to show how you solve it using pruned state space tree. plw $20* $30» $35.» $12* $3. pi/wi- 10» 60 5» 4° 30 2» 5* 2» 30 4° 30 W=12(Knapsack capacity)-
2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi, v2, ..., vn], 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 W. Tt i=1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using an array with size...
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...
For given capacity of knapsack W and n items {i1,i2,...,in} with its own value {v1,v2,...,vn} and weight {w1,w2,...,wn}, find a greedy algorithm that solves fractional knapsack problem, and prove its correctness. And, if you naively use the greedy algorithm to solve 0-1 knapsack problem with no repetition, then the greedy algorithm does not ensure an optimal solution anymore. Give an example that a solution from the greedy algorithm is not an optimal solution for 0-1 knapsack problem.
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...
In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, 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 W . i-1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using . an...
Fill out the table for the knapsack problem, where the objects, weights, and values are as given, and the overall weight limit is 10 Next, circle the entries in the table that are used when backtracking to find objects to use in the solution Then list the object numbers that can be used for an optimal solution .Also list the weights and values of those objects Verify that the values of your solution objects add up to the optimal number...
"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...