Guest
Sign in to keep your graphs and progress.
Select an algorithm and generate steps to begin visualization
Every edge a colour, no clash at any vertex
Colours the edges so that no two at a vertex match: Δ colours on bipartite graphs by swapping alternating paths, at most Δ + 1 in general with Misra–Gries fan rotations
Select an algorithm and generate steps to begin visualization
An edge colouring gives each edge a colour so that the edges meeting at any vertex all differ. The fewest colours that work is the chromatic index. A vertex of degree Δ needs Δ colours on its own, so Δ is a lower bound, and Vizing proved in 1964 that Δ + 1 always suffices for simple graphs. Every graph is therefore class 1, needing Δ colours, or class 2, needing Δ + 1. König showed in 1916 that bipartite graphs are always class 1. Deciding the class of a general graph is NP-hard, even when every vertex has degree three. Each colour class is a matching, so an edge colouring splits the edges into matchings.
Edges are coloured one at a time. On a bipartite graph the run takes a colour a free at one end and a colour b free at the other. If a is free at both ends it is used at once. Otherwise the path from the second end whose edges alternate b and a has its two colours swapped, which keeps every vertex proper and, because the graph has no odd cycle, never reaches the first end, so a becomes free at both. On other graphs the run uses the Misra–Gries algorithm (1992): it builds a fan of neighbours around one end, inverts an alternating path from that centre, rotates the colours along part of the fan and colours the last edge, never using more than Δ + 1 colours. The time is O(n·m). The visualizer colours the edges, draws each alternating path in green and enlarges the fan. Misra–Gries guarantees Δ + 1, not the minimum, so on a class 1 graph that is not bipartite it may still use Δ + 1 colours.
A round-robin tournament is an edge colouring of a complete graph, each colour one round of games, and for an even number of teams n − 1 rounds suffice. Timetables are edge colourings of the bipartite graph between teachers and classes, each colour a period, which König's theorem makes as short as the busiest teacher or class. The same idea schedules transfers between pairs of devices, link activations in wireless networks where a radio talks to one neighbour at a time, and connections through switching fabrics.
One edge at a time, with the bipartite case and the general case side by side.
EdgeColour(G):
for each edge u–v:
if G is bipartite: // König, Δ colours
a = a colour free at u, b = a colour free at v
if a is used at v:
swap a and b on the a/b path from v
colour u–v with a
else: // Misra–Gries, Δ + 1
F = maximal fan of u starting at v
c = colour free at u, d = colour free at the last vertex of F
invert the c/d path from u
w = first vertex of F with d free (its prefix still a fan)
rotate the fan up to w, colour u–w with dBoth branches recolour only edges that are already coloured and keep the colouring proper after every step. A free colour always exists: in the general case each vertex has at most Δ edges and Δ + 1 colours are allowed, and in the bipartite case u–v itself is still uncoloured, so u and v use at most Δ − 1 of the Δ colours.
The page loads the Petersen graph: ten vertices, fifteen edges, every vertex of degree 3.
Example graph: The outer five-cycle A–B–C–D–E–A, the spokes A–F, B–G, C–H, D–I and E–J, and the inner pentagram F–H, H–J, J–G, G–I, I–F.
The Petersen graph has Δ = 3 but needs 4 colours: it is class 2. Three colours would split its 15 edges into three perfect matchings of 5 edges each, and the Petersen graph has no such split. So 4 is optimal here, not only the bound Misra–Gries guarantees.
Time: O(n·m) · Space: O(n·Δ)
Each of the m edges builds a fan of at most Δ vertices and may invert one alternating path of at most n edges, so each edge costs O(n) and the whole run O(n·m). Recording which colour is used at which vertex takes O(n·Δ). Faster methods exist, for bipartite graphs O(m log Δ) by Cole, Ost and Schirra.
Other ways to colour edges.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Greedy edge colouring | Speed matters more than the number of colours. Each edge takes the smallest colour free at both ends. | O(m·Δ), up to 2Δ − 1 colours |
| Repeated perfect matchings (Hopcroft–Karp) | A Δ-regular bipartite graph: remove a perfect matching Δ times, and each one is a colour class. | O(Δ·m·√n) |
| Exact search (SAT or ILP) | You must know whether Δ colours suffice for a graph that is not bipartite. The question is NP-complete even for cubic graphs. | Exponential in the worst case |
Related algorithms: Graph Coloring, DSatur Coloring, Hopcroft-Karp Matching, Edmonds' Blossom Algorithm (Maximum Matching), Bipartite Check