I I I I I I I I I: Optimal Solution Your Solution
I I I I I I I I I: Optimal Solution Your Solution
Your homework submissions need to be typeset (hand-drawn figures are OK). See the
course web page for suggestions on typing formulas. Your solution to each question needs to be
uploaded to CMS as a separate pdf file. To help enable more anonymous grading: do not write your
name on the homework (CMS will know it’s your submission). Collaboration is encouraged. Write
the netid of your collaborators on your solution. However, you need to write up solutions
separately! Remember that when a problem asks you to design an algorithm, you must
also prove the algorithm’s correctness and analyze its running time. The running time (or
expected running time) must be bounded by a polynomial function of the input size.
(1) (10 points with option for 10 additional bonus points) The Knapsack problem discussed in class
on Friday, November 17th is given by n items each with a value vi ≥ 0 and weight wi ≥ 0, and a weight
P
limit W . The problem is to find a subset I of items maximizing the total value i∈I vi while obeying
the weight limit i∈I wi ≤ W . You may assume that wi ≤ W for all i, that is, each item individually
P
1
your output with the provided sample outputs (SampleOutput i.txt in which 0 ≤ i ≤ 5).
The format of the input file is the following:
• The first line has two numbers, n, W , which are the number of items, and the weight limit
respectively.
• In the i-th line (let i = 0, · · · , n − 1) of the next n lines, there are two numbers vi , wi , denoting
value and weight of item i.
The format of the output file is the following:
• The first line has one number, V , which is your total value.
• In the i-th line (let i = 0, · · · , n − 1) of the next n lines, you either output 1 or 0, where 1 means
you picked item i and 0 means you didn’t pick that item.
Make sure your total value matches with your item selection. The output file will be considered wrong
if total value and item selection don’t match.
(2) (10 points) You are helping a shipping port facing the following optimization problem. Each day
lots of ships arrive to the port with n containers of weights w1 , . . . , wn , which they need to unload and
ship to a nearby facility. They can put multiple containers on any truck, but all trucks have a weight
limit W . They know that finding the packing that results in the smallest possible number of trucks
is NP-complete (reduction from Partition is possible, but you don’t have to show this). To speed up
the process of loading and unloading they consider running the following simple process: simply stack
all containers on a truck till the next container would exceed the weight limit. At that point send the
truck off, and start packing on a new truck. They are aware that this may not result in the smallest
number of trucks used but wonder if this may be good enough, and also wonder about small possible
improvements.
(a.) (6 points) Show that the number of trucks used by this greedy packing is at most twice the minimum
possible.
(b.) (4 points) Show that the bound of 2 proved in part (a) is asymptotically tight. For an example with
n containers let rn be the ratio of the trucks used in the greedy packing divided by the optimum.
So you were asked to prove in part (a) that rn ≤ 2 for all examples. Give a sequence of examples
such that limn→∞ rn = 2. A single example when greedy is not optimal (rather than a class of
examples with rn → 2) will be graded for 1 point out of 4.
(3) (10 points) We can also use the linear programming based approximation technique discussed in
class on Monday, November 20th, for solving SAT problems. Let Φ be a SAT formula with variables
x1 , . . . , xn . Suppose Φ has m clauses C1 , . . . , Cm , where Cj contains the set Pj = {i such that xi ∈ Cj }
(variables xi occur positively in Cj ) and the set Nj = {i such that x̄i ∈ Cj } (variables xi occur negatively
in Cj ). First, we claim that the following integer program describes the SAT problem Φ .
Observe that the above integer program has a solution if and only if the SAT formula Φ is satisfiable:
simply set xi true, whenever yi = 1, and set xi false whenever zi = 1. You do not need to prove this
fact.
2
In this problem we will consider the linear programming relaxation of the above integer program.
yi , zi ≥ 0 for all i = 1, . . . , n
yi + zi = 1 for all i = 1, . . . , n
X X
yi + zi ≥ 1 for all j = 1, . . . , m
i∈Pj i∈Nj
If this inequality system doesn’t have a solution Φ is clearly not satisfiable. (Do you see why? You
don’t have to submit an answer for why). In this problem, we consider the case when the inequality
system has a solution y, z and will try to turn this solution to a truth assignment that satisfies many
clauses.
Now use yi and zi as probabilities, and independently for each variable i, set xi true with probability
yi and set xi false with probability zi . Note that by the first two sets of constraints, this makes sense,
yi and zi can be thought of as probabilities for this decision.
For example, if Φ has the clause (xi ∨xj ), and our fractional solution is y and z, then our probabilistic
setting of x will make xi true with probability yi and false with probability zi , and xj will be true with
probability yj and false with probability zj . Because the choices for i and j are independent, with
probability zi zj neither is true (and hence the clause is not satisfied).
(a.) (4 points) Consider a clause C with 2 variables. Show that the probability that C is satisfied by
the above algorithm is at least 3/4 (assuming (y, z) is a solution to the linear program with clause
C one of the clauses).
(b.) (3 points) Consider a formula where all clauses have only 1 or 2 variables. Show that the expected
number of clauses satisfied by the above method is at least 0.75m.
(c.) (3 points) Show that with probability at least 1/2 the above method satisfies at least 1/2 of the
clauses in any formula where all clauses have 1 or 2 variables.