Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1: Knapsack: which items to take? In class we developed the dynamic programming solution for the knapsack problem, which allows us to compute the

image text in transcribed

Problem 1: Knapsack: which items to take? In class we developed the dynamic programming solution for the knapsack problem, which allows us to compute the value of the optimal solution (OPT) in (nW) time. In this problem you will extend this solution to compute which items the thief should take (a) At first glance we might think that we can compute the optimal solution at the same time as we are computing the optimal value. Consider the following naive modification (underlined code) of the iterative knapsack solution we saw from class, and explain why it does not work. Hint: why can't we start printing items to take until we compute all the way up to MIn, W]? input: item weights W,..., Wn and values V,.., Vn and knapsack capacityW for w 0 to W M[0, w] = 0 for i 1 to n for w = 1 to W if (wi > w) else print i //item i is in optimal solution return MIn, W] (b) Describe how once M is computed, we can generate the list of items that the thief should take What is your algorithm's asymptotic running time? Problem 1: Knapsack: which items to take? In class we developed the dynamic programming solution for the knapsack problem, which allows us to compute the value of the optimal solution (OPT) in (nW) time. In this problem you will extend this solution to compute which items the thief should take (a) At first glance we might think that we can compute the optimal solution at the same time as we are computing the optimal value. Consider the following naive modification (underlined code) of the iterative knapsack solution we saw from class, and explain why it does not work. Hint: why can't we start printing items to take until we compute all the way up to MIn, W]? input: item weights W,..., Wn and values V,.., Vn and knapsack capacityW for w 0 to W M[0, w] = 0 for i 1 to n for w = 1 to W if (wi > w) else print i //item i is in optimal solution return MIn, W] (b) Describe how once M is computed, we can generate the list of items that the thief should take What is your algorithm's asymptotic running time

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago