CS 432, Algorithms
Problem Set #5, Fall 2005


To turn in:

Turn in solutions to the two problems below

  1. Answers to the two 0/1 knapsack questions below.
  2. Show that the decision version of the 0/1 knapsack problem is in NP. (See below.)

Problems due: At the end of class on Tuesday, Nov. 29.


Collaboration Rules for This Assignment (Same as for Previous HWs):

You may talk about the problems with other students in the course and TAs, or you can work alone. If you talk with or collaborate with other students, you must list their names at the first page of your paper. (Failure to do so violates the collaboration policy for CS432.) If you work alone, write a pledge that you worked alone without collaboration on the assignment.

If you collobarate with other students, a group of three students (and no more) may agree to turn in a group write-up of the solutions. List all group members on the paper, and pledge that all members made a reasonable contribution to working out the solutions. However, any of the group members may choose to turn in an individual write-up of the solutions. If you choose to do this, you cannot not simply copy all or part of another group member's write-up. (We will investigate this if we observe it.) You should still list your collaborators on the first page of your paper.

The goal of collaboration among students is simple. you can help each other learn. If what you do for another student simply lets them turn in the assignment without helping them learn in the process, this is not acceptable.


Problem 1: 0/1 knapsack problem

Part A) 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?

Part B) Here is the write-up on the 0/1 Knapsack problem and its dynamic programming solution. (Word format only.)

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 2:

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 v_i in O is at least k.