Turn in solutions to these problems. (Below they're marked
with this image: )
Important: Put the answer to each question on a separate sheet of paper (or one problem on front and another on the back). This is to make grading easier for us.
Collaboration Rules for This Assignment:
Here
is a handout on the 0/1 Knapsack problem
and its dynamic programming solution.
In the handout on the 0/1 knapsack problem, values are given where a
non-optimal solution is
found by the greedy approach that chooses based on the value-to-weight
ratio when it tries to solve the 0/1 knapsack
problem. Explain in a sentence or two why the optimal solution would be
found by the final step(s) when we do the
continuous knapsack? What leads to the difference in these results?
Problem 2: 0/1 knapsack problem
worksheet
Here
is an Excel worksheet that lets you work through an
example of the 0/1 knapsack problem. It uses the example values given
in the handout. Get a copy of this file,
open it, and fill in the values as instructed in this file. (There's a
2nd worksheet in the file called "blankCopy"
if you mess up the sheet.)
If you enter numbers into this file, some values are calculated and
filled-in for you, which is very handy. So
you can complete this by entering values into the file, and then turn
it in by printing a copy. Make sure you name
is on the print-out.
There is a table with increasing values of k and w, in the same order
as they're processed in the nested-loops
in the algorithm. Enter values into that table, looking at the notes
for each column (e.g. Note A) to see what's
needed. There are "explanations" that call your attention to
interesting points in the algorithm's execution
(if you put in the right values). There is a "Reason" table that tells
you why an value is selected at
each step.
Hopefully this exercise will help you understand what the algorithm
does and why in a way that's better for learning
than simply filling out a table yourself.
Show that the decision version of the 0/1 knapsack problem is in NP. Describe what you need to do to show this and then do it. If you need an algorithm, show clear pseudo-code, not English descriptions. (Make it very clear for grading purposes.)
The decision version of the 0/1 knapsack is the same as what's described in the handout, except that there is one more parameter k, which is a target value for the total-value of what's placed in the knapsack. Thus, the problem is this: Return true if you can choose a subset O of S such that the total weight of the items chosen does not exceed W and the sum of items vi in O is at least k.
The subset sum problem is this: Given a set S of n integers and an integer k, is there a subset of integers in S that sum to k? For example, if S = { 1, 2, 5, 8 } then the result would be "yes" for k=8, but it would "no" for k=12.
Subset-Sum is known to be NP-c, and you can use this information to answer this question.
The decision version of the 0/1 knapsack problem is stated below. It differs from what you have seen only because we add a new input, a target-value k.
Inputs: A set S of n items, where each item has a value vi and weight wi. Also, you are given a knapsack capacity W and a target-value k.
Required solution: choose a subset O of S such that the total weight of the items chosen does not exceed W and the sum of the values of items in O is no less than k.
Hints:
We tell you that many NP-complete problems come up "in real life." The subset-sum problem can arise in situations like the following:
Suppose a webserver (or any kind of server) has a set of download requests to process, and each request has a size (in number of bytes). Thus each download request can be abstracted to be just an integer based on file-size. If our server has a bandwidth defined as number of bytes it can accommodate in a single minute, we might be interested in finding the subset of current requests that exactly sums to our bandwidth capacity. This is the subset-sum problem.
If we increase our bandwidth, of course its performance may improve,
but solving the problem of using this increased
bandwidth in the best possible way actually becomes harder (and become
harder quickly), since the input size for
our NP-complete problem is now larger.
Hint 3 says:
"This is a pretty simple reduction in terms of what has to be done!
Each of the n items in one input becomes
exactly one item in the
transformed input. There are values and weights to be taken care of,
but you don't really need to do anything
too complicated with these."
Some have told me that this hint in particular is a bit confusing. What
I mean is this:
When you do the transformation, you'll do something with inputs for the
two problems.
In the subset-sum problem, there is a set of n items (each with a
value).
In the 0/1 knapsack problem, there is a set of n items (each with two
values, v_i and w_i).
What I tried to say in the hint is that the transformation between one
input to the other does not do anything
fancy like create 3 items where there was just 1 in the other input.
There will be a one-to-one correspondence
between the n items in one problem's input when it is transformed to
the other problem's input.
Hope this makes sense. (If it made sense to you before, never mind!)