Two sides, edges only between
No edge within a side. The sides are independent sets, and the graph is exactly a relation between two populations.
A bipartite graph splits into two independent sets with every edge crossing between them. That is exactly the graphs with no odd cycle, and the equivalence is proved by a colouring argument.
Core ideas
Three characterisations of one class, and the third is what makes the class easy to test for.
No edge within a side. The sides are independent sets, and the graph is exactly a relation between two populations.
A graph is bipartite exactly when every cycle has even length. Nothing else can prevent it.
Two-colour greedily by breadth-first search; a conflict is an odd cycle. Linear time, unlike almost every other question in this course.
The material
Definition, the odd-cycle theorem, the test, and the applications.
A graph is bipartite when its vertices can be partitioned into sets X and Y such that every edge joins a vertex of X to one of Y. Equivalently, X and Y are independent sets.
C₄, C₆ and every tree are bipartite. C₃, C₅ and Kₙ for n ≥ 3 are not. The complete bipartite graph K_{m,n} is bipartite by construction and has mn edges.
A graph is bipartite if and only if it contains no cycle of odd length.
(⟹) Suppose the graph is bipartite and consider any cycle. Each step crosses from one side to the other, so after an odd number of steps you are on the opposite side from where you started. A cycle returns to its start, so its length must be even.
(⟸) Suppose there is no odd cycle. Work within one component; pick a vertex r and put each vertex in X or Y according to whether its distance from r is even or odd.
If some edge joined two vertices of the same class, the two paths from r to its ends, together with that edge, would give a closed walk of odd length, and a closed walk of odd length contains an odd cycle. So no such edge exists and the partition works. Repeat for each component.
□
The second direction is the substantive one, and the construction it uses is exactly the algorithm: colour by parity of distance from a root. The proof and the test are the same thing.
Breadth-first search from each unvisited vertex, colouring each vertex opposite to its parent. If an edge is ever found joining two vertices of the same colour, the graph is not bipartite and that edge closes an odd cycle. Otherwise the colouring is a bipartition. The cost is Θ(n + |E|).
Contrast that with “Graph Colouring”'s chromatic number, where deciding 3-colourability is NP-complete. Two colours is easy and three is hard, and the boundary is exactly here.
A matching is a set of edges no two of which share a vertex. In a bipartite graph, a matching pairs up members of X with members of Y.
A bipartite graph with parts X and Y has a matching saturating X if and only if every subset S ⊆ X has at least |S| neighbours in Y.
The condition is obviously necessary — |S| vertices need |S| distinct partners — and the content of the theorem is that it is sufficient. Note the resemblance to the pigeonhole principle: if some set of k vertices has fewer than k neighbours, two of them must share, and no matching exists.
Interactive
Your graph, the course's algorithms
Method
Colour by breadth-first search; a conflict is the proof it fails.
Say colour 0. Any starting choice works; the two colourings differ by swapping.
Proceeding by breadth-first search, so each vertex is coloured when first reached.
An edge joining two vertices of the same colour means no bipartition exists, and it closes an odd cycle.
Each component is coloured independently. A disconnected graph is bipartite exactly when all its components are.
C₆ and C₅, coloured by distance parity from vertex 1.
The failing edge is not an accident of the colouring order: any attempt produces a conflict somewhere, because the obstruction is the odd cycle and it is present regardless of where the search starts.
Two-colour a graph of your own until it fails, then trace the paths from the root to both ends of the offending edge. Together with the edge they form the odd cycle.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.