The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
53 views

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;

asked in Algorithms by Active (3.7k points) | 53 views
0
D ...
0
can you explain please?

Please log in or register to answer this question.



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,657 questions
46,732 answers
140,417 comments
58,136 users