Solutions to problems 6

T-79.4202
Principles of Algorithmic Techniques
Tutorial 6
Problems, Hints and Solutions
Autumn 2015
Basic problems:
1.
(a) Show that for infinitely many n, there are graphs with n vertices such that the maximal
matching -based approximation algorithm for Vertex Cover presented at Lecture 11 may
produce a cover that is twice the size of the optimum cover. Thus the approximation ratio
2 derived for this algorithm at Lecture 11 is tight.
Solution. Notice that this is in particular the case for a triangle G = ({A, B,C}, {(A, B), (B,C), (C, A)}),
where all maximal matchings are of size 1 and any minimal vertex cover is of size 2.
Therefore, this is also the case for any number of (pairwise disconnected) triangles.
(b) [Dasgupta et al., Ex. 5.34] Show that for any integer n that is a power of 2, there is an
instance of the Set Cover problem with the following properties:
(i) There are n elements in the base set.
(ii) The optimal cover uses just two sets.
(iii) The greedy algorithm may pick log2 n sets.
Thus the logarithmic approximation ratio derived for the greedy set cover algorithm at
Lecture 11 is tight.
Solution. Let n = 2k , let A = {1, 2, . . . , 2k } be the base set, and consider the sets B and C of, respectively, odd and even integers in B. Moreover, for all i, let Di = {2k−i , 2k−i + 1, . . . , 2k−i+1 }.
S
Clearly, A = ki=1 Di . However, at each step of the greedy algorithm, neither A nor B covers
strictly more than half of the remaining vertices, whereas Di covers at least one more vertex
than A or B.
2. [Dasgupta et al., Ex. 9.6] In the Minimum Steiner Tree problem, the input consists of: a complete graph G = (V, E) with distances duv between all pairs of nodes; and a distinguished set of
terminal nodes V 0 ⊆ V . The goal is to find a minimum-cost tree that includes the vertices V 0 .
The tree may or may not include nodes in V \V 0 .
Suppose the distances in the input satisfy the conditions of a metric:
(i) duv ≥ 0 for all u, v,
(ii) duv = 0 if and only if u = v,
(iii) duv = dvu for all u, v,
(iv) duv ≤ duw + dwv for all u, v, w (triangle inequality).
Show that an efficient ratio-2 approximation algorithm for Minimum Steiner Tree can be obtained by ignoring the nonterminal nodes and simply returning a minimum spanning tree on V 0 .
(Hint: Recall the approximation algorithm for metric TSP presented at Lecture 11.)
Solution. Let S = (V, ES ) be a Steiner tree, and let T be a spanning tree of V 0 obtained by
replacing each maximal induced subtree of S on vertices V \V 0 by a cycle on all its leaves. By
the triangular inequality (as in the approximation algorithm for TSP shown in Lecture 11), the
total cost of these new edges cannot be more than twice the cost of walking between the edges.
Therefore, 2c(S) ≥ c(T ) ≥ c(T ∗ ), where T ∗ is the cost of a minimal spanning tree on G.
3. Monte Carlo and Las Vegas algorithms.
(a) Let 0 < ε2 < ε1 < 1. Consider a Monte Carlo algorithm that gives the correct solution to
a problem with probability at least 1 − ε1 , regardless of the input. How many independent
executions of this algorithm suffice to raise the probability of obtaining at least one correct
solution to at least 1 − ε2 , regardless of the input?
(b) Consider a Monte Carlo algorithm A for a problem Π whose running time is at most
O(T (n)) on any instance of size n and that outputs a correct solution with probability at
least γ(n). Suppose further that, given a solution to Π, we can verify its correctness in
time O(t(n)). Show how to obtain a Las Vegas algorithm that always
outputs a correct
solution and runs in expected time at most O (T (n) + t(n))/γ(n) .
Solution. We simply run the Monte-Carlo algorithm until the checker find a correct answer. In other words, each round computes a solution using the Monte Carlo algorithm,
and then checks it, which takes T (n) + t(n) time.
k
The expected running time of this Las Vegas algorithm is therefore E = ∑+∞
k=0 (1 − γ) γ(k +
1)(T (n) + t(n)): indeed, the algorithm runs exactly k times with probability (1 − γ)k γ.
k+1 )
(then, one can solve the equation by recalling that (1 − γ)k (k + 1) = d((1−γ)
, and theredγ
k
fore ∑∞
k=0 (1 − γ) (k + 1) =
d(1/γ)
dγ
= 1/γ2 .
4. Random permutations and random bits.
(a) Suppose you have access to a subroutine that, given a positive integer k as input, returns
an integer drawn uniformly at random from {1, 2, . . . , k}. Design an algorithm that, given
a positive integer n as input, returns a permutation of the integers 1, 2, . . . , n drawn uniformly at random from the set of all such permutations.
(b) Suppose you have access to a source of independent uniform random bits. Describe a
(Las Vegas) implementation of the subroutine.
Advanced problems:
5. [Dasgupta et al., Ex. 9.8] In the MAX-SAT problem, we are given a set of clauses, and we want
to find an assignment that satisfies as many of them as possible.
(a) Show that if this problem can be solved in polynomial time, then so can SAT.
Solution. If we can get a solution for MAX-SAT in polynomial time, then in particular
we are able to tell in polynomial time if that solution is equal to the number of clauses in
the formula, and if so accept (and else reject).
(b) Here’s a very naive algorithm:
for each variable:
set its value to either 0 or 1 by flipping a coin
Suppose the input has m clauses, of which the jth has k j literals. Show that the expected
number of clauses satisfied by this simple algorithm is
m 1
m
1
−
≥ .
∑
kj
2
2
j=1
In other words, this is a 2-approximation in expectation! And if the clauses all contain k
literals, then this approximation factor improves to 1 + 1/(2k − 1).
Solution. For all j, clause j is satisfied if any of its literals is true, hence is satisfied with
probability 1/2k j by this algorithm. Let X j be a random variable taking value 1 if clause j
is satisfied, and 0 else. The expected number of satisfied clauses is the expected value of
the sum of all X j , which by linearity of expectation is equal to ∑mj=1 (1 − 1/2k j ).
(c) Can you make this algorithm deterministic? (Hint: Express the expected number of satisfied clauses using two conditional expectations. At least one of the conditional expectations has to be at least the expected number of satisfied clauses.)
Solution. For each i starting at i = 0, set variable xi to 0 and 1, and compute the expectations Ei,0 and Ei,1 of the number of satisfied clauses in the remaining formula, according
to the calculation in the previous question. Select the value yielding the maximal expectation, and proceed to step i + 1. Since at each step, undecided clauses can still satisfied at
future steps, at least half of them can still be satisfied (by the previous calculation), either
for xi = 0 or for xi = 1. Therefore, at the end of the algorithm, at least half of the clauses
are satisfied.
6. [Dasgupta et al., Ex. 2.33] Suppose you are given three real matrices A, B,C of size n × n and
you are to decide (yes/no) whether AB = C. You can do this in O(nlog2 7 ) steps using Strassen’s
algorithm. In this exercise we will explore a much faster, O(n2 ) time Monte Carlo test.
(a) Let v ∈ {0, 1}n be an n × 1 vector selected uniformly at random from {0, 1}n . Show that
if M is an n × n real matrix with at least one nonzero entry, then P Mv = 0 ≤ 1/2, where
the probability is over the random choices of v. (Hint: Assume w.l.o.g. that the top-left
element in M is nonzero. Suppose Mv = 0 and solve for the random bit v1 .)
Solution. Let c be a column where M has non-zero values, and let v0 = v0 v1 . . . vc−1 ¬vc vc+1 . . . vn−1 ,
i.e. v where only bit vc has been flipped. Now, at least one of Mv and Mv0 must be nonzero, because Mv − Mv0 = M(v − v0 ) is non-zero, since (v − v0 ) only has one non-zero
bit, at position c, and M has non-zero values on column c. Hence, for a vector v chosen
uniformly at random, Mv = 0 with probability at least 1/2.
(b) Show that P ABv = Cv ≤ 1/2 if AB 6= C.
Solution. This is an immediate consequence of the previous question, with M = AB −C.
(c) Give pseudocode for an O(n2 ) time Monte Carlo algorithm for checking whether AB = C.
Exactly when does the algorithm produce an incorrect output?
Solution. In order to get error probability 1/2k , repeat the following test k times: toss a
coin n times to get a vector v, and then compute A(Bv) − (Cv). If (AB − C)v 6= 0, return
“AB 6= C”, else proceed to the next step.
This algorithm takes O(kn2 ) steps: indeed, Bv and Cv are vectors, both computable in
O(n2 ) steps. Therefore, A(Bv) can also be computed in O(n2 ), and finally A(Bv) − (Cv)
takes O(n) steps.