Docsity

Proving Perfect Matching in Graphs: Max-Flow Min-Cut Theorem and Applications, Assignments of Computer Science

Toggle sidebar
bg1
CS 6505: Algorithms, Computability and
Complexity
Problem Set 3 Solutions
Problem 1
Aperfect matching of a graph is a matching in which every vertex is matched.
Let G= (X∪Y, E ) be a bipartite graph with |X|=|Y|. Prove, using the
max-flow min-cut theorem, that Ghas a perfect matching if and only if
|A| ≤ |N(A)|for every subset A⊆X, where N(A) denotes the set of all
vertices adjacent to vertices in A.
Solution:
It should be clear that if G(X∪Y, E ) has a perfect matching then for
all subsets A⊆Xwe must have |A| ≤ |N(A)|. Otherwise, if A′is such that
A′⊆Xwith |A′|>|N(A′)|, since every node in A′is matched with some
node N(A′) there must be some node in A′that remains unmatched. This
proves necessity of the claim.
Assume |A| ≤ |N(A)|for every subset A⊆X. To prove sufficiency of
this condition we construct a flow network Nfrom Gin the following way:
orient all edges so that they are directed from Xto Y, add vertices sand t,
with directed edges from sto every vertex in Xand directed edges from each
vertex in Yto t. We give all edges infinite capacity and give unit capacity
to all vertices in X∪Y. Any valid integral flow in Nmust have edge flows
values either 0 or 1. It’s clear that such a flow induces a matching on G
where we take the edges in Ethat have flow value 1 to be in the matching.
We show that the max-flow has value |X|. Equivalently, we show that the
min-cut has size |X|. Suppose for contradiction that the min-cut is strictly
smaller than |X|. Then let C=A∪Bbe a cut, where A⊆Xand B⊆Y.
By assumption |A| ∪ |B|<|X|. Since Cis a cut, there can be no edge from
X−Ato Y−B. It follows that N(X−A)⊂B. Then we get
|N(X−A)| ≤ |B|<|X| − |A|=|X−A|
and so |X−A|>|N(X−A)|contradicting our assumption. Thus the size of
the min-cut (and max-flow) is |X|. Since all the capacities are integral, we
can find an integral max-flow. As described above this induces a matching
on Gof size |X|thus proving the theorem.
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Proving Perfect Matching in Graphs: Max-Flow Min-Cut Theorem and Applications and more Assignments Computer Science in PDF only on Docsity!

CS 6505: Algorithms, Computability and

Complexity

Problem Set 3 Solutions

Problem 1

A perfect matching of a graph is a matching in which every vertex is matched. Let G = (X ∪ Y, E) be a bipartite graph with |X| = |Y |. Prove, using the max-flow min-cut theorem, that G has a perfect matching if and only if |A| ≤ |N (A)| for every subset A ⊆ X, where N (A) denotes the set of all vertices adjacent to vertices in A.

Solution: It should be clear that if G(X ∪ Y, E) has a perfect matching then for all subsets A ⊆ X we must have |A| ≤ |N (A)|. Otherwise, if A′^ is such that A′^ ⊆ X with |A′| > |N (A′)|, since every node in A′^ is matched with some node N (A′) there must be some node in A′^ that remains unmatched. This proves necessity of the claim. Assume |A| ≤ |N (A)| for every subset A ⊆ X. To prove sufficiency of this condition we construct a flow network N from G in the following way: orient all edges so that they are directed from X to Y , add vertices s and t, with directed edges from s to every vertex in X and directed edges from each vertex in Y to t. We give all edges infinite capacity and give unit capacity to all vertices in X ∪ Y. Any valid integral flow in N must have edge flows values either 0 or 1. It’s clear that such a flow induces a matching on G where we take the edges in E that have flow value 1 to be in the matching. We show that the max-flow has value |X|. Equivalently, we show that the min-cut has size |X|. Suppose for contradiction that the min-cut is strictly smaller than |X|. Then let C = A ∪ B be a cut, where A ⊆ X and B ⊆ Y. By assumption |A| ∪ |B| < |X|. Since C is a cut, there can be no edge from X − A to Y − B. It follows that N (X − A) ⊂ B. Then we get

|N (X − A)| ≤ |B| < |X| − |A| = |X − A|

and so |X −A| > |N (X −A)| contradicting our assumption. Thus the size of the min-cut (and max-flow) is |X|. Since all the capacities are integral, we can find an integral max-flow. As described above this induces a matching on G of size |X| thus proving the theorem.

Problem 2

Prove that 2 - SAT ∈ P.

Solution: First note that a clause (α ∨ β) is logically equivalent to each of the expressions (α → β) and (β → α). Given 2-CNF formula ϕ, we construct a directed graph Gϕ as follows: The vertices are the literals of ϕ (i.e. the variables of ϕ and their negations). For each clause (α ∨ β) in ϕ, introduce two edges (α, β) and (β, α) corresponding to the two logical implications above. We note that Gϕ has the following interesting symmetry: for two vertices (i.e. literals) α, β, (α, β) is an edge if and only if (β, α) is an edge. In the following, for two vertices u, v of Gϕ (i.e. two literals u, v of ϕ), the notation u v shall mean that there is a path from vertex u to vertex v in Gϕ. We show that ϕ is satisfiable if and only if for each variable x, x 6 x or x 6 x. For each x, this condition can be tested in linear time by Depth First Search or Breadth First Search.

Suppose that for some variable x, both x x and x x. We show that ϕ is unsatisfiable. Assume by way of contradiction that some assignment A satisfies ϕ. WLOG assume that A(x) = 1 and thus A(x) = 0. (A similar argument works when A(x) = 0.) Since there is a path from x to x, and A(x) = 1 while A(x) = 0, along the path there must be an edge (α, β) such that A(α) = 1 and A(β) = 0. Since (α, β) is an edge of Gϕ, it follows that (α ∨ β) is a clause of ϕ. However this clause is not satisfied by A as A(α) = A(β) = 0, a contradiction.

Conversely, suppose that for each variable x, x 6 x or x 6 x. We show that ϕ is satisfiable by constructing an assignment A that satisfies ϕ. We note that an assignment satisfies ϕ if and only if under the assignment, no edge of Gϕ goes from 1 to 0. We repeat the following steps until all vertices have an assignment:

  1. Pick a vertex (i.e. literal) α such that (i) A(α) has not been defined and (ii) α 6 α. Let A(α) = 1 and A(α) = 0.
  2. For each vertex (i.e. literal) β such that α β, let A(β) = 1 and A(β) = 0.

Note that these steps are well defined: If both α β and α β, then by the symmetry of Gϕ, β α, and thus α α, contradicting the hypothesis that α 6 α. Furthermore, if there were a path from α to a vertex β that

  • Assign 0 to b.
  • For each 1 ≤ i ≤ m, assign 1 to zi if both A(yi, 1 ) = 0 and A(yi, 2 ) = 0; else assign 0 to zi.

Conversely, if ϕ′^ has an NAE-assignment A, then we obtain a satisfying assignment to ϕ as follows: By Part (1) we assume that A(b) = 0 (otherwise negate the assignment). For each i, A cannot assign 0 to all of yi, 1 , yi, 2 , yi, 3 for doing so would force one of the two clauses of C i′ to have all 0’s. Hence, restricting this assignment to the variables of ϕ gives a satisfying assignment to ϕ. Therefore, NAE-SAT is NP-Hard as 3 - SAT is NP-Complete. We con- clude that NAE-SAT is NP-Complete as NAE-SAT ∈ NP. 

Problem 4

A cut of an undirected graph G = (V, E) is a partition of the vertices V = A ∪ B (with A ∩ B = ∅). The size of a cut is defined as the number of edges crossing the cut. MAX-CUT is the following optimization problem: Given a graph G = (V, E), find a cut of G with the maximum size. By reduction from NAE-SAT, prove that unless P = NP, there is no polynomial- time algorithm for MAX-CUT.^1

Proof: For simplicity we may assume that for each variable x, no clause of ϕ contains both x and ¯x since such a clause is clearly satisfied by any assignment and thus can be removed. Let ϕ be a NAE-SAT instance with n variables and k clauses. Construct a graph Gϕ with 6nk vertices as follows: Each variable xi corresponds to 6k vertices – 3k labeled xi and 3k labeled ¯xi. For each i ∈ { 1 ,... , n}, connect each xi vertex with each ¯xi vertex (for a total of 9k^2 edges). For each clause in φ, select three vertices labeled by the literals in that clause and connect each pair of them by an edge. Avoid selecting the same vertex more than once. (This is possible as there are 3k vertices for each literal/label.) We show that ϕ ∈ NAE-SAT if and only if Gϕ has a cut of size at least 9 k^2 n + 2k. Suppose that ϕ has an NAE-assignment A. Then A yields a cut of size 9k^2 n+2k in Gϕ by placing all vertices corresponding to true variables on one side and all other variables on the other side. The the edges crossing the cut consisting of all 9kn^ edges between literals and their negations, and

(^1) Note that the MIN-CUT problem can be solved in polynomial time using MAX FLOW.

two edges for each clause as it contains at least one true and one false literal, yielding a total of 9k^2 n + 2k edges. Conversely, suppose that Gϕ has a cut of size at least 9k^2 n+2k. Observe that a cut can contain at most two edges for each clause, since at least two of the corresponding literals must be on the same side of the cut. Thus the clause edges can contribute at most 2k to the cut. Since Gϕ contains only 9 kn^ other edges, if Gϕ has a cut of size at least 9k^2 n + 2k, all of those edges appear in it and each clause contributes its maximum. Hence all vertices labeled by the same literal occur on the same side of the cut. By selecting either side of the cut and assigning 1 to its literals, we obtain an assignment to the variables of ϕ. Since each clause contributes two edges to the cut, it must have vertices appearing on both sides and so it has at least one true and one false literal. Hence ϕ has an NAE-assignment. Therefore, if there is a polynomial time algorithm for MAX-CUT, then NAE-SAT ∈ P: To decide NAE-SAT, on input an instance ϕ of NAE-SAT with n variables and k clauses, simply construct the graph Gϕ as above, find a maximum cut of Gϕ, and output 1 if and only if its size is at least 9 k^2 n + 2k. This would imply that P = NP as NAE-SAT is NP-Complete. 

Problem 5

  1. MAX- 2 - LIN is the following optimization problem: Given a system of equations each of the form xi ⊕ xj = b, where each xi is a Boolean variable, ⊕ denotes XOR, and b ∈ { 0 , 1 }, find an assignment to the variables xi’s that maximizes the number of satisfied equations. By reduction from MAX-CUT, prove that unless P = NP, there is no polynomial-time algorithm for MAX- 2 - LIN. Proof: Let G = (V, E) be a graph, with V = { 1 ,... , n} and m = |E|. We let variables x 1 ,... , xn correspond to the n vertices of G, and construct a system of m equations eaching involving two variables as follows: For each edge e = (i, j) ∈ E, introduce an equation xi⊕xj = 1. We show that G has a cut of size k if and only if there is an assignment that satisfies k of the m equations. Suppose that G has a cut (S, S) of size k. Let A be an assignment that to xi for each 1 ≤ i ≤ n, assigns 1 if i ∈ S, and assigns 0 otherwise. Under the assignment A, for each edge e = (i, j) that crosses the cut, xi ⊕ xj = 1; and for each edge e = (i, j) that does not cross the cut, xi ⊕ xj = 0. Thus the assignment A satisfies k of the m equations.
  1. Prove that the following problem is NP-Hard: Decide whether a given n-variate polynomial f (x 1 ,... , xn) ∈ Z[x 1 ,... , xn] with integral coef- ficient has a root in Zn, that is, some a = (α 1 ,... , αn) ∈ Zn^ such that f (α 1 ,... , αn) = 0. For extra credit, show that the above decision problem remains NP-Hard even in the special case where the degree in each variable xi of the given polynomial f (x 1 ,... , xn) is at most 2. Proof: By reduction from Subset-Sum. Let 〈{a 1 ,... , an} , t〉 be a given instance of Subset-Sum. Define the polynomial

f (x 1 ,... , xn) =

( (^) n ∑

i=

aixi − t

∑^ n

i=

(x^2 i − xi).

It is clear that in f (x 1 ,... , xn) the degree of each variable is 2. If there is a subset {ai 1 ,... , aik } such that

∑k j=1 aij^ =^ t, then setting xij = 1 for each 1 ≤ j ≤ k and xℓ = 0 for all other ℓ gives an integral solution to the polynomial f (x 1 ,... , xn). On the other hand, suppose that the polynomial f (x 1 ,... , xn) has an integral root (α 1 ,... , αn). Note that for any integer values α 1 ,... , αn, both (

∑n i=1 aiαi^ −^ t)

(^2) and ∑n i=1(α 2 i −αi) are nonnegative. Thus f (α 1 ,... , αn) = 0 if and only if both (

∑n i=1 aiαi^ −^ t)

(^2) = 0 and ∑n i=1(α 2 i −^ αi) = 0. Note that^

∑n i=1(α 2 i −^ αi) = 0 if and only if^ αi^ = 0 or αi = 1 for each 1 ≤ i ≤ n, and that (

∑n i=1 aiαi^ −^ t)

(^2) = 0 if and only if

∑n i=1 aiαi^ =^ t. Define^ I^ =^ {i^ :^ αi^ = 1}. Then^

i∈I ai^ =^ t.^ 

  1. What’s wrong with the following attempt for showing that the above problem is in NP: A non-deterministic Turing machine can decide the problem in polynomial time simply by guessing a solution a = (a 1 ,... , an) ∈ Zn^ and verifying that f (a 1 ,... , an) = 0. Answer: This argument is wrong because a solution a = (α 1 ,... , αn) may be super-polynomially long, and in this case f (α 1 ,... , αn) cannot be evaluated in polynomial time. 

Note: Recall that this is the famous Hilbert’s 10th Problem that is known to be undecidable (and thus not in NP).

Problem 7

  1. Prove that if P = NP, that is, if there is a polynomial-time algorithm that decides 3 - SAT, then there is a polynomial-time algorithm that given a 3 - SAT instance ϕ (i.e. a formula in 3-CNF), finds a satisfying assignment to ϕ if ϕ ∈ 3 - SAT, or outputs NO if ϕ 6 ∈ 3 - SAT. Solution: Suppose that P = NP. Then there is a polynomial-time algorithm A that decides 3-SAT. We now describe an algorithm B that actually finds a satisfying solution to any given 3-SAT instance ϕ that is satisfiable by invoking algorithm A n times, where n is the number of variables in ϕ. Therefore, if A runs in polynomial-time, then B runs in polynomial-time.

Algorithm B: On input ϕ(x 1 ,... , xn):

(a) Run algorithm A on ϕ to decide whether ϕ is satisfiable. If not, then output NO and halt. If ϕ is satisfiable, then the rest of the algorithm finds a satisfying assignment in n iterations, as follows. (b) Define formulas ϕ 0 (x 2 ,... , xn) = ϕ(0, x 2 ,... , xn) and ϕ 1 (x 2 ,... , xn) = ϕ(1, x 2 ,... , xn). That is, ϕ 0 and ϕ 1 are the resulting formulas after x 1 is substituted by constants 0 and 1 respectively. If ϕ is satisfiable, then clearly at least one of ϕ 0 and ϕ 1 must be satisfi- able, as in any satisfying assignment x 1 is assigned either 0 or 1. Thus, in the first iteration, first run algorithm A on ϕ 0 to decide whether ϕ 0 is satisfiable, and if so, set a 1 = 0; else ϕ 1 must be satisfiable, and set a 1 = 1. Assign x 1 = a 1 , and repeat the above for ϕa 1 until all variables have been assigned. That is: (c) In general, in the i-th iteration, with a 1 ,... , ai− 1 already assigned to x 1 ,... , xi− 1 in the first i−1 iterations so that ϕa 1 ,...,ai− 1 (xi,... , xn) = ϕ(a 1 ,... , ai− 1 , xi,... , xn) is satisfiable, set

ϕa 1 ,...,ai− 1 , 0 (xi+1,... , xn) = ϕ(a 1 ,... , ai− 1 , 0 , xi+1,... , xn),

and

ϕa 1 ,...,ai− 1 , 1 (xi+1,... , xn) = ϕ(a 1 ,... , ai− 1 , 1 , xi+1,... , xn).

Then as above, at least one of ϕa 1 ,...,ai− 1 , 0 and ϕa 1 ,...,ai− 1 , 1 must be satisfiable. Thus, first run algorithm A on ϕa 1 ,...,ai− 1 , 0 to decide whether it is decidable, and if so, set ai = 0; else ϕa 1 ,...,ai− 1 , 1 must be satisfiable, and set ai = 1.

(d) Output x 1 = a 1 ,... , xn = an and halt.

It is not hard to see that algorithm D finds an assignment that satisfies the maximum number of clauses of a given formula ϕ, and it takes polynomial time provided that C runs in polynomial time.