A graph is bipartite exactly when it has no odd cycle
Statement
A finite graph is bipartite if its vertices can be split into two classes such that every edge joins the two classes (equivalently, it can be coloured with colours so that adjacent vertices get different colours). Prove that a graph is bipartite if and only if it contains no cycle of odd length.
Hint
For "if": in each connected component pick a root and colour each vertex by the parity of its distance to the root. If some edge joins two vertices of the same colour, build a closed walk of odd length, and show that an odd closed walk contains an odd cycle.
Show solutionHide solution
Solution
() Suppose the classes are and . Going along a cycle, we alternate between and , and we return to the start, so the number of steps is even.
() Assume there is no odd cycle. It suffices to colour each connected component separately. In a component choose a root and give a vertex the colour of the parity of , the length of a shortest path from to .
Suppose an edge joins two vertices of the same parity. Then the walk "shortest path , the edge , shortest path " is a closed walk of length , which is odd.
Claim. A closed walk of odd length contains an odd cycle.
*Proof by strong induction on the length .* If no vertex repeats (except the start/end), the walk is a cycle, of odd length . Otherwise some vertex occurs twice in the walk, which splits it into two closed walks (from to ) whose lengths are positive, smaller than , and add up to . One of them is odd; apply the induction hypothesis to it.
So the edge would create an odd cycle, a contradiction. Hence every edge joins vertices of opposite parity, and the graph is bipartite.
Example. Trees, even cycles and grids have no odd cycle, so they can be -coloured. A triangle needs colours.
Lesson. Colour by parity of distance; an odd closed walk always hides an odd cycle.