Mathwords logoMathwords

Perfect Matching — Definition, Formula & Examples

A perfect matching is a set of edges in a graph such that every vertex is included in exactly one edge. In other words, every vertex is paired with exactly one neighbor, with no vertex left unmatched.

Given a graph G=(V,E)G = (V, E), a perfect matching MEM \subseteq E is a set of pairwise non-adjacent edges (no two edges share a vertex) such that every vertex vVv \in V is an endpoint of exactly one edge in MM. A necessary condition is that V|V| is even. For bipartite graphs, Hall's marriage theorem gives a necessary and sufficient condition for the existence of a perfect matching.

Key Formula

M=V2|M| = \frac{|V|}{2}
Where:
  • MM = The perfect matching — the set of selected edges
  • V|V| = The total number of vertices in the graph (must be even)

How It Works

To find a perfect matching, you need to select edges so that each vertex appears in exactly one selected edge. Start by checking whether the graph has an even number of vertices — if it does not, no perfect matching can exist. For bipartite graphs G=(AB,E)G = (A \cup B, E) with A=B|A| = |B|, Hall's theorem states a perfect matching exists if and only if for every subset SAS \subseteq A, the neighborhood N(S)N(S) satisfies N(S)S|N(S)| \geq |S|. Algorithms such as the Hopcroft–Karp algorithm efficiently find perfect matchings in bipartite graphs, while Edmonds' blossom algorithm handles general graphs.

Worked Example

Problem: Determine whether the complete bipartite graph K3,3K_{3,3} (with vertex sets A={a1,a2,a3}A = \{a_1, a_2, a_3\} and B={b1,b2,b3}B = \{b_1, b_2, b_3\}) has a perfect matching, and if so, find one.
Step 1: Check that the total number of vertices is even.
V=A+B=3+3=6 (even, so a perfect matching is possible)|V| = |A| + |B| = 3 + 3 = 6 \text{ (even, so a perfect matching is possible)}
Step 2: Verify Hall's condition. In K3,3K_{3,3}, every vertex in AA is adjacent to all three vertices in BB, so for any subset SAS \subseteq A, the neighborhood N(S)=BN(S) = B whenever SS \neq \emptyset. Thus N(S)=3S|N(S)| = 3 \geq |S| for all SS.
N(S)=3Sfor all SA|N(S)| = 3 \geq |S| \quad \text{for all } S \subseteq A
Step 3: Construct a perfect matching by pairing each vertex in AA with a distinct vertex in BB.
M={(a1,b1),  (a2,b2),  (a3,b3)}M = \{(a_1, b_1),\; (a_2, b_2),\; (a_3, b_3)\}
Step 4: Confirm: M=3=V/2=6/2|M| = 3 = |V|/2 = 6/2, every vertex appears exactly once, and no two edges share a vertex.
M=3=62|M| = 3 = \frac{6}{2} \checkmark
Answer: Yes, K3,3K_{3,3} has a perfect matching. One example is M={(a1,b1),(a2,b2),(a3,b3)}M = \{(a_1, b_1), (a_2, b_2), (a_3, b_3)\}.

Another Example

Problem: Does the cycle graph C5C_5 (a 5-vertex cycle) have a perfect matching?
Step 1: Count the vertices in C5C_5.
V=5 (odd)|V| = 5 \text{ (odd)}
Step 2: A perfect matching requires M=V/2|M| = |V|/2, which must be an integer. Since 5/2=2.55/2 = 2.5, this is impossible.
V2=52Z\frac{|V|}{2} = \frac{5}{2} \notin \mathbb{Z}
Answer: No. C5C_5 cannot have a perfect matching because it has an odd number of vertices.

Why It Matters

Perfect matchings appear throughout combinatorics courses and algorithms classes when studying assignment problems, scheduling, and network flows. In operations research, assigning workers to tasks at minimum cost reduces to finding a minimum-weight perfect matching. They also underpin results in chemistry (Kekulé structures of molecules) and computer science (stable marriage algorithms).

Common Mistakes

Mistake: Forgetting that the graph must have an even number of vertices for a perfect matching to exist.
Correction: Always check V|V| first. If V|V| is odd, you can immediately conclude no perfect matching exists.
Mistake: Confusing a maximum matching with a perfect matching.
Correction: A maximum matching is the largest matching possible in the graph, but it may still leave some vertices unmatched. A perfect matching leaves zero vertices unmatched. A perfect matching is maximum, but a maximum matching is not necessarily perfect.

Related Terms

  • GraphThe underlying structure where matchings are found
  • Bipartite GraphGraph type where Hall's theorem applies
  • EdgeA perfect matching is a specific set of edges
  • VertexEvery vertex must be covered exactly once
  • CombinatoricsBroader field that studies matchings and counting