Sub topic 4
The Odd Cycle Theorem
This chapter assumes you know basic graph terms (vertices, edges, paths, cycles), the definition of a bipartite graph, and the idea of a proper two-colouring from the previous chapters. It also uses shortest-path distance, which is the number of edges on the shortest path between two vertices.
So far you have a definition: a graph is bipartite when its vertices split into two sides and every edge crosses between them. That definition is hard to check directly, because the number of possible splits grows exponentially with the number of vertices. The Odd Cycle Theorem replaces it with a structural test that leads straight to a linear-time algorithm.
The Statement
Theorem. A graph is bipartite if and only if it contains no cycle of odd length.
A cycle's length is its number of edges. A triangle has length 3, so any graph containing a triangle is not bipartite. A square has length 4, and on its own it is bipartite.
| Graph | Odd cycle? | Bipartite? |
|---|---|---|
| Path on 5 vertices | No cycles at all | Yes |
| Any tree | No cycles at all | Yes |
| Cycle of length 6 | No | Yes |
| Cycle of length 5 | Yes | No |
| Complete graph on 3 vertices | Yes (triangle) | No |
The proof has two directions.
Bipartite Implies No Odd Cycle
Suppose the vertices split into sides A and B, with every edge joining A to B. Walk around any cycle. Each edge moves you to the other side. To get back to the vertex where you started, you must have switched sides an even number of times. So every cycle has even length.
No Odd Cycle Implies Bipartite
This direction does the real work, because it tells you how to build the colouring. Assume the graph is connected and has no odd cycle. A disconnected graph is handled one component at a time, which a later chapter covers.
Pick any root vertex r. Let d(v) be the shortest-path distance from r to v. Colour v with 0 if d(v) is even and with 1 if d(v) is odd.
We need to show that no edge joins two vertices of the same colour. Take an edge between u and v.
- Distances to adjacent vertices differ by at most 1. A path to u followed by the edge to v reaches v, so d(v) ≤ d(u) + 1. The same argument works the other way round.
- So if d(u) and d(v) have the same parity, they must be equal. Call that value k.
- Take a shortest path P from r to u and a shortest path Q from r to v. Let w be the last vertex along P that also lies on Q. Every vertex on a shortest path sits at its true distance from r, so w is at position d(w) = j on both paths.
- The section of P from w to u has length k − j. So does the section of Q from w to v. These two sections share only w.
- Join them with the edge u–v. The result is a cycle of length (k − j) + (k − j) + 1 = 2(k − j) + 1, which is odd.
That contradicts the assumption that the graph has no odd cycle. So every edge joins vertices of different parity, and the parity colouring is a proper two-colouring.
Common Mistakes
- Checking only short cycles. Ruling out triangles is not enough. A cycle of length 5 or 101 also breaks bipartiteness.
- Counting vertices in the wrong place. In a simple cycle the number of vertices equals the number of edges. In a path, the vertex count is one more than the edge count. Measure parity on edges.
- Assuming the two shortest paths are disjoint from the root. They often share a prefix. The proof works because it branches at w, the last shared vertex, and not at r.
Exercise
A connected graph contains cycles of lengths 4, 6, and 10 and no other cycles. Is it bipartite? Then suppose you add one edge joining two vertices at the same BFS depth from some root. What can you say about the new graph?
Show answer
Every cycle in the original graph has even length, so by the Odd Cycle Theorem it is bipartite. The added edge joins two vertices with the same depth parity. By the proof's argument, that edge together with the two shortest paths back to their last common vertex forms an odd cycle, so the new graph is not bipartite.
Exercise
In the proof, why can't an edge u–v have d(u) = 2 and d(v) = 4?
Show answer
A shortest path to u followed by the edge u–v is a path to v of length 3, so d(v) ≤ 3. Distances of adjacent vertices differ by at most 1.