CS 4102, Algorithms
Problem Set #6, Spring 2010

Updated: April 27, 2010, 2:40pm.  Fixed typos in the Collaboration section about number of problems.

Homework 6 is a "long" homework, worth the same as HWs 1, 2 and 5.   Like HWs 1, 2 and 5, you can work alone or in groups of two -- see rules below (same as for HW1 and 2, different than HW 3).


To turn in:

Turn in solutions to these problems.  (Below they're marked with this image: Submit-Button)

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:

  1. There are four required problems here to submit.  We may later add some more, not to be submitted.  If so, for the ones that are not required to be submitted, you can collaborate or discuss in any way with as many people as you wish.
  2. For the required problems that you submit:
    1. You may submit your work on your own or with up to two partners.  If you work with a partner, you must pledge that all partners did approximately equal amounts of work on the required problems.
    2. If you work alone, you can discuss how to solve the problems with one other group or one other single person.  List the names of these people on your submission.
    3. If you don't understand the question or what it is asking, you can get clarification from other students only if this does not involve saying how the problem might be solved in any way.  If in doubt, don't discuss and see the TA or the instructor.
  3. Fill out the cover sheet on the website and submit it with your homework.

Problem 1: 0/1 knapsack problem Submit-Button

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 Submit-Button

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.


Problem 3: Submit-Button

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.


Problem 4: Submit-Button

Show that the decision version of the 0/1 knapsack problem is in NP-hard. Describe what you need to do to show this and then do it. To solve this, you should make use of the following info about another problem.

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:

  1. Think about the direction of the reduction that's required.
  2. Write out very explicitly what the input for one problem is, and what format it needs to be converted into.
  3. 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. (See additional clarification of this hint at the end of this page!)
  4. Think about this: for the 0/1 knapsack problem, you want to choose a subset of items that weighs no more than the capacity but scores no less than the target-value. What if the capacity and the target-value were the same? (You'd be shooting for some value exactly, no?)
  5. Convince yourself that the reduction works by trying it out with the two example-inputs given for the subset-sum above.


FYI on the subset-sum problem:

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.


Clarification on Hint 3 Above:

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!)