Greedy Coloring
Greedy Coloring
2 Greedy coloring
We are often interested in proving that all graphs of a certain type are k-colorable for some k. Here,
it is not enough to draw a picture, because there could be infinitely many graphs of that type to
1
This document comes from the Math 3322 course webpage: http://facultyweb.kennesaw.edu/mlavrov/
courses/3322-fall-2024.php
1
color. Usually, the way we do this is to find an algorithm that tells us how to color the graphs we
care about, and then prove that the algorithm never uses too many colors.
The simplest graph coloring algorithm is the greedy coloring algorithm. This does the follow-
ing:
1. Number the vertices v1 , v2 , . . . , vn in an arbitrary order. (We will usually illustrate this by
drawing the graph so that the vertices are v1 , v2 , . . . , vn from left to right.)
2. Color the vertices in that order, giving vi the first color2 that does not appear on any of its
neighbors among v1 , v2 , . . . , vi−1 .
This is “greedy” because it does the first thing it can think of without thinking about future
consequences. Sometimes this backfires. The graph below is a tree, so it is bipartite—and 2-
colorable. But if we go from left to right, we get a 4-coloring (labels in red):
1 2 1 3 1 2 1 4
The truth about the greedy algorithm is that the result heavily depends on the order of vertices
v1 , v2 , . . . , vn that we picked at the start. In the example above, I had to carefully order the vertices
to get the tree to be 4-colored. On the other hand, if you want the tree to be 2-colored, you also
have to order the vertices at least a little bit carefully.
The following bound on chromatic number is what we’re guaranteed to get even if we take no care
in ordering the vertices:
Theorem 2.1. For any graph G, χ(G) ≤ ∆(G) + 1.
Proof. We will prove that the greedy algorithm never uses more than ∆(G)+1 colors. (Here, ∆(G) is
the maximum degree of G.) In other words, if our colors come from the set S = {1, 2, . . . , ∆(G)+1},
the greedy algorithm will never get stuck.
When we are coloring vertex vi , it has at most ∆(G) neighbors among v1 , v2 , . . . , vi−1 . (It could
have fewer for two reasons: it’s possible that vi has fewer than ∆(G) neighbor, and it’s possible
that not all of them come before vi in the ordering we picked.)
Among those neighbors, there can be at most ∆(G) colors. Therefore there is at least one color
from the set S = {1, 2, . . . , ∆(G) + 1} that does not show up on any of them. We can continue by
giving vi the first such color.
Since the greedy algorithm never fails to pick a color from S, at the end we will have a proper
(∆(G) + 1)-coloring of G.
In the remainder of the lecture, we will apply the greedy coloring algorithm to two special cases of
the graph coloring problem. By putting some thought into the order we color the vertices, we will
be able to do better than the general bound in Theorem 2.1.
2
The “first color” assuming the colors are numbered 1, 2, 3, . . . , so that they have a definite order.
2
3 Greedily coloring planar graphs
Coloring a map is the origin of graph coloring, and when we color a map, we are usually coloring
a planar graph. (Put a vertex in each region on the map. Draw an edge between vertices if
their regions share a border. If the regions are connected—which is not always true in real-world
maps—then these edges can be drawn without crossing.)
By carefully ordering the vertices of a planar graph, we can get the greedy algorithm to perform
better. Here, the heuristic we will use is that it is good to leave low-degree vertices until
the end. If a vertex v does not have many neighbors, then even if v’s neighbors all get different
colors, there will be a color left for v.
What kind of low-degree vertices will planar graphs have? We can show the following:
Lemma 3.1. Every planar graph G has minimum degree δ(G) ≤ 5.
Proof. This is true for every planar graph with at most 6 vertices because at that point, you can’t
have any degrees bigger than 5.
For planar graphs with n ≥ 3 vertices and m edges, we have the inequality m ≤ 3n − 6. However,
if every vertex had degree 6 or more, we would have m ≥ 12 (6n) = 3n by the handshake lemma,
and we cannot have 3n ≤ 3n − 6. Therefore not all vertices have degree 6 or more: there must be
a vertex with degree 5 or less.
Just having a small minimum degree would not help us. What does help us is that when you remove
a vertex of minimum degree, we are left with a smaller planar graph, for which the following holds.
This lets us pick a good vertex ordering:
Lemma 3.2. Every planar graph G has a vertex ordering v1 , v2 , . . . , vn in which each vertex is
adjacent to at most 5 of the vertices that come before it.
Proof. We will prove this by induction on n. When n is small (say, n ≤ 6), any vertex ordering
will do.
Assume that the lemma is true for all (n − 1)-vertex planar graphs, and let G be an n-vertex planar
graph. By Lemma 3.1, G has a vertex v with deg(v) ≤ 5.
Apply the induction hypothesis to find a vertex ordering v1 , v2 , . . . , vn−1 of G − v. We can extend
it to a vertex ordering of G by setting vn = v. This vertex ordering does what we want for the first
n − 1 vertices by the induction hypothesis, and for the last vertex because deg(v) ≤ 5.
By induction, we can find such a vertex ordering for all n.
Using this lemma, we can get a bound on the chromatic number of arbitrary planar graphs!
Theorem 3.3. Every planar graph G has χ(G) ≤ 6.
Proof. Using the vertex ordering given by Lemma 3.2 and 6 colors, apply the greedy coloring
algorithm to color G. We will show that at every step in the greedy algorithm, one of the 6 colors
is available to color the next vertex.
3
Since each vertex vi is adjacent to at most 5 of the vertices that come before it, there will be at
least one of the colors from S = {1, 2, 3, 4, 5, 6} that does not appear on any of vi ’s already-colored
neighbors. So we can always continue by assigning vi some color from S. When we’re done, we will
have given G a proper 6-coloring.
Much more is true! In fact, there is a famous theorem called the Four Color Theorem that χ(G) ≤ 4
for every planar graph G. However, this is much harder to prove, to the point that all known proofs
require a computer to check many cases.
If planar graphs are the historically important application of graph coloring, then interval graphs
are the modern application. There are two important applications that boil down to coloring an
interval graph:
• Event scheduling. Here, we imagine that each interval [ai , bi ] represents an event starting at
time ai and ending at time bi . We want to put the events in rooms, but we have a limited
supply of rooms available, so we want to use as few as possible. However, if two events are
happening at the same time, they must be in different rooms.
• Register allocation: an application to computer science. Here, each interval [ai , bi ] represents
a variable in a computer program, which is initialized at step ai in the code, and last used at
step bi . There are special parts of computer memory called registers which are particularly
easy to access, but their number is limited. We want to see if the variables can be stored in
registers, so that variables which are in use simultaneously occupy different registers.
With interval graphs, the greedy algorithm turns out to perform well with the natural ordering of
the vertices. We sort the intervals [ai , bi ] by their starting point, so that a1 < a2 < · · · < an . Then,
we color the vertices v1 , v2 , . . . , vn in this order.
How well does this do? Here’s how well:
Theorem 4.1. If G is an interval graph, then χ(G) = ω(G) (ω(G) is the clique number of G).
4
Proof. Suppose we are coloring vertex vi during the greedy algorithm. Which vertices among
v1 , . . . , vi−1 are adjacent to this vertex: which of the intervals that come before [ai , bi ] overlap with
it?
Well, they all start before ai , so to overlap with [ai , bi ], they must end after ai . This means that
they all contain the point ai itself. But if we’re looking at a set of intervals that all contain ai , then
they form a clique, because they all overlap! So, together with vi , we are looking at ω(G) or fewer
vertices: vi has at most ω(G) − 1 neighbors that come before it.
Therefore the greedy algorithm will never use more than ω(G) colors.
(Conversely, it will have to use at least ω(G) colors, because the vertices of a clique will all need
different colors. More on this in the next lecture.)
5
5 Practice problems
1. Draw a tree that, when the vertices are unfortunately ordered, ends up being given 5 different
colors by the greedy algorithm.
(Think about how the 4-color example works; don’t try to reinvent the wheel.)
2. Here is a plane embedding of the icosahedral graph.