Bipartite Two-Coloring and Odd Cycles
Try to split an arbitrary graph into two sides and inspect an odd-cycle certificate when that is impossible.
Free theory articleTry to split an arbitrary graph into two sides and inspect an odd-cycle certificate when that is impossible.
Concept & interpretation
A graph is bipartite if its vertices can be divided into two disjoint and independent sets such that every edge connects a vertex in one set to a vertex in the other set. We can test if a graph is bipartite by attempting to two-color it using Breadth-First Search (BFS). If we successfully color the entire graph with two colors without any adjacent vertices sharing a color, the graph is bipartite. If we encounter a conflict (two adjacent vertices with the same color), the graph is not bipartite, and the conflict reveals an odd-length cycle, which is a mathematical proof that the graph cannot be bipartite.
Experimenting with the Module
You can test graphs interactively at https://riano.app/module/bipartite-two-coloring.
- Enter the edges of a graph in the Edges input (e.g.,
0 1;1 2;2 3;3 4;0 4). - Click Step to dequeue one vertex, scan its neighbors and reveal the resulting colors and queue.
- Observe the queue, the assigned colors (blue and green), and the BFS tree structure forming as solid lines.
- Alternatively, click Finish to immediately compute the terminal result.
- If the graph is not bipartite, the module will highlight the odd cycle in red and display it in the results panel.
- Use Reset to rewind the trace and try different graph configurations.