# Matching (graph theory)

In the mathematical discipline of graph theory, a matching or independent edge set in a graph is a set of edges without common vertices. Finding a matching in a bipartite graph can be treated as a network flow problem.

## Definition

Given a graph G = (V,E), a matching M in G is a set of pairwise non-adjacent edges, none of which are loops; that is, no two edges share a common vertex.

A vertex is matched (or saturated) if it is an endpoint of one of the edges in the matching. Otherwise the vertex is unmatched.

A maximal matching is a matching M of a graph G that is not a subset of any other matching. A matching M of a graph G is maximal if every edge in G has a non-empty intersection with at least one edge in M. The following figure shows examples of maximal matchings (red) in three graphs. A maximum matching (also known as maximum-cardinality matching) is a matching that contains the largest possible number of edges. There may be many maximum matchings. The matching number $\nu (G)$ of a graph $G$ is the size of a maximum matching. Every maximum matching is maximal, but not every maximal matching is a maximum matching. The following figure shows examples of maximum matchings in the same three graphs. A perfect matching (a.k.a. 1-factor) is a matching which matches all vertices of the graph. That is, every vertex of the graph is incident to exactly one edge of the matching. Every perfect matching is maximum and hence maximal. In some literature, the term complete matching is used. In the above figure, only part (b) shows a perfect matching. A perfect matching is also a minimum-size edge cover. Thus, ν(G) ≤ ρ(G) , that is, the size of a maximum matching is no larger than the size of a minimum edge cover. A perfect matching can only occur when the graph has an even number of vertices.

A near-perfect matching is one in which exactly one vertex is unmatched. This can only occur when the graph has an odd number of vertices, and such a matching must be maximum. In the above figure, part (c) shows a near-perfect matching. If, for every vertex in a graph, there is a near-perfect matching that omits only that vertex, the graph is also called factor-critical.

Given a matching M,

• an alternating path is a path that begins with an unmatched vertex and whose edges belong alternately to the matching and not to the matching.
• an augmenting path is an alternating path that starts from and ends on free (unmatched) vertices.

One can prove that a matching is maximum if and only if it does not have any augmenting path. (This result is sometimes called Berge's lemma.)

An induced matching is a matching that is an induced subgraph.

## Properties

In any graph without isolated vertices, the sum of the matching number and the edge covering number equals the number of vertices. If there is a perfect matching, then both the matching number and the edge cover number are |V | / 2.

If A and B are two maximal matchings, then |A| ≤ 2|B| and |B| ≤ 2|A|. To see this, observe that each edge in B \ A can be adjacent to at most two edges in A \ B because A is a matching; moreover each edge in A \ B is adjacent to an edge in B \ A by maximality of B, hence

$|A\setminus B|\leq 2|B\setminus A|.$ Further we deduce that

$|A|=|A\cap B|+|A\setminus B|\leq 2|B\cap A|+2|B\setminus A|=2|B|.$ In particular, this shows that any maximal matching is a 2-approximation of a maximum matching and also a 2-approximation of a minimum maximal matching. This inequality is tight: for example, if G is a path with 3 edges and 4 vertices, the size of a minimum maximal matching is 1 and the size of a maximum matching is 2.

## Matching polynomials

A generating function of the number of k-edge matchings in a graph is called a matching polynomial. Let G be a graph and mk be the number of k-edge matchings. One matching polynomial of G is

$\sum _{k\geq 0}m_{k}x^{k}.$ Another definition gives the matching polynomial as

$\sum _{k\geq 0}(-1)^{k}m_{k}x^{n-2k},$ where n is the number of vertices in the graph. Each type has its uses; for more information see the article on matching polynomials.

## Algorithms and computational complexity

### Maximum-cardinality matching

A fundamental problem in combinatorial optimization is finding a maximum matching. This problem has various algorithms for different classes of graphs.

In an unweighted bipartite graph, the optimization problem is to find a maximum cardinality matching. The problem is solved by the Hopcroft-Karp algorithm in time O(VE) time. A randomised algorithm by Mucha and Sankowski, based on the fast matrix multiplication algorithm, gives $O(V^{2.376})$ complexity. For the special case of planar graphs the problem can be solved in time $O(n\log ^{3}n)$ .

### Maximum-weight matching

In a weighted bipartite graph, the optimization problem is to find a maximum-weight matching; a dual problem is to find a minimum-weight matching. This problem is often called maximum weighted bipartite matching, or the assignment problem. The Hungarian algorithm solves the assignment problem and it was one of the beginnings of combinatorial optimization algorithms. It uses a modified shortest path search in the augmenting path algorithm. If the Bellman–Ford algorithm is used for this step, the running time of the Hungarian algorithm becomes $O(V^{2}E)$ , or the edge cost can be shifted with a potential to achieve $O(V^{2}\log {V}+VE)$ running time with the Dijkstra algorithm and Fibonacci heap.

In a non-bipartite weighted graph, the problem of maximum weight matching can be solved in time $O(V^{2}E)$ using Edmonds' blossom algorithm.

### Maximal matchings

A maximal matching can be found with a simple greedy algorithm. A maximum matching is also a maximal matching, and hence it is possible to find a largest maximal matching in polynomial time. However, no polynomial-time algorithm is known for finding a minimum maximal matching, that is, a maximal matching that contains the smallest possible number of edges.

A maximal matching with k edges is an edge dominating set with k edges. Conversely, if we are given a minimum edge dominating set with k edges, we can construct a maximal matching with k edges in polynomial time. Therefore, the problem of finding a minimum maximal matching is essentially equal to the problem of finding a minimum edge dominating set. Both of these two optimization problems are known to be NP-hard; the decision versions of these problems are classical examples of NP-complete problems. Both problems can be approximated within factor 2 in polynomial time: simply find an arbitrary maximal matching M.

### Counting problems

The number of matchings in a graph is known as the Hosoya index of the graph. It is #P-complete to compute this quantity, even for bipartite graphs. It is also #P-complete to count perfect matchings, even in bipartite graphs, because computing the permanent of an arbitrary 0–1 matrix (another #P-complete problem) is the same as computing the number of perfect matchings in the bipartite graph having the given matrix as its biadjacency matrix. However, there exists a fully polynomial time randomized approximation scheme for counting the number of bipartite matchings. A remarkable theorem of Kasteleyn states that the number of perfect matchings in a planar graph can be computed exactly in polynomial time via the FKT algorithm.

The number of perfect matchings in a complete graph Kn (with n even) is given by the double factorial (n − 1)!!. The numbers of matchings in complete graphs, without constraining the matchings to be perfect, are given by the telephone numbers.

### Finding all maximally-matchable edges

One of the basic problems in matching theory is to find in a given graph all edges that may be extended to a maximum matching in the graph (such edges are called maximally-matchable edges, or allowed edges). Algorithms for this problem include:

• For general graphs, a deterministic algorithm in time $O(VE)$ and a randomized algorithm in time ${\tilde {O}}(V^{2.376})$ .
• For bipartite graphs, if a single maximum matching is found, a deterministic algorithm runs in time $O(V+E)$ .

## Online bipartite matching

The problem of developing an online algorithm for matching was first considered by Richard M. Karp, Umesh Vazirani, and Vijay Vazirani in 1990.

In the online setting, nodes on one side of the bipartite graph arrive one at a time and must either be immediately matched to the other side of the graph or discarded. This is a natural generalization of the secretary problem and has applications to online ad auctions. The best online algorithm, for the unweighted maximization case with a random arrival model, attains a competitive ratio of $1-{\frac {1}{e}}$ .

## Characterizations and notes

Kőnig's theorem states that, in bipartite graphs, the maximum matching is equal in size to the minimum vertex cover. Via this result, the minimum vertex cover, maximum independent set, and maximum vertex biclique problems may be solved in polynomial time for bipartite graphs.

Hall's marriage theorem provides a characterization of bipartite graphs which have a perfect matching and the Tutte theorem provides a characterization for arbitrary graphs.

A perfect matching is a spanning 1-regular subgraph, a.k.a. a 1-factor. In general, a spanning k-regular subgraph is a k-factor.

## Matching in hypergraphs

The notion of matching can be extended from graphs to Hypergraphs. :466--470  :sec.2

A matching in a hypergraph is a set of disjoint hyperedges. For example, let H be the following 3-uniform graph: { {1,2,3}, {1,4,5}, {4,5,6}, {2,3,6} }. Then H admits two matchings of size 2, namely {{1,2,3}, {4,5,6}} and {{1,4,5}, {2,3,6}}. The matching number of a hypergraph H is the largest size of a matching in H.

A fractional matching in a hypergraph is a function that assigns a fraction in [0,1] to each hyperedge, such that for every vertex v, the sum of fractions of hyperedges containing v is at most 1. A matching is a special case of a fractional matching in which all fractions are either 0 or 1. The size of a fractional matching is the sum of fractions of all hyperedges. The fractional matching number of a hypergrah H is the largest size of a fractional matching in H.

The duality between matching and covering extends to hypergraphs. A covering in a hypergraph is a subset of its vertices, such that each hyperedge contains at least one vertex of the set. The covering number is the smallest size of a covering. A fractional covering is a function assigning a weight to each vertex, such that for every hyperedge e, the sum of fractions of vertices in e is at least 1. The size of a fractional covering is the sum of fractions of all vertices. The fractional covering number of a hypergraph H is the smallest size of a fractional covering in H. Linear programming duality implies that, for every hypergraph H:

matching-number (H) <= fractional-matching-number (H) == fractional-covering-number(H) <= covering-number (H).

A (fractional) matching is called perfect if for every vertex v, the sum of fractions of hyperedges containing v is exactly 1. Given a set V of vertices, a collection E of subsets of V is called balanced if the hypergraph (V,E) admits a perfect fractional matching. For example, of V = {1,2,3,a,b,c} and E = { {1,a}, {2,a}, {1,b}, {2,b}, {3,c} }, then E is balanced, with the perfect matching { 1/2, 1/2, 1/2, 1/2, 1 }.

Consider a hypergraph H in which each hyperedge contains at most n vertices. If H admits a perfect fractional matching, then its fractional matching number is at least |V|/n. If each hyperedge in H contains exactly n vertices, then its fractional matching number is at exactly |V|/n. This is a generalization of the fact that, in a graph, the size of a perfect matching is |V|/2.

The fractional-matching-number of a hypergraph is, in general, larger than its matching-number. A theorem of Zoltán Füredi provides upper bounds on the ratio between them:

• If each hyperedge contains at most n vertices, then the ratio is at most (n-1+1/n).
• If H is n-partite (- the vertices are partitioned into n parts and each hyperedge contains a vertex from each part), then the ratio is at most (n-1).

Similarly, the fractional-covering-number of a hypergraph is, in general, smaller than its covering-number. A theorem of László Lovász provides an upper bound on the ratio between them: if each vertex is contained in at most d hyperedges (i.e., the degree of the hypergraph is at most d), then the ratio is at most (1 + ln (d)).