examf98

download examf98

of 4

Transcript of examf98

  • 8/8/2019 examf98

    1/4

    Columbia UniversityW4231 : Analysis of Algorithms I Fall98Professor 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

  • 8/8/2019 examf98

    2/4

    Problem 2. Difference of Sets

    Describe an algorithm that on input two lists of integers A = a1, . . . , an and B = b1, . . . , bmgives in output the list of all the elements which belong to A but not to B. You can assumethat A and B do not contain duplicate elements, if this helps. You cannot assume that theelements 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.

    s t

    a

    b

    c

    d

    e

    2(2)

    2(2)

    5(4)

    2(0)1(0)

    A label like 5(4) attached to an edge meansthat the capacity is 5 and the flow is 4.

    1(1)4(3)

    5(1)

    3(0)

    5(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 sumof the elements in a set is twice the sum of the elements in the other.

    Formally, decide whether there exists I {1, . . . , n} such that

    iI ai = (

    n

    i=1 ai)/3.

    The Partition problem is defined similarly, except that we require

    iIai = (

    n

    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 instancea1, . . . , an of Partition.

    Call A =n

    i=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 valuesof the integers in the new instance is 3A/2.

    2

  • 8/8/2019 examf98

    3/4

    If there exists a set I {1, . . . , n} which is a good solution for the Partitioninstance (i.e.

    iI 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, ifI is a good solutionof (1/3, 2/3)-Partition, then

    iI

    ai =1

    3(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 Partitionyou can end up with a YES-instance of (1/3, 2/3)-Partition?

    3

  • 8/8/2019 examf98

    4/4

    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 ofA, check with binary searchwhether it belongs to B. If not, output it. This requires n applications of a O(log m) timebinary 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.

    4