Skip to content

Chapter 59. Bipartite Matching

A bipartite matching is a matching in a bipartite graph. Bipartite matching theory studies how vertices in one part of the graph can be paired with vertices in the other part without conflicts. The subject combines combinatorics, graph algorithms, optimization, and linear programming. (en.wikipedia.org)

Bipartite matchings model assignment problems. Workers are assigned to jobs, students to schools, tasks to processors, or resources to requests. The graph encodes compatibility constraints, while the matching represents a valid assignment.

The theory is especially important because bipartite matching problems admit elegant structural theorems and efficient algorithms.

59.1 Bipartite Graphs

A graph

G=(XY,E) G = (X \cup Y,E)

is bipartite if:

XY=, X \cap Y = \varnothing,

and every edge joins a vertex in XX to a vertex in YY.

The sets XX and YY are called the partite sets.

No edge joins two vertices within the same part.

For example,

X={x1,x2,x3},Y={y1,y2,y3}, X=\{x_1,x_2,x_3\}, \qquad Y=\{y_1,y_2,y_3\},

with edges

x1y1,x1y2,x2y2,x3y3 x_1y_1, \quad x_1y_2, \quad x_2y_2, \quad x_3y_3

defines a bipartite graph.

Bipartite graphs are characterized by the absence of odd cycles. (en.wikipedia.org)

59.2 Matchings in Bipartite Graphs

A matching

ME M \subseteq E

is a set of edges such that no two edges share a vertex.

In a bipartite graph, a matching pairs vertices from XX with vertices from YY.

Each vertex can participate in at most one chosen edge.

For example,

M={x1y1,x2y2,x3y3} M= \{ x_1y_1, x_2y_2, x_3y_3 \}

is a matching if the three edges are distinct and vertex-disjoint.

The matching is perfect if every vertex is matched.

The matching saturates XX if every vertex in XX is matched.

59.3 Maximum Bipartite Matching

A maximum bipartite matching is a matching of largest possible size.

Its size is denoted by

ν(G). \nu(G).

The problem of finding a maximum matching is one of the fundamental optimization problems in graph theory.

Unlike general matching problems, bipartite matching has especially clean structure. Hall’s theorem characterizes existence, and augmenting-path algorithms solve the optimization problem efficiently.

59.4 Augmenting Paths

Let MM be a matching in a bipartite graph GG.

An alternating path is a path whose edges alternate between belonging to MM and not belonging to MM.

An augmenting path is an alternating path that begins and ends at unmatched vertices.

For example,

x1y1x2y2x3 x_1y_1x_2y_2x_3

may alternate:

EdgeStatus
x1y1x_1y_1not in MM
y1x2y_1x_2in MM
x2y2x_2y_2not in MM
y2x3y_2x_3in MM

If the first and last vertices are unmatched, then flipping the edges along the path increases the matching size by one.

This operation replaces matching edges by nonmatching edges and vice versa.

59.5 Berge’s Lemma

The key theorem behind matching algorithms is Berge’s lemma.

Theorem 59.1. Berge’s Lemma.
A matching MM is maximum if and only if there exists no augmenting path with respect to MM. (en.wikipedia.org)

This theorem transforms the matching problem into a path-search problem.

Proof Sketch

If an augmenting path exists, flipping the path increases the matching size by one, so MM cannot be maximum.

Conversely, suppose MM is not maximum. Let NN be a larger matching.

Consider the symmetric difference

MN. M \triangle N.

Every connected component of this graph is either:

ComponentStructure
Even cycleAlternating
Alternating pathEdges alternate
Isolated vertexDegree 00

Since NN has more edges than MM, some component contains more edges from NN than from MM. Such a component must be an augmenting path.

Therefore, the absence of augmenting paths characterizes maximum matchings.

59.6 Alternating Trees

Many matching algorithms build alternating trees.

Start from an unmatched vertex in XX. Explore alternating paths by:

StepEdge Type
From unmatched levelNonmatching edge
From matched levelMatching edge

The resulting structure alternates between unmatched and matched edges.

Alternating trees search systematically for augmenting paths.

If an unmatched vertex in YY becomes reachable, an augmenting path has been found.

59.7 The Hungarian Perspective

Bipartite matching can be interpreted as an assignment problem.

Suppose:

SetMeaning
XXWorkers
YYJobs
Edge xyxyWorker xx can perform job yy

A matching assigns workers to distinct jobs.

A perfect matching assigns every worker exactly one job and every job exactly one worker.

Weighted versions assign costs or profits to edges and seek optimal assignments. These lead to the Hungarian algorithm and linear optimization theory.

59.8 Hall’s Theorem Revisited

Hall’s theorem completely characterizes when a bipartite graph contains a matching saturating XX.

Theorem 59.2. Hall’s Theorem.
A bipartite graph

G=(XY,E) G=(X \cup Y,E)

contains a matching saturating XX if and only if for every subset

AX, A \subseteq X, N(A)A. |N(A)| \ge |A|.

|N(A)| \ge |A|

Hall’s theorem is the structural foundation of bipartite matching theory.

59.9 Maximum Matching Algorithms

The simplest algorithm repeatedly searches for augmenting paths.

Augmenting-Path Algorithm

  1. Start with an empty matching.
  2. Search for an augmenting path.
  3. If one exists, flip the path.
  4. Repeat until no augmenting path exists.

By Berge’s lemma, the final matching is maximum.

Complexity

If each augmenting path search uses breadth-first search or depth-first search, then the running time is polynomial.

More advanced algorithms improve efficiency substantially.

59.10 The Hopcroft-Karp Algorithm

The Hopcroft-Karp algorithm is the standard algorithm for maximum bipartite matching. (en.wikipedia.org)

Instead of augmenting one path at a time, the algorithm finds many shortest augmenting paths simultaneously.

Main Idea

  1. Use breadth-first search to construct layered levels.
  2. Find a maximal collection of vertex-disjoint shortest augmenting paths.
  3. Augment along all of them simultaneously.

This greatly reduces the number of augmentation phases.

Complexity

The Hopcroft-Karp algorithm runs in

O(EV). O(E\sqrt{V}).

This is significantly faster than naive augmenting-path algorithms for large sparse graphs.

59.11 Bipartite Matching as Flow

Bipartite matching can be transformed into a network flow problem.

Construct a directed network:

EdgeCapacity
Source to each xXx \in X11
Each edge xyxy11
Each yYy \in Y to sink11

A matching corresponds to an integer flow.

Each selected matching edge carries one unit of flow.

A maximum matching corresponds exactly to a maximum flow.

Thus bipartite matching is a special case of network flow.

59.12 König’s Theorem

One of the deepest results about bipartite graphs is König’s theorem.

A vertex cover is a set of vertices touching every edge.

Theorem 59.3. König’s Theorem.
In every bipartite graph,

maximum matching size=minimum vertex cover size. \text{maximum matching size} = \text{minimum vertex cover size}.

(en.wikipedia.org)

This theorem is remarkable because it connects:

ProblemType
Maximum matchingPacking problem
Minimum vertex coverCovering problem

In arbitrary graphs, these quantities need not be equal.

59.13 Proof Idea of König’s Theorem

Let MM be a maximum matching.

Build alternating trees from unmatched vertices in XX.

Define:

SetMeaning
ZXZ_XReachable vertices in XX
ZYZ_YReachable vertices in YY

Then the set

(XZX)ZY (X \setminus Z_X) \cup Z_Y

forms a minimum vertex cover.

Its size equals

M. |M|.

Thus:

minimum vertex cover sizeM. \text{minimum vertex cover size} \le |M|.

Since every vertex cover must contain at least one endpoint of each matching edge,

Mminimum vertex cover size. |M| \le \text{minimum vertex cover size}.

Equality follows.

59.14 Weighted Bipartite Matching

In weighted matching problems, each edge has weight or cost.

The goal becomes:

ObjectiveMeaning
Maximum-weight matchingMaximize total weight
Minimum-cost matchingMinimize total cost

These problems arise in scheduling, transportation, and assignment optimization.

The Hungarian algorithm solves the weighted assignment problem in polynomial time.

59.15 Complete Bipartite Graphs

The complete bipartite graph

Km,n K_{m,n}

contains every possible edge between XX and YY.

Its maximum matching size is

ν(Km,n)=min(m,n). \nu(K_{m,n})=\min(m,n).

If

m=n, m=n,

then the graph contains a perfect matching.

Indeed, any bijection between XX and YY defines one.

59.16 Matchings and Matrix Theory

Let GG be bipartite with adjacency matrix

A=(aij). A=(a_{ij}).

A matching corresponds to selecting entries equal to 11 such that no two chosen entries lie in the same row or column.

A perfect matching corresponds to a permutation matrix embedded in AA.

Thus bipartite matching connects graph theory with matrix combinatorics.

The permanent of the adjacency matrix counts perfect matchings.

59.17 Stable Matchings

Classical bipartite matching studies compatibility only.

Stable matching introduces preferences.

Each vertex ranks its possible partners. A matching is stable if no unmatched pair prefers each other over their assigned partners.

This leads to the Gale-Shapley stable marriage algorithm.

Stable matching differs fundamentally from maximum matching because the objective concerns preference stability rather than cardinality.

59.18 Applications

Bipartite matching appears in many domains.

ApplicationInterpretation
Job assignmentWorkers matched to jobs
Course registrationStudents matched to classes
SchedulingTasks matched to machines
Organ donationDonors matched to recipients
Network routingRequests matched to channels
Computer visionFeature correspondence
Recommendation systemsUsers matched to items

The mathematical abstraction is simple, but its practical reach is extremely broad.

59.19 Common Types of Bipartite Matching Problems

ProblemGoal
Maximum matchingLargest number of matched pairs
Perfect matchingMatch every vertex
Weighted matchingOptimize total weight
Stable matchingRespect preference structure
Online matchingDecisions made incrementally

These variants form a major part of combinatorial optimization.

59.20 Exercises

  1. Find a maximum matching in the graph:
X={x1,x2,x3},Y={y1,y2,y3}, X=\{x_1,x_2,x_3\}, \qquad Y=\{y_1,y_2,y_3\},

with edges

x1y1,x1y2,x2y2,x3y2,x3y3. x_1y_1, \quad x_1y_2, \quad x_2y_2, \quad x_3y_2, \quad x_3y_3.
  1. Prove Berge’s lemma.

  2. Show that every augmenting path increases matching size by exactly one.

  3. Determine the maximum matching size of K4,7K_{4,7}.

  4. Prove König’s theorem for a simple example.

  5. Explain why every perfect matching is maximum.

  6. Construct the flow network corresponding to a bipartite matching problem.

  7. Show that a matching corresponds to a collection of matrix entries with no repeated row or column.

  8. Give an example of a maximal matching that is not maximum.

  9. Explain why Hopcroft-Karp is faster than repeatedly augmenting along arbitrary paths.