852 views
1 1 vote

In the knapsack problem we are given a set of n items, where each item i is specified by a size si and a value vi. We are also given a size bound S (the size of our knapsack). The goal is to find the subset of items of maximum total value such that sum of their sizes is at most S (they all fit into the knapsack).

We are trying to use Dynamic programming paradigm to reduce the time complexity for the solution. The algorithm follows

Value(n,S)
{
if (n == 0) return 0;
if (arr[n][S] != unknown) return arr[n][S];
if (s_n > S) result = Value(n-1,S);
else result = max{v_n + Value(n-1, S-s_n), Value(n-1, S)};
XXXX
return result;
}

What statement can go in the place of XXXX to make algorithm complete?

(A) No Statement is needed. It is already complete algorithm.

(B) arr[S][n]= result;

(C) arr[n][n]= result;

(D) arr[n][S] = result;

Please log in or register to answer this question.

Position:
Show:

Related questions

0 0 votes
1 1 answer
1.6k
1.6k views
ryandany07 asked Aug 18, 2022
1,633 views
int max(int a, int b) { return (a b) ? a : b; }// Returns the maximum value that can be// put in a knapsack of capacity Wint knapSack(int W, int wt[], int val[], int n){...