The Poor Cartographer-Graph: Coloring
The Poor Cartographer-Graph: Coloring
Focus
Problem solving.
Logical reasoning.
Algorithmic procedures and complexity.
Communication of insights.
Summary
Many optimization problems involve situations where certain events cannot occur at the
same time, or where certain members of a set of objects cannot be adjacent. For example,
anyone who has tried to time-table classes or meetings will have encountered the problem
of satisfying the constraints on all the people involved. Many of these difficulties are
crystallized in the map coloring problem, in which colors must be chosen for countries on
a map in a way that makes bordering countries different colors. This activity is about that
problem.
Technical terms
Graph coloring; exponential time algorithms; heuristics.
Materials
For each child you will need:
What to do
This activity revolves around a story in which the children have been asked to help out a car-
tographer, or map-maker, who is coloring in the countries on a map. It doesn’t matter which
color a country is, so long as it’s different to all bordering countries. For example, Figure 13.1
shows four countries. If we color Northland red, then Westland and Eastland cannot be red,
since their border with Northland would be hard to see. We could color Westland green, and it
is also acceptable to color Eastland green because it does not share a border with Westland. (If
two countries meet only at a single point, they do not count as sharing a border and hence can
be made the same color.) Southland can be colored red, and we end up needing only two colors
for the map.
In our story, the cartographer is poor and can’t afford many crayons, so the idea is to use as
few colors as possible.
Page 130
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
Figure 13.2: Solution for coloring the map on page 138 using just two colors.
1. Describe the problem that the children will be working on, demonstrating the coloring
process on a blackboard.
2. Give out the blackline master on page 138. This map can be colored correctly using only
two colors. Although restricting the number of colors to just two might sound particularly
challenging, the task is quite simple compared with maps that require more colors because
there is very little choice about what color each country can be.
Have the children try to color the map in with only two colors. In the process they may
discover the “has-to-be” rule: once one country is colored in, any bordering country has
to be the opposite color. This rule is applied repeatedly until all countries are colored in.
It is best if the children can discover this rule for themselves, rather than being told it, as
it will give them a better insight into the process. Figure 13.2 shows the only possible
solution for the map on page 138 (of course, the choice of colors is up to the child, but
only two different ones are required).
The children may also discover that it is better to use place-holders, such as colored
counters, instead of coloring the countries straight away, since this makes it easier for
Page 131
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
Figure 13.3: Solutions for coloring the maps on page 139 using just three and four colors re-
spectively.
3. As children complete each exercise they can be given the next sheet to try. The map at the
top of page 139 can be colored correctly using three colors, while the one at the bottom
requires four. Possible solutions are shown in Figure 13.3. The map on page 140 is a
simpler three-color map, with a possible solution shown in Figure 13.4.
For older children, ask them to explain how they know that they have found the minimum
number of colors. For example, at least three colors are required for the map in Figure 13.4
because the map includes a group of three countries (the largest three), each of which has
borders with the other two.
4. If a child finishes all the sheets early, ask them to try to devise a map that requires five
different colors. It has been proved that any map can be colored with only four colors, so
this task will keep them occupied for some time! In our experience children will quickly
find maps that they believe require five colors, but of course it is always possible to find a
Page 132
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
Figure 13.4: Solution for coloring the map on page 140 using just three colors.
Page 133
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
Figure 13.5: Solution for coloring the map on page 141 using just two colors. The colors are
shown in this figure as shaded and white.
Page 134
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
many is ever actually required. (Experts conjecture that fewer than 10 colors are sufficient.)
Children might enjoy acting out this situation, which is rather like a two-person game.
In a variation know as empire coloring, we start with two different maps on two sheets of
paper having the same number of countries. Each country on one of the maps (say, the Earth)
is paired with exactly one country on the other map (which might be colonies on the Moon). In
addition to the usual coloring requirement of different colors for countries that share a border
(for both maps) we add the requirement that each Earth country must be colored the same as its
colony on the Moon. How many colors do we need for this problem? The answer is currently
unknown.
Page 135
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
Map coloring belongs to a general class of problems known as “graph coloring.” In com-
puter science, a graph is an abstract representation of relationships. An example is shown in
Figure 13.6.
As mentioned in Activity 9 on the Muddy City, the term graph is used in a different sense in
mathematics to mean a chart displaying numerical data, such as a bar graph, but the graphs that
computer scientists use are not related to these. In computer science, graphs are drawn using
circles or large dots, technically called “nodes,” to denote objects, with lines between them to
indicate some sort of relationship between the objects. The graph in Figure 13.6 happens to
represent the map of Figure 13.1. The nodes represent the countries, and a line between two
nodes indicates that those two countries share a common border. On the graph, the coloring rule
is that no connected nodes should be allocated the same color. Unlike a map, there is no limit
to the number of colors that a general graph may require, because many different constraints
may be drawn in as connecting lines, whereas the two-dimensional nature of maps restricts the
possible arrangements. The “graph coloring problem” is to find the minimum number of colors
that are needed for a particular graph.
Figure 13.7 shows another graph. Here the nodes correspond to subjects in a school. A
line between two subjects indicates that at least one student is taking both subjects, and so
they should not be timetabled for the same period. Using this representation, the problem of
finding a workable timetable using the minimum number of periods is equivalent to the coloring
problem, where the different colors correspond to different periods. Graph coloring algorithms
are of great interest in computer science, and are used for many real-world problems, although
they are probably never used to color in maps!—our poor cartographer is just a fiction.
There are literally thousands of other problems based on graphs. Some are described else-
where in this book, such as the minimal spanning tree of Activity 9 and the dominating sets of
Activity 14. Graphs are a very general way of representing data and can be used to represent all
sorts of situations, such as routes available for travel between cities, connections between atoms
in a molecule, paths that messages can take through a computer network, connections between
components on a printed circuit board, and relationships between the tasks required to carry out
a large project. For this reason, problems involving graph representations have long fascinated
computer scientists.
Many of these problems are very difficult—not difficult conceptually, but difficult because
they take a long time to solve. For example, to determine the most efficient solution for a graph
coloring problem of moderate size—such as finding the best way to timetable a school with
thirty teachers and 800 students—would take years, even centuries, for a computer using the
best known algorithm. The problem would be irrelevant by the time the solution was found—
and that’s assuming the computer doesn’t break down or wear out before it finishes! Such
problems are only solved in practice because we are content to work with sub-optimal, but still
very good, solutions. If we were to insist on being able to guarantee that the solution found was
the very best one, the problem would be completely intractable.
The amount of computer time needed to solve coloring problems increases exponentially
with the size of the graph. Consider the map coloring problem. It can be solved by trying
out all possible ways to color the map. We know that at most four colors are required, so we
need to evaluate every combination of assigning the four colors to the countries. If there are
n countries, there are 4n combinations. This number grows very rapidly: every country that is
Page 136
ACTIVITY 13. THE POOR CARTOGRAPHER—GRAPH COLORING
added multiplies the number of combinations by four, and hence quadruples the solution time.
Even if a computer were invented that could solve the problem for, say, fifty countries in just
one hour, adding one more country would require four hours, and we would only need to add ten
more countries to make the computer take over a year to find the solution. This kind of problem
won’t go away just because we keep inventing faster and faster computers!
Graph coloring is a good example of a problem whose solution time grows exponentially.
For very simple instances of the problem, such as the small maps used in this activity, it is quite
easy to find the optimal solution, but as soon as the number of countries increases beyond about
ten, the problem becomes very difficult to do by hand, and with a hundred or more countries,
even a computer would take many years to try out all the possible ways of coloring the map in
order to choose the optimal one.
Many real-life problems are like this, but must be solved anyway. Applied computer sci-
entists use methods that give good, but not perfect, answers. These heuristic techniques are
often very close to optimal, very fast to compute, and give answers that are close enough for
all practical purposes. Schools can tolerate using one more classroom than would be needed if
the timetable were perfect, and perhaps the poor cartographer could afford an extra color even
though it is not strictly necessary.
No-one has proved that there isn’t an efficient way to solve this sort of problem on con-
ventional computers, but neither has anyone proved that there is, and computer scientists are
sceptical that an efficient method will ever be found. We will learn more about this kind of
problem in the next two activities.
Further reading
Harel discusses the four-color theorem, including its history, in Algorithmics. More aspects of
the map-coloring problem are discussed in This is MEGA-Mathematics! by Casey and Fellows.
More information about graph coloring can be found in Beineke and Wilson’s book Selected
Topics in Graph Theory, and Garey and Johnson’s book Computers and Intractability.
Page 137
Instructions: Color in the countries on this map with as few colors as
possible, but make sure that no two bordering countries are the same
color.