Definition
3-Colouring Problem
The 3-colouring problem is a decision problem.
Question: Does there exist a colouring of the vertices of
with three colours such that adjacent vertices always have different colours?
NP-Membership
The 3-colouring problem is in NP. There are several equivalent ways to show this.
Let
Here, the certificate is a colouring function
Why this proves NP-membership
A nondeterministic algorithm may guess one of three colours for each vertex and then check in polynomial time whether the resulting assignment is a valid 3-colouring.
Reductions
Reduction to SAT
Let
For each vertex
The intended meaning is that
We define a reduction
where:
ensures that every vertex gets at least one colour,
ensures that no vertex gets two different colours at the same time, and
ensures that adjacent vertices do not receive the same colour.
Therefore,
Branching
The trivial deterministic algorithm tries all three colours for every vertex. For
time, up to the cost of checking a colouring.
For 3-colouring, one can do better than this basic branching by using two facts:
- the names of the three colours are symmetric;
- a vertex adjacent to an already coloured vertex has at most two compatible colours left.
First assume the input graph is connected. If an algorithm works for connected graphs, disconnected graphs can be handled by solving each connected component separately.
Choose one vertex
Then repeatedly choose an unprocessed vertex
Since
The running time follows from the branching tree. The first vertex has only one option, because its colour may be fixed by symmetry. Every later vertex has at most two options. At each step, it takes at most
Therefore 3-colouring can be solved exactly and deterministically in time
where
This breaks the trivial
More advanced exact algorithms improve the base further. For example, 3-colouring can be solved in time
where