Skip to main content

Perfect matching detection

We consider the following problem: Given a bipartite graph G=(V,E)G=(V,E) where V=XYV = X \cup Y is a bi-partition and X=Y=n|X|=|Y|=n, our goal is to decide whether GG has a perfect matching.

Digression: Matching

Let us try to understand a bit the structure of the problem through a set of exercises. A matching in GG is a set of edges ME(G)M \subseteq E(G) that are vertex-disjoint (i.e., for all distinct e,fMe, f \in M, we have ef=e \cap f = \emptyset). A matching is perfect if the union of edges in MM (vertices incident to MM) is V(G)V(G).

The problem of finding a matching of maximum cardinality (a.k.a. maximum matching) is among the most fundamental problems in algorithms (the "big threes" in algorithms = matching, cuts, flows).

Exercise 126

For all nn, present a connected graph with nn nodes, in which every maximum matching has only one edge.

Exercise 127

Consider the following Heuristic A: Starting from M=M = \emptyset, keep adding arbitrary edges into MM while possible until we cannot add anymore.

  • Present a graph where this heuristic returns one edge and the optimal has two edges.
  • Prove that this heuristic returns at a matching of size at least half of the optimal.
Exercise 128

Let us further improve the heuristic (say, Heuristic A+). Starting from MM returned by Heuristic A, while it is possible to find eMe \in M and f,fE(G)M,fff, f' \in E(G) \setminus M, f\neq f' so that (M{e}){f,f}(M - \{e\}) \cup \{f,f'\} is a matching, update M(M{e}){f,f}M \gets (M-\{e\}) \cup \{f,f'\}.

  • Present a graph where this heuristic returns two edges and the optimal has three edges.
  • Prove that this heuristic returns a matching of size at least two thirds of the optimal.
Exercise 129

Define Heuristic A++ that strengthens A+ and achieves at least three fourths of the optimal. Prove that your heuristic returns a matching of size at least three fourths of the optimal.

Back to polynomials

Currently, there is a near linear-time algorithm for solving perfect matching in bipartite graphs. We will look at a much simpler, randomized algorithm that is highly parallelizable. In particular, we will show a randomized reduction from perfect matching to computing the determinant of a matrix - a task that admits a high degree of parallelism.

Determinants: Denote by SnS_n the set of all permutations σ:[n][n]\sigma: [n] \rightarrow [n].1 For each permutation σSn\sigma \in S_n, the sign of σ\sigma, denoted by sign(σ){\sf sign}(\sigma) is a number which is either 1-1 or 11 (depending on σ\sigma). We use the following definition of the determinant of matrix MM.

det(M)=σSnsign(σ)i=1nMi,σ(i)\det(M) = \sum_{\sigma \in S_n} {\sf sign}(\sigma) \prod_{i=1}^n M_{i,\sigma(i)}

The precise definition of sign{\sf sign} is quite irrelevant here, so we omit this definition.

Reduction from matching to determinant: Given a bipartite graph GG, we denote X={x1,,xn}X= \{x_1,\ldots, x_n\} and Y={y1,,yn}Y= \{y_1,\ldots, y_n\}. Each entry MijM_{ij} is defined to be a variable zi,jz_{i,j} if {xi,yj}E(G)\{x_i, y_j\} \in E(G) and 00 if there is no edge {xi,yj}\{x_i, y_j\} in GG. Notice that we have at most n2n^2 variables in the matrix MM, so p(z)=det(M)p(\textbf{z}) = \det(M) is a polynomial on at most n2n^2 variables. The degree of pp is at most nn (each term i[n]Mi,σ(i)\prod_{i \in [n]}M_{i,\sigma(i)} is a product of at most nn distinct variables).

Observation 3

Polynomial pp is a non-zero polynomial if and only if graph GG has a perfect matching.

Proof (Sketch):

To prove the \Longleftarrow direction, let MM be a perfect matching, we use the permutation defined by MM. More formally, we define σM\sigma_M where σM(i)=j\sigma_M(i) = j whenever {xi,yj}M\{x_i,y_j\} \in M. This implies that the term sign(σM)i[n]Mi,σM(i)=sign(σM)i[n]zi,σM(i){\sf sign}(\sigma_M) \prod_{i \in [n]} M_{i,\sigma_M(i)} = {\sf sign}(\sigma_M) \prod_{i \in [n]} z_{i,\sigma_M(i)} is non-zero, hence pp is non-zero (one also needs to formally justify this, i.e. do you see why the term does not cancel out?). The other direction can be proved similarly.

Since pp is a polynomial of degree at most nn, we can test whether pp is identically zero by picking a random a{1,,10n}n2\textbf{a} \in \{1,\ldots, 10n\}^{n^2} and check whether p(a)=0p(\textbf{a}) =0. In practice, this can be done by defining matrix AA where Ai,j{1,,10n}A_{i,j} \in \{1,\ldots, 10n\} is chosen randomly and uniformly. Afterwards, compute the determinant det(A)\det(A). We argue that the probability of failure is small.

  • If GG does not have a perfect matching, then det(M)\det(M) is a zero polynomial and so is det(A)\det(A).
  • If GG has a perfect matching, then p(z)=det(M)p(\textbf{z}) = \det(M) is a non-zero polynomial of degree at most nn. Therefore, the probability that p(a)=det(A)=0p(\textbf{a}) = \det(A) = 0 is at most n/10n=1/10n/10n = 1/10 by Theorem 48.

Footnotes

  1. For instance, S3={(1,2,3),(1,3,2),(2,1,3),(2,3,1),(3,1,2),(3,2,1)}S_3 = \{(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1)\}.