Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ANSWER EITHER THIS QUESTION OR QUESTION 3 Consider the problem of taking a set of n items with sizes s1,,sn, and values v1,,vn respectively. We
ANSWER EITHER THIS QUESTION OR QUESTION 3 Consider the problem of taking a set of n items with sizes s1,,sn, and values v1,,vn respectively. We assume si,viN for all 1in. Suppose we are also given a "knapsack capacity" CN. The knapsack problem is the problem of finding a subset S{1,,n} such that iSsiC and such that iSvi is maximized subject to the first constraint. We write Pn,C to denote the value iSvi of the maximum-value knapsack on the set of all items. For any kn, and any CC,CN, we can consider the same problem on the first k items in regard to capacity C. We denote the maximum-value knapsack for such a subproblem by Pk,C^. (a) Prove that the following recurrence holds: Pk,C^=0Pk1,Cmax{Pk1,C,Pk1,Csk+vk}ifk=0ifk>0butsk>Cotherwise. [10r (b) Use the recurrence above to develop a (nC) dynamic programming algorithm to compute the optimal knapsack wrt. the original n items and capacity C. Justify the (nC) runtime of your algorithm. [15n
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