Polynomial time Determining if a graph can be colored with 2 colors is equivalent to determining whether or not the graph is
bipartite, and thus computable in
linear time using
breadth-first search or
depth-first search. More generally, the chromatic number and a corresponding coloring of
perfect graphs can be computed in
polynomial time using
semidefinite programming.
Closed formulas for chromatic polynomials are known for many classes of graphs, such as forests, chordal graphs, cycles, wheels, and ladders, so these can be evaluated in polynomial time. If the graph is planar and has low branch-width (or is nonplanar but with a known
branch-decomposition), then it can be solved in polynomial time using dynamic programming. In general, the time required is polynomial in the graph size, but exponential in the branch-width.
Exact algorithms Brute-force search for a
k-coloring considers each of the k^n assignments of
k colors to
n vertices and checks for each if it is legal. To compute the chromatic number and the chromatic polynomial, this procedure is used for every k=1,\ldots,n-1, impractical for all but the smallest input graphs. Using
dynamic programming and a bound on the number of
maximal independent sets,
k-colorability can be decided in time and space O(2.4423^n). Using the principle of
inclusion–exclusion and
Yates's algorithm for the fast zeta transform,
k-colorability can be decided in time O(2^n n) for any
k. Faster algorithms are known for 3- and 4-colorability, which can be decided in time O(1.3289^n) and O(1.7272^n), respectively. Exponentially faster algorithms are also known for 5- and 6-colorability, as well as for restricted families of graphs, including sparse graphs.
Contraction The
contraction G/uv of a graph
G is the graph obtained by identifying the vertices
u and
v, and removing any edges between them. The remaining edges originally incident to
u or
v are now incident to their identification (
i.e., the new fused node
uv). This operation plays a major role in the analysis of graph coloring. The chromatic number satisfies the
recurrence relation: : \chi(G) = \text{min} \{ \chi(G+uv), \chi(G/uv)\} due to , where
u and
v are non-adjacent vertices, and G+uv is the graph with the edge added. Several algorithms are based on evaluating this recurrence and the resulting computation tree is sometimes called a Zykov tree. The running time is based on a heuristic for choosing the vertices
u and
v. The chromatic polynomial satisfies the following recurrence relation : P(G-uv, k)= P(G/uv, k)+ P(G, k), where
u and
v are adjacent vertices, and G-uv is the graph with the edge removed. P(G - uv, k) represents the number of possible proper colorings of the graph, where the vertices may have the same or different colors. Then the proper colorings arise from two different graphs. To explain, if the vertices
u and
v have different colors, then we might as well consider a graph where
u and
v are adjacent. If
u and
v have the same colors, we might as well consider a graph where
u and
v are contracted. Tutte's curiosity about which other graph properties satisfied this recurrence led him to discover a bivariate generalization of the chromatic polynomial, the
Tutte polynomial. These expressions give rise to a recursive procedure called the
deletion–contraction algorithm, which forms the basis of many algorithms for graph coloring. The running time satisfies the same recurrence relation as the
Fibonacci numbers, so in the worst case the algorithm runs in time within a polynomial factor of \left(\tfrac{1+\sqrt{5}}2\right)^{n+m}=O(1.6180^{n+m}) for
n vertices and
m edges. The analysis can be improved to within a polynomial factor of the number t(G) of
spanning trees of the input graph. In practice,
branch and bound strategies and
graph isomorphism rejection are employed to avoid some recursive calls. The running time depends on the heuristic used to pick the vertex pair.
Greedy coloring The
greedy algorithm considers the vertices in a specific order v_1, ..., v_n and assigns to v_i the smallest available color not used by v_i's neighbours among v_1, ..., v_{i-1}, adding a fresh color if needed. The quality of the resulting coloring depends on the chosen ordering. There exists an ordering that leads to a greedy coloring with the optimal number of \chi(G) colors. On the other hand, greedy colorings can be arbitrarily bad; for example, the
crown graph on
n vertices can be 2-colored, but has an ordering that leads to a greedy coloring with n/2 colors. For
chordal graphs, and for special cases of chordal graphs such as
interval graphs and
indifference graphs, the greedy coloring algorithm can be used to find optimal colorings in polynomial time, by choosing the vertex ordering to be the reverse of a
perfect elimination ordering for the graph. The
perfectly orderable graphs generalize this property, but it is NP-hard to find a perfect ordering of these graphs. If the vertices are ordered according to their
degrees, the resulting greedy coloring uses at most \text{max}_i \text{ min} \{d(x_i ) + 1, i\} colors, at most one more than the graph's maximum degree. This heuristic is sometimes called the Welsh–Powell algorithm. Another heuristic due to
Brélaz establishes the ordering dynamically while the algorithm proceeds, choosing next the vertex adjacent to the largest number of different colors. Many other graph coloring heuristics are similarly based on greedy coloring for a specific static or dynamic strategy of ordering the vertices, these algorithms are sometimes called
sequential coloring algorithms. The maximum (worst) number of colors that can be obtained by the greedy algorithm, by using a vertex ordering chosen to maximize this number, is called the
Grundy number of a graph.
Heuristic algorithms Two well-known polynomial-time heuristics for graph colouring are the
DSatur and
recursive largest first (RLF) algorithms. Similarly to the
greedy colouring algorithm, DSatur colours the
vertices of a
graph one after another, expending a previously unused colour when needed. Once a new
vertex has been coloured, the algorithm determines which of the remaining uncoloured vertices has the highest number of different colours in its neighbourhood and colours this vertex next. This is defined as the
degree of saturation of a given vertex. The
recursive largest first algorithm operates in a different fashion by constructing each color class one at a time. It does this by identifying a
maximal independent set of vertices in the graph using specialised heuristic rules. It then assigns these vertices to the same color and removes them from the graph. These actions are repeated on the remaining subgraph until no vertices remain. The worst-case complexity of DSatur is O(n^2), where n is the number of vertices in the graph. The algorithm can also be implemented using a binary heap to store saturation degrees, operating in O((n+m)\log n) where m is the number of edges in the graph. This produces much faster runs with sparse graphs. The overall complexity of RLF is slightly higher than
DSatur at O(mn). DSatur and RLF are
exact for
bipartite,
cycle, and
wheel graphs.
Parallel and distributed algorithms It is known that a -chromatic graph can be -colored in the deterministic LOCAL model, in O(n^{1/\alpha}). rounds, with \alpha = \left\lfloor \frac{c - 1}{\chi - 1} \right\rfloor. A matching lower bound of \Omega(n^{1/\alpha}) rounds is also known. This lower bound holds even if quantum computers that can exchange quantum information, possibly with a pre-shared entangled state, are allowed. In the field of
distributed algorithms, graph coloring is closely related to the problem of
symmetry breaking. The current state-of-the-art randomized algorithms are faster for sufficiently large maximum degree Δ than deterministic algorithms. The fastest randomized algorithms employ the
multi-trials technique by Schneider and Wattenhofer. In a
symmetric graph, a
deterministic distributed algorithm cannot find a proper vertex coloring. Some auxiliary information is needed in order to break symmetry. A standard assumption is that initially each node has a
unique identifier, for example, from the set . Put otherwise, we assume that we are given an
n-coloring. The challenge is to
reduce the number of colors from
n to, e.g., Δ + 1. The more colors are employed, e.g.
O(Δ) instead of Δ + 1, the fewer communication rounds are required. A straightforward distributed version of the greedy algorithm for (Δ + 1)-coloring requires Θ(
n) communication rounds in the worst case – information may need to be propagated from one side of the network to another side. The simplest interesting case is an
n-
cycle. Richard Cole and
Uzi Vishkin show that there is a distributed algorithm that reduces the number of colors from
n to
O(log
n) in one synchronous communication step. By iterating the same procedure, it is possible to obtain a 3-coloring of an
n-cycle in
O(
n) communication steps (assuming that we have unique node identifiers). The function ,
iterated logarithm, is an extremely slowly growing function, "almost constant". Hence the result by Cole and Vishkin raised the question of whether there is a
constant-time distributed algorithm for 3-coloring an
n-cycle. showed that this is not possible: any deterministic distributed algorithm requires Ω(
n) communication steps to reduce an
n-coloring to a 3-coloring in an
n-cycle. The technique by Cole and Vishkin can be applied in arbitrary bounded-degree graphs as well; the running time is poly(Δ) +
O(
n). The technique was extended to
unit disk graphs by Schneider and Wattenhofer. The fastest deterministic algorithms for (Δ + 1)-coloring for small Δ are due to Leonid Barenboim, Michael Elkin and Fabian Kuhn. The algorithm by Barenboim et al. runs in time
O(Δ) + (
n)/2, which is optimal in terms of
n since the constant factor 1/2 cannot be improved due to Linial's lower bound. use network decompositions to compute a Δ+1 coloring in time 2 ^{O\left(\sqrt{\log n}\right)} . The problem of edge coloring has also been studied in the distributed model. achieve a (2Δ − 1)-coloring in
O(Δ +
n) time in this model. The lower bound for distributed vertex coloring due to applies to the distributed edge coloring problem as well.
Decentralized algorithms Decentralized algorithms are ones where no
message passing is allowed (in contrast to distributed algorithms where local message passing takes place), and efficient decentralized algorithms exist that will color a graph if a proper coloring exists. These assume that a vertex is able to sense whether any of its neighbors are using the same color as the vertex i.e., whether a local conflict exists. This is a mild assumption in many applications e.g. in wireless channel allocation it is usually reasonable to assume that a station will be able to detect whether other interfering transmitters are using the same channel (e.g. by measuring the SINR). This sensing information is sufficient to allow algorithms based on learning automata to find a proper graph coloring with probability one.
Computational complexity Graph coloring is computationally hard. It is
NP-complete to decide if a given graph admits a
k-coloring for a given
k except for the cases
k ∈ . In particular, it is NP-hard to compute the chromatic number. The 3-coloring problem remains NP-complete even on 4-regular
planar graphs. On graphs with maximal degree 3 or less, however,
Brooks' theorem implies that the 3-coloring problem can be solved in linear time. Further, for every
k > 3, a
k-coloring of a planar graph exists by the
four color theorem, and it is possible to find such a coloring in polynomial time. However, finding the
lexicographically smallest 4-coloring of a planar graph is NP-complete. The best known
approximation algorithm computes a coloring of size at most within a factor
O(
n(log log
n)2(log n)−3) of the chromatic number. For all
ε > 0, approximating the chromatic number within
n1−
ε is
NP-hard. It is also NP-hard to color a 3-colorable graph with 5 colors, 4-colorable graph with 7 colours, and a
k-colorable graph with \textstyle\binom k {\lfloor k/2 \rfloor} - 1 colors for
k ≥ 5. Computing the coefficients of the chromatic polynomial is
#P-hard. In fact, even computing the value of \chi(G,k) is #P-hard at any
rational point k except for
k = 1 and
k = 2. There is no
FPRAS for evaluating the chromatic polynomial at any rational point
k ≥ 1.5 except for
k = 2 unless
NP =
RP. For edge coloring, the proof of Vizing's result gives an algorithm that uses at most Δ+1 colors. However, deciding between the two candidate values for the edge chromatic number is NP-complete. In terms of approximation algorithms, Vizing's algorithm shows that the edge chromatic number can be approximated to within 4/3, and the hardness result shows that no (4/3 −
ε)-algorithm exists for any
ε > 0 unless
P = NP. These are among the oldest results in the literature of approximation algorithms, even though neither paper makes explicit use of that notion. == Applications ==