A Generalized Implicit Graph Enumeration Algorithm For Graph Coloring 1982
A Generalized Implicit Graph Enumeration Algorithm For Graph Coloring 1982
Programming
Techniques and
Data Structures
A Generalized Implicit
Ellis Horowitz
Editor
Graph Coloring
ABSTRACT: A generalized algorithm for graph coloring by simple backtracking rule. Suppose that the vertices of
implicit enumeration is formulated. A number of graph G have been ordered in some way and are rein-
backtrackingsequential methodsare discussedin terms of dexed so that vi is the ith vertex in this ordering. Then,
the generalized algorithm. Someare revealed to be partially two steps: fotward and backward, are performed alter-
correct and inexact. A few corrections to the invalid nately. The forward step colors the vertices sequen-
algorithms, which cause these algorithms to guarantee tially up to a vertex which cannot be colored because
optimal solutions, are proposed.Finally, somecomputational of a lack of colors available to it. The backward step
results and remarkson the practical relevance of improved moves sequentially back in search of the first vertex
implicit enumeration algorithms are given. which can be colored with another feasible color and
then the forward step is resumed, etc. If a new, better
1. INTRODUCTION coloring of G has been found, the algorithm attempts to
It is well known that the problem of coloring the ver- find the next one. The activity terminates when a back-
tices of a graph with a minimum number of colors so track reaches VI.
that no adjacent vertices are the same color is probably The forward step of Brown’s original algorithm can
intractable. Not only is the general problem NP-com- be improved either by using a look-ahead procedure [2]
plete, but even a drastically simplified problem of de- or by reordering yet uncolored vertices [6]. On the
termining the 6-colorability of a a-regular planar graph other hand, the backward step turns out to be much
remains NP-complete [4, i’]. Also, the problem of deter- harder to refine. Chriatofides [3] was the first to at-
mining the chromatic number of an arbitrary graph tempt to improve on the backward step. Unintention-
within a worst-case ratio of less than z has been shown ally, he obtained an algorithm which does not always
to be NP-complete [6]. That is why no polynomial time find a chromatic coloration and which, moreover, fails
algorithm for exact graph coloring is likely to exist. to terminate properly on some graphs. Brelaz [l], who
In general, there are three tree search strategies to made a few errors and also arrived at a partially correct
solve this classical combinatorial problem: maximal in- approximation algorithm, was the next to improve
dependent sets, dichotomous search, and implicit enu- Brown’s coloring algorithm. A simple counterexample
meration. The most flexible and space efficient of these to both algorithms is shown in Figure 1. Brelaz’s modi-
is the implicit enumeration (backtracking)approach. The fication was corrected independently by Kubale and
first coloring algorithm of this type is due to Brown [Z]. Kusz [lo] and Peemoller [ll]. (Peemoller’s correction
The main idea of his method is based on the following seems to be closer to Brilaz’s intention.)
This article is motivated by the above-mentioned er-
0 1985 ACM oool-0782/85/0400-0412 750 rors. We begin by presenting, in the next section, a
The correctness of the genleral algorithm cannot be To estimate the complexity of FORWARDS notice that
proved until the semantics of the statements initialize, determining of FC(i) requires deg(vi) operations. There-
deteimine, and update is gefined. This is a crucial point fore, one pass of FORWARDS takes at most O(m) time
of the algorithm, because by defining feasible colors, plus, eventually, O(n) time to store coloration C’ and
current predecessors, an d a mode of initialization one actualize variables ub and r when a better solution has
can obtain a wide range df coloring algorithms, both been found. Thus a total of O(m + n) time must be used.
exact and approximate. Hence, the general implicit al- (iv) The definition of CP is trivial, namely
gorithm should be regarded as a frame al orithm, any
instance of which requires a separate anap1ysis. Also, the CP = (1, 2, . , r - 11,
time complexity of the algorithm depends on a particu-
lar definition of the above-niisntioned notions. How- where r is a value of parameter carried in to the BACK-
ever, taking into account only explicit constraints on a WARDS procedure. Since no updating is necessary,
solution space, we see that the number of backtracks BACKWARDS requires constant effort for each i and
never exceeds n! regardless of the particular definitions O(n) time in all.
of the FC and CP sets. Thus the worst-case time for an
implicit enumeration algorithm $11 generally be Remarks. Brown’s ordinary algorithm finds the lexico-
O((f(n) + b(n))n!) where f(n) and b(n) are polynomials graphically first exact coloration with respect to the
determining the complexity of FORWARDS and BACK- GLF ordering of vertices in the following sense: Out of
WARDS, respectively.
two different complete solutions C = C(l), . . . , C(n) and
C’ = C’(l), . . . , C’(n), the coloring C is said to be prior to
3. A SURVEY OF CONCREITE REALIZATIONS
C’ under a given vertex order if either C(1) < C’(1) or
There are four basic algoiithms in the family of implicit
C(1) = C’(l), . . . , C(i - 1) = C’(i - 1) and C(i) < C’(i) for
enumeration methdds.
some i = 2, . . . , n.
1. Brown’s algorithm
2. Christofides’ algorithm 3.1.2 Brown’s Algorithm with Look-Ahead
3. Br6laz’s algorithm (i) Same as in Section 3.1.1.
4. Korman’s algorithm (ii) Same as in Section 3.1.1.
In this section we outline the main features of the (iii) Brown reduced the number of backtracks by in-
algorithms in their corrected form with a special refer- troducing the so-called look-ahead (LA) procedure to the
ence to the following: forward step. LA makes it possible to diminish the FC
(il initialization,- that is, stating bounds on the sets by enlarging the PC sets. The new definition of
chromatic number, initial ordering of vertices, prohibited colors is PC(i) = {c < ub: there is an adjacent
etc., predecessor of Vi colored with c or any of the adjacent
(ii) rearrangement of yet nncolored vertices, successors of vi can be colored only with c]. The im-
(iii) computation of the sets of feasible colors FC(i), proved FORWARDS procedure can still run in linear
(iv) computation of the set of current predecessors time O(m + n), but within a greater constant of propor-
CP. tionality.
(iv) Same as in Section 3.1.1.
3.1 Brown’s Two Algorithms [2]
Remarks. The concept of looking ahead can be refined
3.1.1 Brown’s Ordinary Algolrithm further by ordering feasible colors by the number of
(i) The vertices are preordered in a greedy largest preventions, that is, the number of adjacent successors
first (GLF) manner. Namely, vl is a maximum degree of Vi which could possibly be assigned color c unless c is
assigned to ZJ;.However, such a complex LA increases The SLF with interchange algorithm takes O(mn) time
the complexity of FORWARDS to the order of O(mn). and the Matula-Dsatur algorithm needs O(min(n2, m log
The backtracking algorithm with simple LA finds the n)) time. Each of the preconditioning algorithms ar-
first chromatic coloring [5] whereas the solution pro- ranges the vertex set so that initial vertices constitute
duced by the complex LA algorithm need not be the an initial clique (IC) of size at least 2 and the number of
lexicographically first one. colors used is usually close to minimum.
(ii) Same as in Section 3.1.
3.2 Corrected Christofides Algorithm [3] (iii) Same as in Section 3.1.
(i) No particular ordering is assumed; lower bound (iv) Br6laz also tried to reduce the CP set but he
and upper bound are determined as in Section 3.1. made two errors. Herein we give Peemoller’s correction
(ii) Same as in Section 3.1. to Brelaz’s dynamic updating of current predecessors.
(iii) Same as in Section 3.1. The set of adjacent predecessors of Vi, AP(i), is partitioned
(iv) In an effort to decrease the number of back- into nonempty sets AP,(I’), . . . , APb(i) such that AP,(I’) =
tracks, Christofides reduced the CP set too drastically (j < i: Vj is colored with cl, c < ub. Let r, = min AP,(i).
and obtained a partially correct approximation algo- Then the set of representatives for AP(i) is defined as
rithm. To correct his definition of CP we need a notion
of path passing throughout increasingly indexed ver- if AP(I’) = 0,
tices. Such a path is said to be monotonic. By the prede- R(i) = 1 {ra, . . . , rb) - IC otherwise.
cessor set of ui we mean P(i) = lj < i: there is a mono-
tonic path from Vj to vi in G). Now, the initial CP set is Now the initial set of current predecessors is
simply defined as
CP = CP U R(r).
CP = CP U P(r).
Updating of the set is accomplished in BACKWARDS as
No updating of the set is performed. follows:
The P(i) sets can be precomputed just after the initial
vertex order is stated. For this purpose one can use any CP = CP U R(i).
efficient method for finding the transitive closure of a
directed graph, for example, [12]. Hence BACKWARDS BACKWARDS can be implemented to run in O(m + n)
can be efficiently implemented in O(n) time. time.
Remarks. It is possible to incorporate looking ahead Remarks. As previously, the LA procedure can be in-
into the Christofides algorithm. This can be done by corporated into the algorithm. In this case additional
restricting FC (as in Section 3.1.2) and updating CP ac- updating takes the form
cording to the formula
CP = CP U jEyil R(j).
CP = CP U jEyilP(j) - ii, . . . , 4,
(In constructing (R(j) uncolored vertices are disre-
where B(i) is the set of all uncolored neighbors of zl; garded.) The Brelaz algorithm also finds the first exact
which could be assigned the only color c unless c is coloring in the lexicographic order sense.
assigned to Vi, It is convenient to construct the set B(i)
while searching for prohibited colors in FORWARDS. 3.4 Korman’s Dynamic Reordering Algorithm [9]
Since the partial solutions of level i are lexicographi- (i) Same as in Section 3.1.
tally ordered, the method finds the first exact coloring (ii) Korman noticed that during the forward step
(unless a refined version of LA is used). some vertices appear to have fewer feasible colors than
others and such vertices should be colored first. His
3.3 Corrected Brilaz Algorithm [l, 111 dynamic rearrangement (DR) rule states simply: From the
(i) The vertices are colored sequentially to obtain a set (Vi, . . , v,) of uncolored vertices choose a vertex
suitable ordering of the vertex set and both bounds on which can be colored with the smallest number of fea-
the chromatic number of G. Brblaz suggests preordering sible colors and replace it with Vi. The complexity of
the vertices by means of a sequential with interchange FORWARDS with dynamic rearrangement is dominated
algorithm applied to a saturation largest first (SLF) order- by the DR procedure which can run in time O(m + n),
ing or the Mutula-Dsatur algorithm (a combination of but at a cost of some increase of the complexity of
SLF and SL) as he calls it. The SLF algorithm, which is BACKWARDS.
a basis for both heuristics, repeatedly colors an unco- (iii) Same as in Section 3.1.
lored vertex of the largest saturation degree with the (iv) Same as in Section 3.1.
smallest possible color, where the saturation degree is
the number of adjacent distinctly colored vertices. Ties Remarks. The DR procedure plays a role similar to that
are broken by choosing the vertex of greater degree. of LA. However, empirical investigations show that, in
spite of the same complexity, the DR rule is much more 4. COMPUTATIONAL RESULTS
powerful than the simple LA. In order to compare a relative speed-up of various im-
Korman’s DR algorithms produces a chromatic colora- provements of Brown’s coloring algorithm on empirical
tion which is lexicographically first with respect to the grounds, the implicit algorithms were coded in Pascal
final vertex order, that is, the vertex order just after the and run on an R-32 computer (equivalent to an IBM
chromatic coloring had been found. 360/65). All the algorithms were programmed in the
A modification to the DR rule is also possible. For versions of the previous section except the corrected
instance, at restart after BACKWARDS coloring may be Brelaz algorithm which was implemented in the form
done according to the latest arrangement of vertices of [lo]. Since the efficiency of vertex sequential algo-
already colored or starting with the latest resumption rithms is highly dependent on the way the vertices are
point. In any case a particular definition of dynamic ordered, the following preparatory procedures arrang-
rearrangement affects only the efficiency of enumera- ing the vertices by their degree were implemented:
tion since any algorithm with a DR-like procedure largest first (LF), smallest last (SL), saturation LF (SLF),
leads to an exhaustive search regardless of the way and saturation SL (SSL). The saturation procedures tend
uncolored vertices are ordered. to use the largest unavoidable color as soon as possible.
It is also possible to incorporate Peemoller’s dynamic The LF ordering procedure ran in linear time while the
updating of the CP set into the! algorithm. others required at most O(n’) additional time. All pro-
grams were executed on identical samples of pseudo- For more details on the extensive experimentally ob-
random graphs generated according to the constant served computing times comparing various backtrack-
density model with vertex number n = 10(10)80 and ing algorithms, see [lo].
graph density d = .1(.2).9. For each n and d three graphs
were generated. Each was colored by each program 5. CONCLUDING REMARKS
within a five minute limit of CPU time. Table I contains Results of the empirical investigations allow us to draw
the best computational results of the four orderings ob- the following conclusions.
tained for each program in question. Aside from aver- 1. Small graphs with II 4 30 can be colored effi-
age timing we give the average number of backtracks ciently by any backtracking algorithm preceded by any
required to color a graph since this parameter seems to vertex ordering procedure. Nevertheless, simple meth-
be a more objective measure of algorithmic complexity, ods, such as Brown’s with LF, are preferable.
especially if a program terminates before the deadline. 2. The effectiveness of this family of coloring algo-
In practice, graphs to be colored are usually sparse in rithms decreases as the density of the graphs increases,
the sense that the number of edges m is much less than except for very dense graphs.
n2/2. For this reason Figure 2 shows timing profiles of 3. The efficiency of implicit enumeration algorithms
the best and worst variants of the analyzed algorithms without dynamic reordering is highly dependent on the
plotted for graphs G with d = .l. initial arrangement of vertices. In this case the SSL
/ - BROWN REFERENCES
2 - --- CHRISTOFIDES 1. Br&z, D. New methods to color the vertices of a graph. Commun.
- BRELAZ ACM 22,4 (Apr. 1979). 251-256.
1.w.........- KORMAN 2. Brown, R.J. Chromatic scheduling and the chromatic number prob-
lem. Manage. Sri. 19,4 (Dec. 1972). 451-463.
3. Christofides, N. Graph Theory. An Algorithmic Approach. Academic
10 io 30 40 5b 60 6 Press, London, 1975, pp. 70-71.
4. Dailey, D.P. Uniqueness of colorability and colorability of planar
l lime in CPU-milliseconds 4-regular graphs are NP-complete. Discrete Math. 30, (1980), 269-293.
5. Diirre, K. An algorithm for coloring the vertices of an arbitrary
FIGURE2. Timing Profiles from the Application of Backtracking graph. In Lecture Notes in Economicsand Mathematical Sysfems.Vol.
78. P. Deussen Ed., Springer-Verlag, Berlin, 1973, pp. 82-89.
Algorithms to Color Random Sparse Graphs 6. Garey, M.R.. and Johnson, D.S. The complexity of near-optimal
graph coloring. I. ACM 23, 1 (Jan. 1976), 43-49.
7. Garey. M.R.. Johnson, D.S.. and Stockmeyer, L. Some simplified NP-
complete graph problems. Theor. Comput. Sci. I, (1976). 237-267.
II. Horowitz. E.. and Sahni. S. Fundamentalsofcomputer Algorithms.
ordering performs best overall and saves more back- Computer Science, Potomac. Md.. 1978, pp. 614-621.
tracking than any improvement of the forward or back- 9. Korman, SM. The graph-colouring problem. In Combinatorial Opti-
mization. N. Christofides. A. Mingozzi, P. Toth, and C. Sandi. Eds.,
ward step. Wiley, New York, 1979. pp. 211-235.
4. Regarding the expectation of the time complexity, 10. Kubale. M.. and Kusz. E. Computational experience with implicit
the dynamic reordering of yet uncolored vertices estab- enumeration algorithms for graph coloring. In Proceedingsof the
WG’83 International Workshopon Graphtheoretic Conceptsin Computer
lishes a great improvement even if compared to the Science.M. Nag1 and J. Perl, Eds., Trauner Verlag. Linz, 1983, pp.
methods with LA. 167-176.
11. PeemGller, J. A correction to BrBlaz’s modification of Brown’s color-
5. If graphs to be colored (aresparse, then both the ing algorithm. Commun. ACM 26,8 (Aug. 1983), 595-597.
Christofides algorithm, applied to the vertices presorted 12. Schmitz, L. An improved transitive closure algorithm. Computing 30.
by SL, and Korman’s dynamic reordering, preceded by 4 (1983). 359-371.