0% found this document useful (0 votes)
47 views3 pages

I I I I I I I I I: Optimal Solution Your Solution

The document provides instructions for Problem Set 10 of an algorithms course. It includes 3 problems: 1) Design an approximation algorithm for the knapsack problem that finds a solution with value at least half optimal, and receive bonus points proportional to solution quality. The input size is up to 10,000 items each with weight and value up to 100,000, and knapsack capacity up to 10,000,000. 2) Analyze a greedy algorithm for container loading that fills each truck until its capacity is exceeded. Prove its solution is within 2x optimal, and give an example where its ratio approaches 2. 3) Use linear programming relaxation to design a probabilistic algorithm for SAT. Analy

Uploaded by

Kevin Gao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

I I I I I I I I I: Optimal Solution Your Solution

The document provides instructions for Problem Set 10 of an algorithms course. It includes 3 problems: 1) Design an approximation algorithm for the knapsack problem that finds a solution with value at least half optimal, and receive bonus points proportional to solution quality. The input size is up to 10,000 items each with weight and value up to 100,000, and knapsack capacity up to 10,000,000. 2) Analyze a greedy algorithm for container loading that fills each truck until its capacity is exceeded. Prove its solution is within 2x optimal, and give an example where its ratio approaches 2. 3) Use linear programming relaxation to design a probabilistic algorithm for SAT. Analy

Uploaded by

Kevin Gao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Algorithms Problem Set 10

CS 4820 Fall 2017 Due 11:59pm Thursday, November 30

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

fits in the knapsack.


This coding problem is asking you to design an efficient algorithm to approximately solve this
problem. For full credit, your algorithm needs to find a solution with total value of at least 1/2 of
the maximum possible. You can get bonus points (which will count towards your homework total)
proportional to the quality of the solution you find, if your solution is better than 1/2 the maximum
value. Specifically, for each test case, let β = optimal solution
your solution , you will get 13 points if β <= 1.2, will get
18 points if β <= 1.1, and will get 20 points if β <= 1.01. Random (or typical) instances of knapsack
problems tend to be rather easy to solve to very close to optimal values. Here we are using a library of
hard instances to test your program.
Here are the size of the input. n ≤ 10, 000, vi , wi ≤ 100, 000, W ≤ 10, 000, 000. You will have
time limit of 1 second for each test case. We provide two biggest test cases for you, and you need to
make sure your program can solve them in 1 second on your computer. We will use a powerful desktop
computer for testing your program. It is unlikely that your program runs in less than 1 second in your
computer but gets time limit exceeded error in our computer. If that happens, you can always bring
your computer to us, and we will use your computer to test the program again. So don’t worry about
the difference between your computer and test computer.
Since this is a NP-complete problem, we don’t have specific algorithm requirements for you. You can
use any algorithms that you like, just be careful with the time limit. You may consider reading Section
11.8 of the book, which will not be covered in class, but the algorithm discussed there is slow and needs
tons of space (as dynamic programs usually do). You may be better off with simple heuristics, thinking
about the following idea: Assume the greedy algorithm took the first k items, and let item k + 1 be the
first item not fitting in the knapsack. If this item has relatively small value, the solution is very close
to optimal. If this is not the case, maybe a better solution arises by forcing item k + 1 to be part of the
solution.
For the code, you must use the framework code (Framework.java) we provide on CMS. You are
required to submit Framework.java with your code added.
Please read the provided framework carefully before starting to write your code. You can test your
code with the test cases provided on CMS. Framework.java will take two command line arguments. The
first one is the name of the input file, and the second is the name of the output file. The input file
should be in the same folder in which your compiled java code is. After you compile and run your code,
the output file will also be in the same folder. In order to test your code with the provided test cases,
copy the test cases in the folder in which you have compiled your code, and set the name of the input
file to be the name of one of the sample inputs (SampleTest i.txt in which 0 ≤ i ≤ 5). You can compare

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 Φ .

yi , zi ∈ {0, 1} 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

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.

You might also like