A matching is a set of edges chosen so that no two chosen edges touch the same vertex. Equivalently, each vertex is used by at most one chosen edge. This simple condition makes matchings a basic model for pairing problems: assigning workers to jobs, students to projects, machines to tasks, or endpoints in a network.
56.1 Definition
Let
be an undirected graph. A matching in is a subset
such that no two distinct edges in have a common endpoint.
Thus, if
and
then
For example, in the path graph
the set
is a matching. The two chosen edges do not share a vertex.
The set
is not a matching, because both edges use the vertex .
56.2 Matched and Unmatched Vertices
Let be a matching in . A vertex is called matched, or saturated, by if is an endpoint of an edge in . Otherwise, is called unmatched, or unsaturated.
If
then are matched. Any vertex outside these four vertices is unmatched.
The matching condition says that a matched vertex is incident with exactly one edge of . It can never be incident with two edges of .
56.3 Size of a Matching
The size of a matching is the number of edges it contains. It is denoted by
If contains edges, then it matches exactly vertices, since every edge has two endpoints and no endpoints are shared.
Therefore, in a graph with vertices,
This upper bound is sharp when the graph contains enough independent edges to pair all vertices, or all but one vertex.
56.4 Maximal Matchings
A matching is maximal if it cannot be enlarged by adding another edge.
More precisely, is maximal if there is no edge
such that
is still a matching.
A maximal matching is locally complete. Every edge outside touches at least one vertex already matched by . Otherwise, that edge could be added.
Maximal means no single extra edge can be inserted. It does not mean largest possible.
For example, in the path
the matching
is maximal. No other edge can be added, because both remaining edges touch or .
However, it is not maximum, because
has size .
56.5 Maximum Matchings
A matching is maximum if it has largest possible size among all matchings in . The size of a maximum matching is called the matching number of , commonly denoted by
Thus,
Every maximum matching is maximal. If a maximum matching were not maximal, one could add an edge and obtain a larger matching, contradicting maximality of its size.
The converse fails. A maximal matching may be smaller than a maximum matching.
This distinction is important in algorithms. A greedy algorithm easily produces a maximal matching, but it may fail to produce a maximum matching.
56.6 Perfect Matchings
A matching is perfect if every vertex of is matched by . A perfect matching is also called a 1-factor in some parts of graph theory.
If has vertices and is perfect, then must be even and
A perfect matching is automatically maximum, because no matching can contain more than edges.
For example, the cycle has two perfect matchings:
and
The cycle has no perfect matching, because it has an odd number of vertices.
56.7 Near-Perfect Matchings
A matching is near-perfect if it leaves exactly one vertex unmatched.
A near-perfect matching can occur only in a graph with an odd number of vertices. If has vertices, then a near-perfect matching has size
For example, the path
has two near-perfect matchings:
and
Each leaves exactly one vertex unmatched.
56.8 Matchings in Bipartite Graphs
Matchings are especially important in bipartite graphs.
Let
be a bipartite graph, where every edge joins a vertex in to a vertex in . A matching pairs vertices of with vertices of .
This is the natural model for assignment problems. The set may represent workers, and the set may represent jobs. An edge means worker is allowed to do job . A matching chooses compatible assignments so that no worker and no job is used more than once.
A matching that saturates every vertex in is called an -saturating matching. It assigns every vertex on the left side to a distinct neighbor on the right side.
A perfect matching in a bipartite graph saturates both sides. Therefore, a bipartite graph with parts and can have a perfect matching only if
56.9 Alternating Paths
Let be a matching in . An alternating path with respect to is a path whose edges alternate between edges outside and edges inside .
For example, a path
is alternating if
Alternating paths describe how a matching can be rearranged. Along such a path, one may remove the matching edges and add the non-matching edges. This operation is called flipping the path.
The matching condition is preserved because the path alternates.
56.10 Augmenting Paths
An augmenting path is an alternating path whose first and last vertices are unmatched.
Suppose the path begins and ends with edges outside . Then the path contains one more non-matching edge than matching edge. If we flip the path, we remove fewer edges than we add. The size of the matching increases by one.
For example, let
be an alternating path such that
and suppose and are unmatched. Then replacing
by
increases the matching size by one.
Augmenting paths are the basic mechanism behind many matching algorithms.
56.11 Berge’s Lemma
The fundamental theorem behind maximum matchings is Berge’s lemma.
Theorem 56.1. Berge’s Lemma.
A matching in a graph is maximum if and only if there is no augmenting path with respect to .
The forward direction is immediate. If an augmenting path exists, then flipping it produces a larger matching. Hence cannot be maximum.
The reverse direction is deeper. If is not maximum, let be a larger matching. Consider the symmetric difference
In the graph formed by these edges, every vertex has degree at most , because each of and uses any vertex at most once. Therefore, each component is a path or a cycle whose edges alternate between and .
Since has more edges than , at least one component contains more edges from than from . Such a component must be an alternating path that begins and ends with edges from . Its endpoints are unmatched by . Hence it is an augmenting path.
Thus the absence of augmenting paths exactly characterizes maximum matchings.
56.12 Greedy Construction of a Maximal Matching
A maximal matching can be found by a simple greedy method.
Start with
Scan the edges of . Whenever an edge has both endpoints currently unmatched, add it to . Continue until no more edge can be added.
This always produces a maximal matching. If an unused edge had two unmatched endpoints at the end, the algorithm could still add it.
However, the result depends on the order of the edges. Different orders may produce different maximal matchings.
On the path
choosing the middle edge first produces a maximal matching of size . Choosing the two outer edges produces a maximum matching of size .
56.13 Approximation by Maximal Matchings
Although a maximal matching may fail to be maximum, it is never too small compared with a maximum matching.
Let be any maximal matching, and let be a maximum matching. Every edge of must touch at least one edge of . Otherwise, that edge could be added to , contradicting maximality.
Each edge of has two endpoints, so it can touch at most two edges of . Therefore,
Hence,
So any maximal matching is a factor- approximation to a maximum matching. This fact is often useful in algorithmic graph theory, where a quick approximate solution may be sufficient.
56.14 Counting Matched Vertices
If is a matching, then each edge in contributes exactly two matched vertices. Therefore, the number of matched vertices is
The number of unmatched vertices is
A matching is perfect exactly when this number is zero:
A matching is near-perfect exactly when this number is one:
These formulas are elementary, but they are useful when checking whether a matching can have a certain form.
56.15 Matching Number
The matching number is the size of a maximum matching.
For a few basic graph families, it can be computed directly.
For the path graph ,
For the cycle graph ,
For the complete graph ,
For the complete bipartite graph ,
These examples show that the matching number is constrained by the number of vertices, but also by the structure of the graph.
56.16 Edge Covers and Matchings
An edge cover is a set of edges such that every vertex is incident with at least one selected edge. Edge covers and matchings are dual in a useful sense for graphs without isolated vertices.
If has no isolated vertices, then the size of a maximum matching and the size of a minimum edge cover satisfy the Gallai identity:
where denotes the minimum size of an edge cover.
The reason is intuitive. A maximum matching covers vertices. Each remaining unmatched vertex can be covered by adding one incident edge. This produces an edge cover of size
Thus,
56.17 Matchings and Vertex Covers in Bipartite Graphs
In bipartite graphs, matchings are closely related to vertex covers.
A vertex cover is a set of vertices that touches every edge. In any graph, every matching gives a lower bound on every vertex cover. Indeed, if is a matching and is a vertex cover, then each edge of must be covered by at least one vertex of . Since the edges of are disjoint, these required vertices are distinct. Therefore,
For bipartite graphs, König’s theorem says that this lower bound is always tight:
This theorem is one of the central min-max results in graph theory. It connects a packing problem, choosing disjoint edges, with a covering problem, choosing vertices that meet all edges.
56.18 Common Types of Matchings
| Type | Meaning |
|---|---|
| Matching | A set of pairwise non-adjacent edges |
| Maximal matching | A matching that cannot be enlarged by adding one edge |
| Maximum matching | A matching of largest possible size |
| Perfect matching | A matching that saturates every vertex |
| Near-perfect matching | A matching that leaves exactly one vertex unmatched |
| -saturating matching | A matching in a bipartite graph that saturates every vertex of |
The most common confusion is between maximal and maximum. Maximal is a local condition. Maximum is a global condition.
56.19 Applications
Matchings model situations where objects must be paired without reuse.
In job assignment, vertices on one side represent workers and vertices on the other side represent jobs. A matching assigns workers to jobs.
In scheduling, vertices may represent tasks and time slots. A matching assigns tasks to available slots.
In chemistry, matchings model pairings of atoms or bonds in molecular graphs.
In network design, matchings describe independent communication links that can be active simultaneously.
In algorithms, matchings appear in flow problems, optimization, approximation algorithms, and reductions between graph problems.
The abstraction is useful because it separates the pairing constraint from the details of the application. Once the graph is built, matching theory supplies the language and algorithms.
56.20 Exercises
Let be the path on six vertices. Find a maximum matching and a maximal matching that is not maximum, if one exists.
Prove that every perfect matching is maximum.
Give an example of a graph with a maximal matching of size and a maximum matching of size .
Find the matching number of .
Let be a matching in . Prove that the number of matched vertices is .
Prove that a graph with an odd number of vertices cannot have a perfect matching.
Let be a maximal matching and a maximum matching. Prove that .
In the cycle , list all perfect matchings.
Let be a bipartite graph with parts and , where . Prove that has no perfect matching.
Explain why an augmenting path increases the size of a matching by exactly one.