Logo
Published on

Introduction to Graph Theory - Part 8

Authors
  • avatar
    Name
    Till Heller
    Twitter

Suppose a company needs to assign jobs to applicants. Each applicant is qualified for certain positions, and each position can be filled by at most one person. How do we pair up as many applicants with jobs as possible? Or think of a dance: people want to be paired into couples, but not everyone is willing to dance with everyone else. How many couples can we form?

These are matching problems — and they are among the most elegant and practically important topics in graph theory. In this final part of our introduction, we'll define matchings formally, learn when perfect matchings exist, and see how a clever idea called augmenting paths ties everything together.

Matchings

Let's start with the basic setup. Given a graph, a matching is a set of edges that don't share any vertices — each vertex is "used" at most once.

Definition 40. A matching in a graph G=(V,E)G = (V, E) is a set of edges MEM \subseteq E such that no two edges in MM share a vertex.

If a vertex vv is an endpoint of some edge in MM, we say that vv is matched. Otherwise, vv is free (or unmatched).

Consider the graph G=({1,2,3,4},{(1,2),(2,3),(3,4),(1,4)})G = (\{1,2,3,4\}, \{(1,2), (2,3), (3,4), (1,4)\}), a cycle C4C_4. The set M={(1,2),(3,4)}M = \{(1,2), (3,4)\} is a matching — the two edges don't share any vertex. The set {(1,2),(2,3)}\{(1,2), (2,3)\} is not a matching, because vertex 22 appears in both edges.

There are different notions of "best" for a matching, and it's important to distinguish them.

Definition 41. A matching MM is maximal if no edge can be added to MM without violating the matching property. In other words, every edge in EME \setminus M shares a vertex with some edge in MM.

Definition 42. A matching MM is maximum if there is no matching with more edges. The size of a maximum matching is denoted ν(G)\nu(G).

A maximal matching is not necessarily maximum. In the path P4P_4 with vertices 1,2,3,41, 2, 3, 4, the matching {(2,3)}\{(2,3)\} is maximal — we can't add (1,2)(1,2) or (3,4)(3,4) without conflicting with (2,3)(2,3) — but it's not maximum, since {(1,2),(3,4)}\{(1,2), (3,4)\} has two edges.

matching

The most desirable outcome is when every vertex gets matched.

Definition 43. A perfect matching is a matching that covers every vertex of the graph. That is, every vertex is matched.

A perfect matching can only exist when the number of vertices is even — after all, each edge in the matching accounts for exactly two vertices. But having an even number of vertices is necessary, not sufficient. The path P4P_4 has four vertices and admits a perfect matching {(1,2),(3,4)}\{(1,2), (3,4)\}, while the star K1,3K_{1,3} also has four vertices but no perfect matching (the center vertex can be matched to only one of the three leaves, leaving two vertices free).

Observation 9. A perfect matching in a graph on nn vertices has exactly n2\frac{n}{2} edges.

Augmenting Paths

How do we find a maximum matching? The key insight is a beautiful structural characterization discovered by Claude Berge in 1957. It revolves around the idea of augmenting paths.

Given a matching MM, imagine walking through the graph along a path that alternates between edges not in MM and edges in MM. If this path starts and ends at free vertices, we can "flip" every edge along the path — replacing the non-matching edges with matching edges and vice versa — to get a matching with one more edge.

Definition 44. Given a matching MM, an alternating path is a path whose edges alternate between edges in MM and edges not in MM.

Definition 45. An augmenting path (with respect to MM) is an alternating path that starts and ends at free vertices.

Let's see this in action. Take the path P4P_4 with vertices 1,2,3,41, 2, 3, 4 and matching M={(2,3)}M = \{(2,3)\}. The path 1,2,3,41, 2, 3, 4 is an alternating path: the edge (1,2)(1,2) is not in MM, the edge (2,3)(2,3) is in MM, and the edge (3,4)(3,4) is not in MM. Since vertices 11 and 44 are both free, this is an augmenting path. If we flip the edges, we get the new matching M={(1,2),(3,4)}M' = \{(1,2), (3,4)\} — one edge larger than MM.

augmenting-path

This idea leads to one of the most fundamental results in matching theory.

Theorem 10 (Berge, 1957). A matching MM is maximum if and only if there is no augmenting path with respect to MM.

Proof. For the "only if" direction: suppose there exists an augmenting path PP with respect to MM. The path has one more non-matching edge than matching edge (since both endpoints are free). Flipping all edges along PP produces a new matching MM' with M=M+1|M'| = |M| + 1, so MM is not maximum.

For the "if" direction: suppose MM is not maximum, and let MM^* be a matching with M>M|M^*| > |M|. Consider the symmetric difference MM=(MM)(MM)M \triangle M^* = (M \setminus M^*) \cup (M^* \setminus M) — the set of edges that belong to exactly one of the two matchings. Every vertex has at most one edge from MM and at most one edge from MM^*, so in MMM \triangle M^*, every vertex has degree at most 22. This means MMM \triangle M^* is a union of isolated vertices, paths, and even cycles. The even cycles contribute equally to MM and MM^*. Since M>M|M^*| > |M|, there must be at least one path in MMM \triangle M^* with more edges from MM^* than from MM. This path starts and ends with edges from MM^*, so its endpoints are free with respect to MM — it is an augmenting path.

Berge's theorem is not just a theoretical characterization — it directly leads to algorithms. To find a maximum matching, start with any matching (even the empty one) and repeatedly search for augmenting paths. Each augmenting path increases the matching by one edge, and by Berge's theorem, we stop exactly when the matching is maximum1.

Hall's Marriage Theorem

Let's now focus on bipartite graphs, where matching theory is especially clean. Recall from Part 3 that a bipartite graph has two groups AA and BB with edges only between them. When does a bipartite graph have a matching that covers every vertex in AA?

Think of it as a marriage problem: each person in group AA has a list of acceptable partners in group BB. Can everyone in AA be matched? Philip Hall answered this question in 1935 with an elegant necessary and sufficient condition.

For a set SAS \subseteq A, we write N(S)N(S) for the neighborhood of SS — the set of all vertices in BB that are adjacent to at least one vertex in SS.

Theorem 11 (Hall, 1935). A bipartite graph G=(AB,E)G = (A \cup B, E) has a matching that covers every vertex in AA if and only if N(S)S|N(S)| \geq |S| for every subset SAS \subseteq A.

The condition N(S)S|N(S)| \geq |S| is called Hall's condition. It says that every group of vertices in AA must collectively have at least as many neighbors in BB — otherwise, there simply aren't enough partners to go around.

The "only if" direction is straightforward: if every vertex in SS is matched, their partners are distinct vertices in N(S)N(S), so N(S)S|N(S)| \geq |S|. The "if" direction is more involved and can be proved using augmenting paths or by induction on A|A|2.

Let's check Hall's condition on a small example. Consider the bipartite graph with A={1,2,3}A = \{1, 2, 3\}, B={a,b,c}B = \{a, b, c\}, and edges {(1,a),(1,b),(2,a),(3,c)}\{(1,a), (1,b), (2,a), (3,c)\}. For S={1}S = \{1\}, we have N(S)={a,b}N(S) = \{a, b\}, so N(S)=21|N(S)| = 2 \geq 1. For S={2}S = \{2\}, N(S)={a}N(S) = \{a\}, so N(S)=11|N(S)| = 1 \geq 1. For S={1,2}S = \{1, 2\}, N(S)={a,b}N(S) = \{a, b\}, so N(S)=22|N(S)| = 2 \geq 2. Checking all subsets confirms Hall's condition holds, and indeed a matching covering AA exists: {(1,b),(2,a),(3,c)}\{(1,b), (2,a), (3,c)\}.

As a corollary, we can characterize when a bipartite graph has a perfect matching.

Corollary 2. A bipartite graph G=(AB,E)G = (A \cup B, E) with A=B|A| = |B| has a perfect matching if and only if N(S)S|N(S)| \geq |S| for every subset SAS \subseteq A.

Vertex Covers and König's Theorem

There is a deep duality between matchings and a seemingly different concept: vertex covers.

Definition 46. A vertex cover of a graph G=(V,E)G = (V, E) is a set CVC \subseteq V such that every edge in EE has at least one endpoint in CC.

A matching picks edges so that no vertex is used twice. A vertex cover picks vertices so that no edge is missed. These two concepts are naturally opposed: every edge in a matching needs at least one of its endpoints in any vertex cover, so the size of any vertex cover is at least the size of any matching.

Observation 10. For any graph GG, ν(G)τ(G)\nu(G) \leq \tau(G), where ν(G)\nu(G) is the size of a maximum matching and τ(G)\tau(G) is the size of a minimum vertex cover.

matching-cover

In general graphs, this inequality can be strict. But in bipartite graphs, a remarkable theorem by Dénes König tells us that equality always holds.

Theorem 12 (König, 1931). In a bipartite graph, the size of a maximum matching equals the size of a minimum vertex cover: ν(G)=τ(G)\nu(G) = \tau(G).

König's theorem is one of the jewels of combinatorics. It connects an optimization problem about selecting edges (matching) to one about selecting vertices (cover), and it tells us that in bipartite graphs, these dual problems always have the same answer. The proof can be constructed by starting with a maximum matching and carefully selecting one endpoint from each matched edge to form a minimum vertex cover3.

Beyond Bipartite Graphs

In bipartite graphs, Hall's theorem gives a clean condition for when a perfect matching exists. What about general graphs? The answer is given by a theorem of William Tutte.

For a graph GG and a set SVS \subseteq V, let o(GS)o(G - S) denote the number of connected components with an odd number of vertices in the graph obtained by removing SS.

Theorem 13 (Tutte, 1947). A graph GG has a perfect matching if and only if o(GS)So(G - S) \leq |S| for every subset SVS \subseteq V.

Tutte's condition generalizes Hall's condition to non-bipartite graphs. The intuition is that each odd component needs at least one "escape edge" to a vertex in SS in order to match all its vertices, so there must be enough vertices in SS to accommodate all odd components.

We state Tutte's theorem here without proof, as the full argument is considerably more technical than Hall's theorem. It remains one of the deepest results in matching theory.

Wrapping Up the Series

With matchings, we've reached the end of this introduction to graph theory. Let's look back at the ground we've covered across all eight parts:

In Part 1, we saw how a puzzle about bridges gave birth to an entire field of mathematics. Part 2 laid the formal foundations with vertices, edges, and degrees. Part 3 introduced the main graph families — complete graphs, paths, cycles, bipartite graphs, trees, and regular graphs. Part 4 taught us how to move through graphs with walks, trails, and paths, and formalized Euler's bridge theorem. Part 5 took a deep dive into trees and their many equivalent characterizations. Part 6 added direction to our edges, opening up the world of digraphs, DAGs, and topological sorting. Part 7 explored graph coloring, from greedy algorithms to the Four Color Theorem. And here in Part 8, we studied matchings and the elegant duality between matchings and vertex covers.

These eight parts only scratch the surface. Graph theory is a vast and active field with connections to computer science, optimization, biology, and many other areas. If you've enjoyed this series, consider exploring some of the more advanced topics on this blog, such as Network Flows or Gallai's Path Conjecture, which build directly on the concepts we've developed here.

Footnotes

  1. For a detailed discussion of algorithms that find augmenting paths efficiently in bipartite graphs, see the article on Algorithms for Maximum Matchings in Bipartite Graphs.

  2. The inductive proof splits into two cases depending on whether Hall's condition holds with strict inequality for all proper subsets of AA, or whether equality is achieved for some proper subset.

  3. König's theorem is closely related to the max-flow min-cut theorem from network flow theory. In fact, it can be derived as a special case — see the series on Network Flows.