Loading [MathJax]/extensions/TeX/mathchoice.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

5.8: Graph Coloring

( \newcommand{\kernel}{\mathrm{null}\,}\)

As we briefly discussed in Section 1.2, the most famous graph coloring problem is certainly the map coloring problem, proposed in the nineteenth century and finally solved in 1976.

Definition 5.8.1: A Proper Coloring

A proper coloring of a graph is an assignment of colors to the vertices of the graph so that no two adjacent vertices have the same color.

Usually we drop the word "proper'' unless other types of coloring are also under discussion. Of course, the "colors'' don't have to be actual colors; they can be any distinct labels—integers, for example. If a graph is not connected, each connected component can be colored independently; except where otherwise noted, we assume graphs are connected. We also assume graphs are simple in this section.

Graph coloring has many applications in addition to its intrinsic interest.

Example 5.8.1

If the vertices of a graph represent academic classes, and two vertices are adjacent if the corresponding classes have people in common, then a coloring of the vertices can be used to schedule class meetings. Here the colors would be schedule times, such as 8MWF, 9MWF, 11TTh, etc.

Example 5.8.2

If the vertices of a graph represent radio stations, and two vertices are adjacent if the stations are close enough to interfere with each other, a coloring can be used to assign non-interfering frequencies to the stations.

Example 5.8.3

If the vertices of a graph represent traffic signals at an intersection, and two vertices are adjacent if the corresponding signals cannot be green at the same time, a coloring can be used to designate sets of signals than can be green at the same time.

Graph coloring is closely related to the concept of an independent set.

Definition 5.8.2: Independent

A set S of vertices in a graph is independent if no two vertices of S are adjacent.

If a graph is properly colored, the vertices that are assigned a particular color form an independent set. Given a graph G it is easy to find a proper coloring: give every vertex a different color. Clearly the interesting quantity is the minimum number of colors required for a coloring. It is also easy to find independent sets: just pick vertices that are mutually non-adjacent. A single vertex set, for example, is independent, and usually finding larger independent sets is easy. The interesting quantity is the maximum size of an independent set.

Definition 5.8.3: Chromatic Number

The chromatic number of a graph G is the minimum number of colors required in a proper coloring; it is denoted χ(G). The independence number of G is the maximum size of an independent set; it is denoted α(G).

The natural first question about these graphical parameters is: how small or large can they be in a graph G with n vertices. It is easy to see that

1χ(G)n1α(G)n

and that the limits are all attainable: A graph with no edges has chromatic number 1 and independence number n, while a complete graph has chromatic number n and independence number 1. These inequalities are thus not very interesting. We will see some that are more interesting.

Another natural question: What is the relation between the chromatic number of a graph G and chromatic number of a subgraph of G? This too is simple, but quite useful at times.

Theorem 5.8.1

If H is a subgraph of G, χ(H)χ(G).

Proof

Any coloring of G provides a proper coloring of H, simply by assigning the same colors to vertices of H that they have in G. This means that H can be colored with χ(G) colors, perhaps even fewer, which is exactly what we want.

Often this fact is interesting "in reverse''. For example, if G has a subgraph H that is a complete graph Km, then χ(H)=m and so χ(G)m. A subgraph of G that is a complete graph is called a clique, and there is an associated graphical parameter.

Definition 5.8.4: Clique Number

The clique number of a graph G is the largest m such that Km is a subgraph of G.

It is tempting to speculate that the only way a graph G could require m colors is by having such a subgraph. This is false; graphs can have high chromatic number while having low clique number; see Figure 5.8.1. It is easy to see that this graph has χ3, because there are many 3-cliques in the graph. In general it can be difficult to show that a graph cannot be colored with a given number of colors, but in this case it is easy to see that the graph cannot in fact be colored with three colors, because so much is "forced''. Suppose the graph can be colored with 3 colors. Starting at the left if vertex v1 gets color 1, then v2 and v3 must be colored 2 and 3, and vertex v4 must be color 1. Continuing, v10 must be color 1, but this is not allowed, so χ>3. On the other hand, since v10 can be colored 4, we see χ=4.

Paul Erdős showed in 1959 that there are graphs with arbitrarily large chromatic number and arbitrarily large girth (the girth is the size of the smallest cycle in a graph). This is much stronger than the existence of graphs with high chromatic number and low clique number.

clipboard_e0b2a1b3c1e99f0bb79cb3048292389e2.png
Figure 5.8.1: A graph with clique number 3 and chromatic number 4.

Bipartite graphs with at least one edge have chromatic number 2, since the two parts are each independent sets and can be colored with a single color. Conversely, if a graph can be 2-colored, it is bipartite, since all edges connect vertices of different colors. This means it is easy to identify bipartite graphs: Color any vertex with color 1; color its neighbors color 2; continuing in this way will or will not successfully color the whole graph with 2 colors. If it fails, the graph cannot be 2-colored, since all choices for vertex colors are forced.

If a graph is properly colored, then each color class (a color class is the set of all vertices of a single color) is an independent set.

Theorem 5.8.2

In any graph G on n vertices, nαχ.

Proof

Suppose G is colored with χ colors. Since each color class is independent, the size of any color class is at most α. Let the color classes be V1,V2,,Vχ. Then n=χi=1|Vi|χα, as desired.

We can improve the upper bound on χ(G) as well. In any graph G, Δ(G) is the maximum degree of any vertex.

Theorem 5.8.3

In any graph G, χΔ+1.

Proof

We show that we can always color G with Δ+1 colors by a simple greedy algorithm: Pick a vertex vn, and list the vertices of G as v1,v2,,vn so that if i<j, d(vi,vn)d(vj,vn), that is, we list the vertices farthest from vn first. We use integers 1,2,,Δ+1 as colors. Color v1 with 1. Then for each vi in order, color vi with the smallest integer that does not violate the proper coloring requirement, that is, which is different than the colors already assigned to the neighbors of vi. For i<n, we claim that vi is colored with one of 1,2,,Δ.

This is certainly true for v1. For 1<i<n, vi has at least one neighbor that is not yet colored, namely, a vertex closer to vn on a shortest path from vn to vi. Thus, the neighbors of vi use at most Δ1 colors from the colors 1,2,,Δ, leaving at least one color from this list available for vi.

Once v1,,vn1 have been colored, all neighbors of vn have been colored using the colors 1,2,,Δ, so color Δ+1 may be used to color vn.

Note that if d(vn)<Δ, even vn may be colored with one of the colors 1,2,,Δ. Since the choice of vn was arbitrary, we may choose vn so that d(vn)<Δ, unless all vertices have degree Δ, that is, if G is regular. Thus, we have proved somewhat more than stated, namely, that any graph G that is not regular has χΔ. (If instead of choosing the particular order of v1,,vn that we used we were to list them in arbitrary order, even vertices other than vn might require use of color Δ+1. This gives a slightly simpler proof of the stated theorem.) We state this as a corollary.

Corollary 5.8.1

If G is not regular, χΔ.

There are graphs for which χ=Δ+1: any cycle of odd length has Δ=2 and χ=3, and Kn has Δ=n1 and χ=n. Of course, these are regular graphs. It turns out that these are the only examples, that is, if G is not an odd cycle or a complete graph, then χ(G)Δ(G).

Theorem 5.8.4: Brook's Theorem

If G is a graph other than Kn or C2n+1, χΔ.

The greedy algorithm will not always color a graph with the smallest possible number of colors. Figure 5.8.2 shows a graph with chromatic number 3, but the greedy algorithm uses 4 colors if the vertices are ordered as shown.

clipboard_e9c26e6979f56c438ac89208e47357f32.png
Figure 5.8.2: A greedy coloring on the left and best coloring on the right.

In general, it is difficult to compute χ(G), that is, it takes a large amount of computation, but there is a simple algorithm for graph coloring that is not fast. Suppose that v and w are non-adjacent vertices in G. Denote by G+{v,w}=G+e the graph formed by adding edge e={v,w} to G. Denote by G/e the graph in which v and w are "identified'', that is, v and w are replaced by a single vertex x adjacent to all neighbors of v and w. (But note that we do not introduce multiple edges: if u is adjacent to both v and w in G, there will be a single edge from x to u in G/e.)

Consider a proper coloring of G in which v and w are different colors; then this is a proper coloring of G+e as well. Also, any proper coloring of G+e is a proper coloring of G in which v and w have different colors. So a coloring of G+e with the smallest possible number of colors is a best coloring of G in which v and w have different colors, that is, χ(G+e) is the smallest number of colors needed to color G so that v and w have different colors.

If G is properly colored and v and w have the same color, then this gives a proper coloring of G/e, by coloring x in G/e with the same color used for v and w in G. Also, if G/e is properly colored, this gives a proper coloring of G in which v and w have the same color, namely, the color of x in G/e. Thus, χ(G/e) is the smallest number of colors needed to properly color G so that v and w are the same color.

The upshot of these observations is that χ(G)=min(χ(G+e),χ(G/e)). This algorithm can be applied recursively, that is, if G1=G+e and G2=G/e then χ(G1)=min(χ(G1+e),χ(G1/e)) and χ(G2)=min(χ(G2+e),χ(G2/e)), where of course the edge e is different in each graph. Continuing in this way, we can eventually compute χ(G), provided that eventually we end up with graphs that are "simple'' to color. Roughly speaking, because G/e has fewer vertices, and G+e has more edges, we must eventually end up with a complete graph along all branches of the computation. Whenever we encounter a complete graph Km it has chromatic number m, so no further computation is required along the corresponding branch. Let's make this more precise.

Theorem 5.8.5

The algorithm above correctly computes the chromatic number in a finite amount of time.

Proof

Suppose that a graph G has n vertices and m edges. The number of pairs of non-adjacent vertices is \text{na}(G)={n\choose 2}-m. The proof is by induction on \text{na}.

If \text{na}(G)=0 then G is a complete graph and the algorithm terminates immediately.

Now we note that \text{na}(G+e)< \text{na}(G) and \text{na}(G/e)< \text{na}(G): \text{na}(G+e)={n\choose 2}-(m+1)=\text{na}(G)-1 \nonumber and \text{na}(G/e)={n-1\choose 2}-(m-c), \nonumber where c is the number of neighbors that v and w have in common. Then \eqalign{ \text{na}(G/e)&={n-1\choose 2}-m+c\cr &\le {n-1\choose 2}-m+n-2\cr &={(n-1)(n-2)\over 2}-m+n-2\cr &={n(n-1)\over 2}-{2(n-1)\over 2}-m+n-2\cr &={n\choose 2} -m -1\cr &=\text{na}(G)-1.\cr }\nonumber

Now if \text{na}(G)>0, G is not a complete graph, so there are non-adjacent vertices v and w. By the induction hypothesis the algorithm computes \chi(G+e) and \chi(G/e) correctly, and finally it computes \chi(G) from these in one additional step.

While this algorithm is very inefficient, it is sufficiently fast to be used on small graphs with the aid of a computer.

Example \PageIndex{4}

We illustrate with a very simple graph:

clipboard_e9c18c9fbaec3905e06673d5b7c137868.png
Figure \PageIndex{3}

The chromatic number of the graph at the top is \min(3,4)=3. (Of course, this is quite easy to see directly.)


This page titled 5.8: Graph Coloring is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by David Guichard via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?