You are on page 1of 4

Columbia University

W4231 : Analysis of Algorithms I Fall’98


Professor Luca Trevisan

Comprehensive Exam — Solutions

Problem 1. Master Theorem


Here is a table of logarithms. In the row i and column j you find the value of logi j.
1 2 3 4
2 log2 1 = 0 log2 2 = 1 log2 3 = 1.5849 log2 4 = 2
3 log3 1 = 0 log3 2 = .6309 log3 3 = 1 log3 4 = 1.2618
4 log4 1 = 0 log4 2 = .5 log4 3 = .7924 log4 4 = 1
5 log5 1 = 0 log5 2 = .4306 log5 3 = .6826 log5 4 = .8613
Solve the following recursions (c is always a constant). Give only the final results.

(a) T (n) = 3T (n/3) + cn.


(b) T (n) = 4T (n/3) + cn.

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

Problem 3. Cuts and Flows


Consider the network drawn below and the associated flow. Is the flow optimum? If not,
find an augmenting path. If it is, give a cut whose capacity is the same as the flow.
5(1)
a
4(3) d 1(1)

2(2)
e
s 3(0)
t
2(2) 1(0)
2(0)
5(4)

c
b 5(4)

A label like 5(4) attached to an edge means


that the capacity is 5 and the flow is 4.

Problem 4. What is Wrong?


Consider the (1/3, 2/3)-Partition problem defined as follows:

• Given a sequence of integers a1 , . . . , an ;


• Decide whether it is possible to partition the integers into two sets such that the sum
of the elements in a set is twice the sum of the elements in the other.
P P
Formally, decide whether there exists I ⊆ {1, . . . , n} such that i∈I ai = ( ni=1 ai )/3.
P Pn
The Partition problem is defined similarly, except that we require i∈I ai = ( i=1 ai )/2.
(1/3, 2/3)-Partition is NP-hard, but the following proof of its NP-hardness is wrong.

Wrong Reduction. We reduce from Partition. We start from an instance


a1 , . . . , an of Partition.
P
Call A = ni=1 ai . We add another element of value an+1 = A/2, and we see
(a1 , . . . , an+1 ) as an instance of (1/3, 2/3)-Partition. Now the sum of the values
of the integers in the new instance is 3A/2.

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 1. (a) T (n) = Θ(n log n). (b) T (n) = Θ(n1.2618··· ).

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.

You might also like