learngraphtheory.org

Guest User

Using app without sign in

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj

Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

DSatur Graph Coloring Calculator

Colour the most constrained vertex first

Greedy colouring that always colours the vertex whose neighbours use the most different colours

Time: O(V²)
Space: O(V)
Use Case: Timetabling, frequency assignment, register allocation
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About DSatur Coloring

DSatur is a greedy graph colouring algorithm published by Daniel Brélaz in 1979. Like every greedy method it gives each vertex the smallest colour its neighbours do not use, but it chooses the order as it goes: the next vertex is the one whose neighbours already show the most different colours, its saturation degree. Colouring the most constrained vertex first usually needs noticeably fewer colours than a fixed order.

How it works

At the start no vertex is coloured and every saturation is 0, so the vertex with the most neighbours goes first. After each step the saturations are updated: a vertex's saturation is the number of different colours among its coloured neighbours. The uncoloured vertex with the highest saturation is coloured next, ties broken by the number of uncoloured neighbours, and it gets the smallest colour that none of its neighbours has. The run ends when every vertex is coloured. A simple scan takes O(V²) time, a priority queue O((V + E) log V). DSatur is exact on bipartite graphs, cycles and wheels; in general minimum colouring is NP-hard and DSatur is a heuristic.

Applications

Graph colouring schedules exams and meetings without conflicts, assigns radio frequencies so that neighbouring transmitters do not interfere, allocates registers in compilers and solves Sudoku-like puzzles. DSatur is a standard baseline in timetabling and frequency assignment, and the starting point of exact branch-and-bound colouring algorithms. On this site it can be compared directly with Welsh-Powell greedy colouring.

Pseudocode

DSatur, short for degree of saturation, is a greedy colouring that chooses its order on the fly. The next vertex is always the one whose neighbours already use the most different colours, since it is the most constrained.

DSatur(graph):
    colour[v] = none for every v
    while some vertex is uncoloured:
        v = the uncoloured vertex with the largest saturation
            // saturation = number of distinct colours among neighbours
            // ties: most uncoloured neighbours, then first label
        colour[v] = the smallest colour no neighbour of v uses
        update the saturation of the neighbours of v
    return colour

Plain greedy colouring fixes the order in advance and can waste colours on vertices whose neighbours are still free. DSatur postpones decisions on easy vertices and colours the hard ones while choices are still open. The rule is known to be exact on bipartite graphs, cycles and wheels, and it performs well on many other graphs.

Worked example, step by step

Colour the example this page loads, a crown graph on eight vertices chosen because plain greedy colouring in label order handles it badly.

Example graph: Two sides, A, C, E, G and B, D, F, H. Each vertex is joined to every vertex on the other side except its partner: A-D, A-F, A-H, C-B, C-F, C-H, E-B, E-D, E-H, G-B, G-D and G-F. Every vertex has degree 3.

  1. Greedy in label order. For comparison, colouring A, B, C, D and so on in turn gives A 1, B 1 (B is not adjacent to A), C 2, D 2, E 3, F 3, G 4 and H 4. Four colours for a bipartite graph that needs only two.
  2. DSatur starts. All saturations are 0 and all degrees tie, so A is taken first and gets colour 1. Its neighbours D, F and H now have saturation 1.
  3. Follow the constraints. D is chosen next, with saturation 1, and gets colour 2. Its neighbours E and G now see colour 2. E is taken and gets colour 1, then B gets 2 because E is a neighbour, and C gets 1.
  4. Finish the sides. F sees only colour 1, from A and C, and gets 2. G sees only colour 2 and gets 1. Last, H sees only colour 1 and gets 2.

DSatur colours the crown graph with 2 colours, A, C, E, G in colour 1 and B, D, F, H in colour 2, which is optimal. The difference from greedy colouring comes entirely from the order: by always picking a vertex next to an already coloured one, DSatur effectively traces out the two sides of the bipartition, while label order mixes them and pays with two extra colours.

Complexity, and where it comes from

Time: O(V^2), or O((V + E) log V) with a heap · Space: O(V + E)

Each of the V steps selects the uncoloured vertex with the highest saturation. Scanning all vertices costs O(V) per step, giving O(V^2). Choosing the smallest free colour for v and updating its neighbours costs O(deg(v)) with a set of neighbour colours per vertex, which totals O(E) over the run. Keeping the uncoloured vertices in a priority queue keyed by saturation and degree reduces selection to O(log V), and since each saturation can increase at most once per edge, the total becomes O((V + E) log V). Memory holds the colours and one set of seen colours per vertex.

When to use DSatur Coloring, and when not to

Graph colouring is NP-hard, so every fast method is a heuristic. They differ in how much effort goes into the order.

AlternativePrefer it whenCost
Greedy (Welsh-Powell)Speed is all that matters. Colour vertices in decreasing degree order with the smallest free colour.O(V log V + E)
Recursive largest first (RLF)Better colourings are worth more time. It builds one colour class at a time and often beats DSatur.O(V^3)
Backtracking or branch and boundYou need the exact chromatic number on a small graph. DSatur ordering is the usual branching rule.exponential
Tabu search (Tabucol)Large hard instances such as timetabling, where a local search can improve the DSatur result.tunable

Common pitfalls

  • Counting coloured neighbours instead of colours. Saturation is the number of distinct colours among the neighbours. A vertex with three neighbours all in colour 1 has saturation 1, not 3. Counting neighbours turns DSatur back into a degree heuristic.
  • Not updating saturations after each step. Saturation changes every time a neighbour is coloured. Computing it once at the start and sorting by it gives a static order and loses the whole point of the method.
  • Expecting an optimal colouring. DSatur is exact on bipartite graphs but not in general. There are 3-colourable graphs on which it uses 4 colours, and for large random graphs it typically needs noticeably more colours than the best known colourings.
  • Ignoring tie-breaking. Ties in saturation are very common, especially at the start. Breaking them by degree in the uncoloured subgraph, as Brélaz proposed, matters for quality. Breaking them arbitrarily makes results vary between runs.

Frequently asked questions

What is the DSatur algorithm?
DSatur is a greedy graph colouring heuristic proposed by Daniel Brélaz in 1979. At every step it colours the uncoloured vertex whose neighbours use the largest number of distinct colours, breaking ties by degree, and gives it the smallest colour not used by any neighbour.
What is the saturation degree of a vertex?
The number of different colours that appear among its already coloured neighbours. A high saturation means the vertex has few colours left to choose from, so DSatur colours it first.
Is DSatur optimal?
It is optimal on bipartite graphs, cycles and wheels. In general it is a heuristic: graph colouring is NP-hard and DSatur can use more colours than necessary, although it usually beats plain greedy colouring.
What is the time complexity of DSatur?
O(V^2) with a simple scan for the next vertex, or O((V + E) log V) with a priority queue. Either is fast enough for graphs with many thousands of vertices.
What is DSatur used for?
Timetabling and exam scheduling, where conflicting events must get different slots, register allocation in compilers, frequency assignment in radio networks, and as the branching rule inside exact colouring algorithms.

Related algorithms: Graph Coloring, Bipartite Check, Maximal Clique, Chordality Check

Interactive Controls

Zoom Controls

41%
Nodes: 8
Edges: 12