Sie sind auf Seite 1von 7

# Subject Computation of Chromatic Polynomials Date 4/1/05 Author(s) Gary Haggard and Thomas R.

Mathies, Bucknell University Technical Assistance Wade Hutchinson, Bucknell University Abstract An eective algorithm for computing chromatic polynomials of connected graphs is presented. The range and speed of this algorithm are substantially beyond other algorithms for this purpose. Animations No Version Maple 9 Viewed Keywords: Graph, complete graph, coloring of a graph, chromatic polynomial, spanning tree, planar graph, planar dual, edge deletion graph, edge contraction graph, computation tree, tree basis, standard basis Computing Chromatic Polynomials Using chromial Let G = (V, E ) be a graph with vertex set V and edge set E . A chromatic polynomial for G is a polynomial P (G, ) of degree |V | with the values at being the number of ways to color the graph G using colors, where = 0, 1, 2, . . .. An edge deletion graph is formed by simply removing an edge e from the graph. The edge deletion graph is denoted as G e. The edge contraction graph involves rst deleting an edge e from the graph and then identifying the ends of that edge as a single vertex. The edge contraction graph is denoted as G/e The paper  gives a very good introduction to chromatic polynomials and describes properties that can be proven by induction using the recursion of Theorem 1. Theorem 1 gives a method for recursively computing a chromatic polynomial. Theorem 1 . Let G = (V, E ) be a graph. Let e E . Then, P (G, ) = P (G e, ) P (G/e, ), where G e is the edge deletion graph and G/e is the edge contraction graph. The computation of a chromatic polynomial for any graph would seem to be fairly straightforward using Theorem 1. It has, however, only been quite recently that the hand computation of Hall, Siry, and Vanderslice  that resulted in the computation of the chromatic polynomial of the planar dual of the truncated icosahedron was carried out by computer using this software, see  and .

Representations The chromatic polynomial has several common representations. The most obvious one is to use the simple powers of : 1, , 2 , 3 , . . . as a basis for the polynomial. This basis is called the standard basis. A representation for graphs with at lest one edge that is particularly useful for implementation purposes is a representation in terms of the tree basis: ( 1), ( 1)2 , ( 1)3 , . . . . The chromatic polynomial of complete(4) can be written either as P (complete(4), ) = 4 63 + 112 6 or P (complete(4), ) = ( 1)3 3( 1)2 + 2( 1). The Maple functions that expand polynomials can easily transform a chromatic polynomial expressed in terms of the tree basis into a chromatic polynomial expressed in the standard basis. The use of the tree basis has a benet in the computation process. The termination of a branch of the computation tree can occur when a tree is detected since all trees with the same number of vertices have the same chromatic polynomial (see Theorem 5 ). The computation identies a spanning tree so that for a graph that is not a tree, there is a way to choose an edge for the deletion/contraction process that will not disconnect the graph. Dealing with connected graphs is a convenience rather than a necessity since the chromatic polynomial of a disconnected graph is the product of the chromatic polynomials of its connected components. The Algorithm The fundamental operation to carry out in computing a chromatic polynomial is choosing an edge and applying the recursion described in Theorem 1. The recursion reduces the problem to two smaller subproblems that are viewed as nodes at the next level of the computation tree. This process is repeated for each node of the computation tree until the graph occurring can actually have its chromatic polynomial computed. The chromatic polynomials computed to terminate branches of the computation tree are then used to compute the chromatic polynomial of the graphs occurring above them in the computation tree. This process continues until the original graph has its chromatic polynomial computed from the chromatic polynomials of the two graphs immediately below it in the computation tree. The general idea of the algorithm will be described and then some of the ideas used to optimize the computations will be described. Additional details about the computation can be found in  and .

chromial(graphG, polynomialP ) Determine a spanning tree in G Put G on the graph stack Call the computational procedure deleteContract Print the chromatic polynomial returned from deleteContract deleteContract(graph G, polynomial P) While the graph stack is not empty If G satises the threshold condition If a graph isomorphic to G has previously been encountered Look up the chromatic polynomial for G else Determine if it is time to compute P(G, x) or call deleteContract with this graph Get a new graph o the graph stack else Carry out delete and contract process for some edge The ordering of the input edges uses the system random number generator to permute them before the graph data structure is built by the program. This step allows dierent computation trees to be used and hence a level of correctness is implicit since the computation tree depends directly on the data structure for the graph that is determined by the order of input of the edges. The computations can be dierent because the order in which the edges are input determines how a spanning tree is constructed and the order of the edges used in the delete/contract process. The chromatic polynomial is independent of the way in which it is computed. The isomorphism test is implemented using Brendan McKays software nauty . At a number of predetermined values for the size of the vertex set of the graph, the isomorphism test is made. The occurrence of a graph in the hash table indicates that it has had its chromatic polynomial computed in some other branch of the computation tree. The isomorphic graph can then just use the result of the previous computation and not repeat the computation. The hash table is allocated dynamically by the program and increased in size as need arises. The termination conditions are twofold. If the graph is a tree, then the chromatic polynomial is just x(x 1)(n1) , where n is the number of vertices in the tree. This polynomial is the same for all trees with n vertices. The second test is whether the graph has seven or fewer vertices. In this case, a sequence of invariants are tested to identify the isomorphism class of the graph. The chromatic polynomial of each isomorphism class is included in the program. Examples The data structure that represents a graph in this algorithm requires that 2 |E | + |V | < 950 and |V | < 65. At this point the algorithm is not designed 3

for complete graphs with more than 30 vertices. The algorithm is designed only for connected graphs. Disconnected graphs cause erroneous output. For disconnected graphs the algorithm can be run for each component and then the resulting chromatic polynomials can be multiplied together using other Maple functions. The graph of the planar dual of the truncated icosahedron (T I ) had its chromatic polynomial computed in about one second in contrast to the time required for the hand calculation of . P (T I, ) = +1 ( 1)31 59 ( 1)30 +1710 ( 1)29 32450 ( 1)28 +453403 ( 1)27 4973197 ( 1)26 +44583400 ( 1)25 335797000 ( 1)24 +2167755011 ( 1)23 12175221281 ( 1)22 +60183865818 ( 1)21 264193106900 ( 1)20 +1037166520075 ( 1)19 3661052024851 ( 1)18 +11665962055746 ( 1)17 33646105485699 ( 1)16 +87942380056419 ( 1)15 208269347521537 ( 1)14 +446095183473635 ( 1)13 861047769728938 ( 1)12 +1489229660477423 ( 1)11 2289676883015802 ( 1)10 +3096554498357805 ( 1) 9 3633794047947863 ( 1) 8 +3636161286009548 ( 1) 7 3033198826142253 ( 1) 6 +2046265622980682 ( 1) 5 1069414679790850 ( 1) 4 +405031279488050 ( 1) 3 98611241495930 ( 1) 2 +11551226205884 ( 1) 1

The computation of the chromatic polynomial of the complete graph on 30 vertices carried out on a Sun Blade 200 took one and a half seconds of computation time. The result is

P (complete(30), ) = +1 ( 1)29 406 ( 1)28 +78561 ( 1)27 9642906 ( 1)26 +843041745 ( 1)25 55880640270 ( 1)24 +2918785153245 ( 1)23 123268226851770 ( 1)22 +4285624815406935 ( 1)21 124243455209483610 ( 1)20 +3031400077459516035 ( 1)19 62656135265695354110 ( 1)18 +1101911578045922391915 ( 1)17 16532187926098943672490 ( 1)16 +211821088794711294496815 ( 1)15 2316762871029690607422990 ( 1)14 +21590257290787088602515180 ( 1)13 170857232541629621904997080 ( 1)12 +1142413073615783087483702480 ( 1)11 6409259592413089839517170080 ( 1)10 +29891934088703915048808047424 ( 1) 9 114481515057741551880042390144 ( 1) 8 +354237722035840197377888292864 ( 1) 7 866422974395414742142363398144 ( 1) 6 +1625014498326371300452283596800 ( 1) 5 2236045380156380112643362816000 ( 1) 4 +2105684281550279072336117760000 ( 1) 3 1197348677077520393310044160000 ( 1) 2 +304888344611713860501504000000 ( 1) 1 Run Time Hints There are always decisions to make about the size of the data structures used in a program so that the typical example can be dealt with. The number of edges in the data structure dened allows for complete(30) to have its chromatic polynomial computed (as well as all its subgraphs). Since the computation depends on the computation tree determined for the particular computation, it is likely that computing the chromatic polynomial for the same graph several times will result in quite dierent run times. Graphs with a larger number of vertices must still satisfy the condition 2 |E | + |V | < 950. These requirements are conrmed by two assertions in the program: assert((T W O |E | + |V |) < EDGESIZE ); 5

assert(|V | < V ERT EXSIZE ); To check that the original graph is connected, the vertices are numbered during an initial depth rst search. The nal depth rst search number is compared with the number of vertices in the assertion: assert(df sN umberedV ertices == verticesInGraph); The assertion indicates the number of vertices in rst connected component of the graph. When the assertion is true, the graph is connected. The assertion assert(!loopP resent); checks to see that the original graph has no loops. If this asssertion is false, it is likely there was an error in entering the edges of the graph. The next internal check is the assertion: assert(C >= 0); that is true as long as the internal stack that manages the graphs that are not the focus of the computation, has not run out of space. It is not possible to predict what a particular computation tree will look like and so there has to be an estimate of the expected size of a large computation tree. The computation tree depends on the order of the input of the edges of the graph. Since the rst step in the program is to permute the edges of the graph being entered, one strategy when this assertion is false is to run the graph again and hope you have better luck in the choice of a computation tree. The data structure can be made to allow larger computation trees. It is suggested that you contact haggard@bucknell.edu to work out the details. One additional assertion veries that the dynamic allocation of memeroy for the hash table does not exceed its limits: assert(currentBlock < M AXB LOCKS ) The hash table has access to over 1gig of memory and seems to be large enough.i Clearly, this can be increased if needed. Runtime for graphs with large numbers of vertices can take hours. It is not dicult to enter a graph for which one run takes seconds and another run of the same graph takes hours to complete. The impact of the computation tree is very marked and not very well understood. Bibliography  Haggard, G. and T.R. Mathies, Note: The computation of chromatic polynomials, Discrete Mathematics 199 (1999) 227231.  Haggard, G. and T.R. Mathies, Using Thresholds to Compute Chromatic Polynomials, Ars Combinatoria 58 (2001) 8595.

 Hall, D.W., J.W. Siry, and B.R. Vanderslice, The Chromatic Polynomial of the Truncated Icosahedron, it Proceedings of the American Mathematical Society (1965), 620628.  McKay, B.D., nauty Users Guide (Version 1.5), Technical Report TR-CS90-02, Australian National University, Department of Computer Science, 1990.  Read, R.C., An introduction to chromatic polynomials, J. Comb. Theory B 13 (1972) 5271.