01 / 22

Bipartite Graphs
and Matchings

Learn how graphs split into two independent sets, discover matchings that pair vertices optimally, and explore Hall's Marriage Theorem.

Discrete Math

What Is a Graph?

A graph \( G = (V, E) \) consists of a set of vertices \( V \) and a set of edges \( E \). Each edge connects two vertices. Graphs model relationships: friendships, network connections, job assignments, and more.

A B C D E

What Makes a Graph Bipartite?

A graph \( G = (V, E) \) is bipartite if we can partition \( V \) into two disjoint sets \( L \) and \( R \) such that every edge connects a vertex in \( L \) to a vertex in \( R \). No edge runs within the same set.

L R
\(\ell_1\)
\(\ell_2\)
\(\ell_3\)
\(r_1\)
\(r_2\)
\(r_3\)

Why Bipartite Graphs Matter

Bipartite graphs appear everywhere when two distinct categories need to be matched or connected.

Job Assignments
Workers on one side, tasks on the other. Edges represent who can do what.
Stable Matching
Medical residents paired with hospitals, students with schools.
Network Routing
Servers on one side, clients on the other. Edges represent connections.

The Two-Color Test

A graph is bipartite if and only if it contains no odd-length cycle. Equivalently, you can 2-color its vertices so that no edge has both endpoints the same color.

1
Pick any vertex and color it blue.
2
BFS/DFS outward: color every neighbor the opposite color (green).
3
If a conflict arises (two adjacent vertices share a color), the graph is not bipartite.
4
If no conflict, the two color classes form \( L \) and \( R \). The graph is bipartite.

What Is a Matching?

A matching \( M \subseteq E \) is a set of edges with no shared endpoints. Each vertex is "used" by at most one edge in \( M \).

L R A B C 1 2 3 Matching edges

Maximum vs Perfect Matching

Maximum Matching
A matching with the largest possible number of edges. Some vertices may remain unmatched.
Perfect Matching
A matching that covers every vertex. Requires \( |L| = |R| \) and enough edges to connect them all.
Maximum (not perfect) unmatched Perfect matching

Hall's Marriage Theorem

The most important result about bipartite matchings. It gives a necessary and sufficient condition for a perfect matching (from \( L \) into \( R \)).

In plain language: every group of vertices on the left has enough distinct neighbors on the right to be matched. This condition is called Hall's condition.

Visualizing Hall's Condition

L R 1 2 3 a b c S = {1, 2} N(S) = {a, b, c} |N(S)| = 3 > |S| = 2 ✓

Matching vs Vertex Cover

Matching Vertex Cover
What it is A set of edges A set of vertices
Constraint No two edges share an endpoint Every edge is "touched" by at least one vertex in the set
Goal Maximize \( |M| \) Minimize \( |C| \)
Relationship By König's Theorem: max matching = min vertex cover in bipartite graphs

Finding a Maximum Matching

The augmenting path method finds a maximum matching step by step.

1
Start with any matching \( M \) (even the empty set).
2
Find an augmenting path: a path that alternates between non-matching and matching edges, starting and ending at unmatched vertices.
3
Flip the path: swap matching and non-matching edges along the path. This increases \( |M| \) by 1.
4
Repeat until no augmenting path exists. By Berge's Theorem, the matching is now maximum.

Augmenting Path Example

A B C 1 2 3 Current M = {A-1, B-2} Augmenting path: C → 2 → B → 3

Example 1: Job Assignment

Three workers Alice, Bob, Carol can do certain jobs. Can every worker be assigned a distinct job?

Alice Bob Carol Web Data Design

Example 2: Hall's Condition Fails

1 2 3 a b S = {1, 2}, |S| = 2 N(S) = {a}, |N(S)| = 1 1 < 2 : Hall's condition violated!

Example 3: Larger Bipartite Graph

P Q R S 1 2 3 4

Common Mistakes

✕ Checking only single vertices
Hall's condition must hold for every subset \( S \subseteq L \), not just individual vertices. A vertex-by-vertex check is insufficient.
✕ Confusing matching with edge cover
A matching has no shared endpoints. An edge cover touches every vertex. They are dual concepts, not the same thing.
✕ Applying König's to non-bipartite graphs
König's theorem only works for bipartite graphs. For general graphs, max matching \(\neq\) min vertex cover.

Summary of Key Concepts

Concept Definition Key Fact
Bipartite Graph \( V = L \cup R \), edges only between \( L \) and \( R \) Exists iff no odd cycle
Matching Edge set with no shared endpoints Maximum found via augmenting paths
Perfect Matching Matching that covers all vertices Exists iff Hall's condition holds
Hall's Theorem \( |N(S)| \geq |S| \) for all \( S \subseteq L \) Necessary and sufficient
König's Theorem Max matching \(=\) Min vertex cover Only for bipartite graphs

Question 1 of 5

A graph is bipartite if and only if it contains no cycle of what kind?

Question 2 of 5

In a bipartite graph with \(|L| = 4\) and \(|R| = 4\), what is the size of a perfect matching?

Question 3 of 5

Suppose \( L = \{x, y, z\} \) and the neighborhoods are \( N(x) = \{a, b\} \), \( N(y) = \{a\} \), \( N(z) = \{a, c\} \). Does a perfect matching from \( L \) exist?

Question 4 of 5

What does König's Theorem state about bipartite graphs?

Question 5 of 5

An augmenting path with respect to a matching \( M \) must: