Professional Documents
Culture Documents
1
Problem 2. Difference of Sets
Describe an algorithm that on input two lists of integers A = a1 , . . . , an and B = b1 , . . . , bm
gives in output the list of all the elements which belong to A but not to B. You can assume
that A and B do not contain duplicate elements, if this helps. You cannot assume that the
elements of A and B are in a small range.
The algorithm should run in time O(n log m + m log m).
2(2)
e
s 3(0)
t
2(2) 1(0)
2(0)
5(4)
c
b 5(4)
2
If there exists a set I ⊆ {1, . . . , n} which is a good solution for the Partition
P
instance (i.e. i∈I ai = A/2), then I is also a good solution for the (1/3, 2/3)-
Partition instance (since A/2 is a third of 3A/2); conversely, if I is a good solution
P
of (1/3, 2/3)-Partition, then i∈I ai = 31 (3A/2) = A/2 and so I is a good solution
for the original Partition instance.
So the answer to the Partition instance is YES if and only if the answer to the
(1/2, 2/3)-Partition instance is YES.
Where does the proof go bogus? can you show that starting with a NO-instance of Partition
you can end up with a YES-instance of (1/3, 2/3)-Partition?
3
Solutions
Problem 2. Sort B in O(m log m) time. For every element of A, check with binary search
whether it belongs to B. If not, output it. This requires n applications of a O(log m) time
binary search. Total time is O(m log m + n log m).
Problem 3. The flow is optimum. A cut showing the optimality of the flow is ({s, a, d}, {b, e, c, t}).
Problem 4. The wrong part of the proof is the claim that a good solution I for the
(1/3, 2/3)-Partition problem is also good for the original Partition instance. If I = {an+1 },
the claim is false. Indeed, every instance of Partition (both YES-instances and NO-
instances) is mapped into a YES-instance of (1/3, 2/3)-Partition, since the solution I =
{an+1 } is always a good one.