learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Algorithm Selection

Select an algorithm and generate steps to begin visualization

Edge Coloring Visualizer

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

Time: O(n·m)
Space: O(n·Δ)
Use Case: Round-robin tournaments, school timetables, link scheduling in wireless networks, switch configuration
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Edge Coloring (Vizing, König)

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.

How it works

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.

Applications

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.

Pseudocode

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 d

Both 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.

Worked example, step by step

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.

  1. Not bipartite. The outer cycle has five edges, an odd cycle, so König does not apply and Misra–Gries runs with at most Δ + 1 = 4 colours.
  2. The first edges. A–B, A–F, F–H and B–C get colours 1, 2, 3 and 3 without any inversion.
  3. First inversion. For B–G the fan of B is G, A, C. Colour 2 is free at B and colour 1 at C, so the path of colours 1 and 2 from B, B–A and A–F, is inverted. Now colour 1 is free at B and B–G gets it.
  4. A fourth colour. G–I gets colour 4 although colour 2 was free at both ends. Misra–Gries takes the colour free at the last vertex of the fan, here B, where 1, 2 and 3 are all in use. It never exceeds Δ + 1 colours but does not try to save one.
  5. More inversions. C–H, D–I and I–F each need an inversion first, of 1, 3 and 1 edges. The remaining edges are coloured straight away.
  6. Done. All 15 edges are coloured with 4 colours, used on 4, 4, 4 and 3 edges.

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.

Complexity, and where it comes from

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.

When to use Edge Coloring (Vizing, König), and when not to

Other ways to colour edges.

AlternativePrefer it whenCost
Greedy edge colouringSpeed 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

Common pitfalls

  • Colouring greedily and stopping there. Giving each edge the smallest colour free at both ends can need up to 2Δ − 1 colours. The swaps and fan rotations are what bring it down to Δ or Δ + 1.
  • Expecting Δ colours from Misra–Gries. Misra–Gries guarantees Δ + 1, not the minimum. On a class 1 graph that is not bipartite it may still use Δ + 1, since deciding the class is NP-hard. In this example G–I gets colour 4 although colour 2 was free.
  • Multigraphs. Vizing's bound of Δ + 1 is for simple graphs. With parallel edges a multigraph can need up to 3Δ/2 colours (Shannon), so remove duplicates or use a method for multigraphs.

Frequently asked questions

What is the chromatic index?
The fewest colours in a proper edge colouring, written χ′(G). By Vizing it is Δ or Δ + 1 for every simple graph.
How does edge colouring schedule a tournament?
Teams are vertices and games are the edges of a complete graph. A colour class is a set of games with no team twice, one round. For an even number n of teams, K_n can be edge coloured with n − 1 colours, so n − 1 rounds suffice.
Why can the bipartite swap not reach the other end?
The path from v alternates colours a and b and starts with an a edge. If it reached u it would arrive on a b edge, since a is free at u, so the path would have even length and, with u–v, close a cycle of odd length, which a bipartite graph does not have.

Related algorithms: Graph Coloring, DSatur Coloring, Hopcroft-Karp Matching, Edmonds' Blossom Algorithm (Maximum Matching), Bipartite Check

An example graph: you can change it, or start blank.

Zoom Controls

39%
Nodes: 10
Edges: 15