Bipartite Graphs
A bipartite graph is a graph whose vertices split into two sets, U and W, so that every edge joins a vertex in U to a vertex in W. No edge stays inside one set. A graph is bipartite exactly when it has no cycle of odd length. The complete bipartite graph K_{m,n} has all m · n possible edges.
Before this lesson: Graph Theory Basics, Graph Isomorphism and Set Operations
The idea
Many graphs connect two different kinds of things: workers and jobs, students and courses, customers and products. Edges only run between the two kinds. A worker is never “qualified for” another worker.
Graphs like this are bipartite. You can draw them in two rows, one row for each kind, with every edge going from the top row to the bottom row and no edge running along a row.
Bipartite graph definition
A graph G = (V, E) is bipartite if V can be split into two sets U and W, with U \cup W = V and U \cap W = \emptyset, so that every edge has one endpoint in U and the other in W. The pair (U, W) is a bipartition.
Another way to say it: you can color every vertex with one of two colors so that each edge joins two different colors. The two color classes are U and W.
Complete bipartite graphs
The complete bipartite graph K_{m,n} has |U| = m, |W| = n, and an edge from every vertex of U to every vertex of W. By the product rule, it has mn edges.
|V(K_{m,n})| = m + n, \qquad |E(K_{m,n})| = mnEach vertex of U has degree n, and each vertex of W has degree m. A graph with only one vertex in U, such as K_{1,4}, is called a star.
The odd cycle test
Theorem. A graph is bipartite if and only if it has no cycle of odd length.
Why bipartite graphs have no odd cycle. Walk around a cycle. Each edge crosses from U to W or from W to U, so the sides alternate. You return to your starting side only after an even number of steps, so every cycle has even length.
Why no odd cycle means bipartite. In each connected piece, pick a vertex r. Put a vertex in U if its shortest path from r has even length and in W if odd. If an edge joined two vertices on the same side, those two shortest paths and the edge would contain an odd cycle.
How to test a graph (two-coloring)
- Pick any uncolored vertex and put it in U.
- Put all of its neighbors in W, then all of their uncolored neighbors in U, and keep alternating.
- If an edge ever joins two vertices on the same side, stop: the graph has an odd cycle and is not bipartite.
- When a connected piece is done, start again at any uncolored vertex. If every edge crosses, the graph is bipartite.
Bipartite graph examples
Example 1: An even cycle
Show that the 6-cycle with edges 12, 23, 34, 45, 56 and 61 is bipartite.
U = \{1, 3, 5\},\ W = \{2, 4, 6\}Try odd numbers in U and even numbers in W.
12,\ 23,\ 34
Each of these edges joins an odd vertex to an even vertex.
45,\ 56,\ 61
So does each of these.
U \cap W = \emptyset
Every vertex is in exactly one set, and every edge crosses.
Answer: bipartite, with U = {1, 3, 5} and W = {2, 4, 6}. The same idea works for every cycle of even length.
Example 2: A triangle blocks it
Graph G has edges ab, bc, ca and cd. Is it bipartite?
a \in U
Start the two-coloring at a.
b \in W,\ c \in W
b and c are neighbors of a.
bc \in E
But b and c are joined, and both are in W.
a, b, c, a
The conflict comes from the triangle, a cycle of length 3.
Answer: not bipartite. The triangle abc is an odd cycle, so no bipartition can exist.
Example 3: Running the two-coloring test
Graph G has vertices 1 to 7 and edges 12, 14, 23, 25, 36, 45, 56 and 67. Decide whether it is bipartite.
1 \in U
Start at vertex 1.
2 \in W,\ 4 \in W
The neighbors of 1.
3 \in U,\ 5 \in U
The uncolored neighbors of 2.
45:\ W \to U
Vertex 4’s other neighbor, 5, is already in U: no conflict.
6 \in W
The uncolored neighbor of 3 and of 5.
7 \in U
The uncolored neighbor of 6.
12, 14, 23, 25, 36, 45, 56, 67
Check all 8 edges: each joins a U vertex to a W vertex.
Answer: bipartite, with U = {1, 3, 5, 7} and W = {2, 4, 6}.
Example 4: Counting in K₄,₅
Find the number of vertices and edges of K_{4,5}, give the degrees, and check the handshaking lemma.
4 + 5 = 9
Count the vertices: 4 in U and 5 in W.
4 \cdot 5 = 20
Count the edges: each of the 4 vertices in U joins all 5 in W.
\deg(u) = 5,\ \deg(w) = 4
A vertex of U has 5 neighbors; a vertex of W has 4.
4 \cdot 5 + 5 \cdot 4 = 40
Add the degrees of all 9 vertices.
2 \cdot 20 = 40
Twice the 20 edges, as the handshaking lemma says.
Answer: 9 vertices and 20 edges; four vertices of degree 5 and five of degree 4.
Example 5: Scheduling tutoring sessions (word problem)
A tutoring center pairs 3 tutors with 6 students. Each student meets exactly 2 tutors, and every tutor meets the same number of students. How many students does each tutor meet?
|E| = 6 \cdot 2
Tutors and students are the two sides; each session is an edge, and each student has degree 2.
6 \cdot 2 = 12
There are 12 sessions in all.
3d = 12
The tutors’ degrees also add to |E|, since every edge has exactly one tutor end.
d = 4
Divide both sides by 3.
Answer: each tutor meets 4 students. In any bipartite graph, the degrees in U and the degrees in W each add up to |E|.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Thinking “no triangles” means bipartite | “The 5-cycle has no triangle, so it is bipartite.” | Any odd cycle blocks it; the 5-cycle is not bipartite. |
| Requiring equal sides | “U and W must have the same size.” | The sides can be any sizes, as in K_{2,3}. |
| Allowing an edge inside a side | Putting both ends of edge bc in W | Every edge must cross from U to W. |
| Counting K_{m,n} edges as m + n | “K_{4,5} has 9 edges.” | m + n counts vertices; the edges number mn = 20. |
| Checking only one piece | Two-coloring one connected piece and stopping | Start again at an uncolored vertex until every vertex is colored. |
| Confusing bipartite with complete bipartite | “The 6-cycle is not bipartite because 1 and 4 are not joined.” | Bipartite only forbids edges inside a side; it does not require every cross edge. |
Related ideas
Adjacency matrices of bipartite graphs
List the vertices of U first and W second. The adjacency matrix then has zero blocks on the diagonal, because no edge stays inside a side: A = \begin{bmatrix} 0 & B \\ B^T & 0 \end{bmatrix}, where B records which vertices of U are joined to which vertices of W.
Matchings
A matching is a set of edges with no shared endpoints, such as pairing each worker with one job. In a bipartite graph, Hall’s marriage theorem says every vertex of U can be matched exactly when each group of k vertices in U has at least k neighbors in W, for every k.
Graphs with no cycles
A graph with no cycles at all has no odd cycles, so it is always bipartite. Paths, stars and branching diagrams such as a tournament bracket are all bipartite.
Practice problems
- Is the 8-cycle with vertices 1 to 8 bipartite? If so, give a bipartition.
- Is the 7-cycle bipartite?
- How many vertices and edges does K_{3,5} have?
- Give the degrees in K_{2,6} and check the handshaking lemma.
- Is the complete graph K_4 bipartite?
- Graph G has edges ab, bc, cd, da and ae. Is it bipartite? If so, give a bipartition.
- Graph G has edges 12, 23, 34, 45, 51 and 13. Is it bipartite? If not, find an odd cycle.
- What is the largest number of edges a bipartite graph with 10 vertices can have?
- The cube graph has the 8 strings 000, 001, …, 111 as vertices, with an edge when two strings differ in exactly one digit. Is it bipartite?
- Eight volunteers each sign up for exactly 3 of 6 shifts, and every shift gets the same number of volunteers. How many volunteers does each shift get?
Show answers
1.
U = \{1, 3, 5, 7\}Put the odd vertices in U.
W = \{2, 4, 6, 8\}Put the even vertices in W.
12, 23, \dots, 78, 81
Each edge joins an odd vertex to an even one.
Answer: yes; U = {1, 3, 5, 7}, W = {2, 4, 6, 8}
2.
7 \text{ is odd}The 7-cycle is itself a cycle of odd length.
Answer: no
3.
3 + 5 = 8
Count the vertices.
3 \cdot 5 = 15
Count the edges.
Answer: 8 vertices and 15 edges
4.
\deg(u) = 6,\ \deg(w) = 2
The 2 vertices of U have 6 neighbors; the 6 of W have 2.
2 \cdot 6 + 6 \cdot 2 = 24
Add all the degrees.
2 \cdot 6 = 12
The number of edges is mn.
2 \cdot 12 = 24
Twice the edges: the lemma checks.
Answer: two vertices of degree 6 and six of degree 2; 24 = 2 · 12
5.
1, 2, 3, 1
Any three vertices of K_4 form a triangle.
Answer: no; it has an odd cycle of length 3
6.
a \in U;\ b, d, e \in W
Start at a; its neighbors are b, d and e.
c \in U
The uncolored neighbor of b (and of d).
ab, bc, cd, da, ae
Every edge joins U to W.
Answer: yes; U = {a, c}, W = {b, d, e}
7.
12,\ 23,\ 31
These three edges exist.
1, 2, 3, 1
They form a cycle of length 3.
Answer: no; 1, 2, 3, 1 is an odd cycle (so is 1, 3, 4, 5, 1)
8.
1 \cdot 9 = 9,\ 2 \cdot 8 = 16
Sides of sizes m and 10 − m allow at most m(10 − m) edges.
3 \cdot 7 = 21,\ 4 \cdot 6 = 24
Keep trying side sizes.
5 \cdot 5 = 25
Equal sides give the most.
Answer: 25 edges, in K_{5,5}
9.
U: 000, 011, 101, 110
Strings with an even number of 1s.
W: 001, 010, 100, 111
Strings with an odd number of 1s.
\text{one digit changes}Each edge changes one digit, so it changes the count of 1s by 1 and crosses sides.
Answer: yes
10.
8 \cdot 3 = 24
Add the volunteers’ degrees: this is |E|.
6d = 24
The shifts’ degrees also add to |E|.
d = 4
Divide both sides by 6.
Answer: 4 volunteers per shift
Bipartite graphs FAQ
How do you know if a graph is bipartite?
Try to two-color it: color one vertex, give its neighbors the other color, and keep alternating. If no edge joins two vertices of the same color, the graph is bipartite.
Why can’t a bipartite graph have an odd cycle?
Each edge switches sides, so a walk returns to its starting side only after an even number of edges. A cycle of odd length would end on the wrong side.
How many edges does a complete bipartite graph have?
The complete bipartite graph K_{m,n} has mn edges and m + n vertices. For example, K_{3,3} has 9 edges.
Is every tree bipartite?
Yes. A tree has no cycles at all, so it has no odd cycles, and the two-coloring test always succeeds.
Summary
- A bipartite graph splits its vertices into U and W, with every edge joining U to W.
- Equivalently, its vertices can be colored with two colors so that every edge joins different colors.
- A graph is bipartite exactly when it has no odd cycle.
- K_{m,n} has m + n vertices and mn edges.
- In a bipartite graph, the degrees in U and the degrees in W each add up to |E|.
Previous lesson: Graph Isomorphism
Next lesson: Euler Paths and Circuits
Back to the Discrete Math Index