Assignment #2, CS 155, Section 1

due October 4, 2007
100 points

This assignment deals with the zero-one and fractional knapsack problems. It is divided into numerous pieces. Some of these pieces involve programming, some do not, and some may if you so choose. In what follows, the pieces that do not involve programming are called "pencil and paper" although you can of course submit your solutions to these pieces electronically.

There are enough pieces that you can get full credit for the assignment by doing only programming, by doing no programming, or by a combination of programming and pencil and paper work.

If you turn in any of the programming pieces,

Your solutions will be graded as instances of the zero-one (or fractional??) knapsack problem, where the items are the pieces, their weights are their maximum grades, their benefits are the grades you receive on them, and the capacity is 100 points. In particular, your solution can consist of pieces whose maximum grades sum to more than 100 points, but you cannot receive more than 100 total points for your solution.

The pieces of the assignment are as follows:

  1. (20 points, programming or pencil and paper) Use the dynamic programming algorithm of the text to find the optimal solutions to the five zero-one knapsack instances with n=5, weight sequence (6, 5, 3, 4, 7), profit sequence (18, 14, 10, 13, 17), and capacities 9, 10, 11, 12, 13, and 25. If you use pencil and paper, you needn't use the algorithm for the capacity 25 case. Otherwise, you are to use a zero-argument method solveDynamically for the Knapsack class to do the job.

  2. (20 points, programming only) Use the method of the previous piece to find the optimal solutions to the four zero-one knapsack instances with n=12, weight sequence (6, 5, 13, 14, 11, 10, 3, 4, 12, 9, 7, 8), profit sequence (22, 15, 51, 55, 42, 35, 11, 15, 42, 35, 31, 35), and capacities 80, 85, 90, and 95.

  3. (20 points, programming or pencil and paper) Use exhaustive search of the power set of the set of items to find the optimal solutions to the first five zero-one knapsack instances of piece 1. If you take the programming option, you are to use a zero-argument method solveExhaustively for the Knapsack class to do the job. This method may use your solution (or my solution) to Assignment 1, it may proceed purely recursively, or it may use another technique. If you do not choose to program, express you answer in terms of a decision tree, where the levels of links in the tree correspond to making a yes/no decision on including each item, in the original order (not the sorted order).

  4. (20 points, programming only) Use the method of the previous piece to find the optimal solutions to the four zero-one knapsack instances of piece 2.

  5. (10 points, programming or pencil and paper) Use the greedy algorithm of the text to find the optimal solutions to the six instances of piece 1, interpreted as instances of the fractional knapsack problem. If you take the programming option, you are to use a zero-argument method solveFractional for the Knapsack class to do the job.

  6. (10 points, programming or pencil and paper) Find approximate solutions to the six instances of piece 1, using the following greedy algorithm: consider the items in order of nonincreasing profit density, and include each item iff it fits into that portion of the knapsack not occupied by items already included. If you take the programming option, you are to use a zero-argument method solveGreedily for the Knapsack class to do the job.

  7. (20 points, pencil and paper only) Show that there is no constant c such that the greedy algorithm of the previous piece returns a solution whose benefit is guaranteed to be within a factor of c of the optimal solution.

  8. (20 points, pencil and paper only) Find an instance of the zero-one knapsack problem where no optimal solution includes either of the two items of greatest profit density, even though the sum of their weights is no larger than the knapsack capacity.

In the programming component of your solution, you may add any other public or private methods or classes you find useful. If you do have a programming component, you are to test it by executing the (main method of) the A2 class, available on the class web site. You are to turn in hard and soft copies of your class definitions. You are also to turn in a hard copy of the results of your tests.