An improved Algorithm for the Chromatic Polynomial ...

10 downloads 6128 Views 192KB Size Report
procedure Whitney2( H, n, e, sign) begin if H≠Tn, ie. (n - 1) > e then begin [| We use 1.2 |]. Find a and b adjacent points, such that deleting the line {a,b} does not.
An improved Algorithm for the Chromatic Polynomial Ramón M. Figueroa-Centeno Universidad Metropolitana Dpto. de Matemáticas Apto. 76819. Caracas. Venezuela.

Reinaldo E. Giudici Universidad Simón Bolívar Dpto. de Matemáticas Puras y Aplicadas Apt. 89000. Caracas. Venezuela.

SUMMARY Computing the chromatic polynomial of a graph is a NP-Complete problem. The algorithms based on Whitney's Identity found in literature are improved by detecting hanged cycles and applying heuristic techniques. 1. INTRODUCTION The graphs considered in this paper are always finite, undirected, simple and without loops. The terminology and other terms not defined here are found in the texts [2, 9]. A coloring of a graph is an assignment of one specified set {1, 2, 3, ... l} of colors to each point of the graph so that no two adjacent points have the same color. It is a well known fact that the number of different colorings of a graph G in which at most l colors are used is a polynomial in l, called the chromatic polynomial of G, it will be denoted by P(G, l). The following three well known Lemmas give the chromatic polynomial for the Null, Complete and Tree graphs, which are the most used bases for writing the chromatic polynomial, [1,2,8]. Lemma 1.1 P(Nn, l) = ln , where Nn is the null graph of order n. Lemma 1.2 P(Kn, l) = (l)n , where Kn is the complete graph of order n, and (l)i ≡l(l 1)(l - 2)...(l - i + 1), is the falling factorial of i. Lemma 1.3 P(Tn, l) = l (l - 1) n , where Tn is any tree of order n. Following the procedure developed by Hassler Whitney [10], we define the identification of points as the process of contracting two points, a and b, belonging to a graph G, in to one, ie. by replacing a and b, by a new point, such that it is joined to any point which was previously joined to a or b. Theorem 1.1 (Whitney's identity) [10] Let G' and G'' be the graphs obtained by joining and identifying, two non-adjacent points a and b of a graph G, respectively. Then P(G,l) = P(G',l) + P(G'',l).

(1.1)

Solving (1.1) for P(G',l), one obtains the next version of Theorem 1.1. Corollary 1.1 Let G' and G'' be the graphs obtained by separating and identifying, two adjacent points a and b of a graph G, respectively. Then P(G,l) = P(G',l) - P(G'',l).

(1.2)

Theorem 1.2 [Karp, 3] Computing the chromatic polynomial of a graph, is NP-Hard. Furthermore it is NP-Complete. Theorem 1.3 [Zykov, 11] The chromatic polynomial of a graph is the product of the chromatic polynomials of its connected components. Since polynomial multiplication is a polynomially bounded problem, and computing the chromatic polynomial, of a graph G, an NP-Hard problem, it is then convenient to calculate the chromatic polynomial of each connected component of G and then multiply them together to obtain P(G, l). Therefore, we will consider only connected graphs.

Definition 1.1 A set S of polynomials is said to span the set of chromatic polynomials C, if any chromatic polynomial can be obtained as a linear combination of the elements of S. A set S that spans C, and whose members are linearly independent is said to be a basis for C. Lemmas 1.1-1.3 conduct to three frequently used bases: (i) The null graph basis: {1, l, l2 , ..., ln , ...}. (ii) The complete graph basis: {1, (l)1 , (l)2 , ..., (l)n , ...}. (iii) The tree basis: {1, l(l - 1), l (l - 1)2 , ..., l (l - 1) n , ...}. Conversions between these three bases can be obtained using the linear transformations described by Loerinc [5] and Margaglio [6]. Definition 1.2 A tail of length d, attached to a graph G is a tree of with d lines that has only one point in common with graph G. Definition 1.3 A hanged cycle , n > 0, with k tails is a Cn with k tails, where m is the sum of the lengths of the k tails. Therefore, a hanged cycle C=, has equal number of points and lines, if n≥3. Some particular cases, are the n-cycle itself Cn=, Tm+1= and Tm=. Figure 1.1 Theorem 1.4 Let G be a connected graph with p points and q lines. G is a hanged cycle if p=q. Conversely if G=, with n≥3, then p=q. Proof If G=, with n ≥ 3, it is direct consequence of the Def.1.3. Conversely, if p=q, let T be a spanning tree of the connected graph G which has (p-1) lines, then the edge that is not in T must form a unique fundamental cycle, since for any tree the number of lines q' is less than the number of points p', actually q'=p'-1. Theorem 1.5 P(, l) = P(, l) with k1, k2≥0. Proof Since and have a the same number of points and only one n-cycle, it sufficient to apply Cor. 1.1, deleting a line belonging the cycle Cn, to obtain a tree Tm+n and a (i = 1, 2) as is indicated in Fig. 1.2.

FIGURE 1.2. Therefore, P(,l) = P(Tm+n,l) - P(,l) (i=1, 2) By using induction on n one obtains n

P(, l) =

∑ i=2

(-1)n-i P(Ti+m,l) (i = 1, 2)

(1.3)

2. COMPUTING THE CHROMATIC POLYNOMIAL In this section the authors improve the known algorithms for calculating the chromatic polynomial, using Theo.1.4.-1.5., and two heuristic arguments. The notation used for the algorithms is similar to the one found in [9]. There are three well known ways of calculating the chromatic polynomial of a graph with a computer. All of then are based in Whitney's identity (Theo. 1.1 ). The methods are stated recursively by the authors as follows. The first one uses Theo. 1.1 Algorithm 2.1: [Loerinc, 5] Input: An undirected graph G. Output: A vector containing the coefficients of P(G, l) in the factorial basis. Let G=(V, E), p ¨|V|, q ¨|E|. Let K be a p-dimensional vector. K¨0. Whitney1(G, p, q). Output(K1, K2, ...,Kp). procedure Whitney1(H, n, e) begin if H≠Kn, ie. e e then begin [| We use 1.2 |] Find a and b adjacent points, such that deleting the line {a,b} does not disconnect H - {a, b}. [| The most convenient way is to choose {a, b} as a back edge obtained by generating a DFS-tree of H, this allows us to eliminate at least a cycle without disconnecting H. |] Delete line {a, b} in H. Whitney2( H, n, e-1, sign). e¨ e-|Adj(a) ´ Adj(b) |. [| where Adj(v) is the adjacency set of v ŒV |] Identify a and b in H. Whitney2( H, n-1, e, -sign).

end else Tn ¨Tn+sign. end. For a graph G with p points and q lines, O(p+q) is the time spent in each step of the recursion [9] and 2r the maximum size of the binary search tree, with r=q-p+1 the number of edges of G not in any of its spanning trees, hence this is an O((p+q)⋅2r) algorithm. The third algorithm was proposed in [5] as an hybrid of the preceding ones, estimating that it requires less than 40% as much computation as them. Let kp = (p(p-1))/2, the number of lines of a complete graph with p points, we say that a graph G with p points and q lines is sparse if »kp/2˘ >q, otherwise it is a dense graph, [5]. Algorithm 2.3 [Loerinc, 5] Input: An undirected connected graph G. Output: A vector containing the coefficients of P(G, l) in the factorial or tree basis. if G is dense then compute P(G, l) using Algorithm 2.1. else if G is sparse then compute P(G, l) using Algorithm 2.2. To improve Algorithm. 2.3., it suffices to improve Algorithm.2.1 or Algorithm.2.2. The authors found that each tree encountered in the recursion of Algorithm 2.2., can be preceded by a hanged cycle. This is due to the fact that the algorithm deletes lines (by identification or deletion itself), of the graphs in the binary search tree until there are only trees, if in the previous step to finding a tree (e=n, at the entry point) then the graph there must be a hanged cycle by Theo.1.4. Figure 1.2 The chromatic polynomial of a hanged cycle is known by Theo.1.5. so we can prune the search tree. However, we must be careful because cases in which a tree is not preceded by a hanged cycle# can be found, see Fig.2.1. By using DFS search of a hanged cycle C=, n and m can be calculated, being this possible because C contains only one back edge. To estimate how detecting a hanged cycle C= improves Algorithm 2.2., we can see that by Theo.1.5. this algorithm will encounter (n-1) trees after C. If now we take these trees as the leaves and C as the root of a binary tree T, then by Knuth [4], T will have (n-3) internal points. Thus, not stoping in the recursion at the moment that C is detected will imply 2(n-2) more steps . Furthermore, two heuristic considerations improve Algorithm.2.3. The first one is, it is relatively common to find complete graphs in the search tree of Algorithm.2.2., therefore it is convenient to prune this tree when such graphs arise. A much rarer occurrence is to find a tree when applying Algorithm.2.1., nevertheless such a case should be considered. The second one concerns the identification process, in Algorithm.2.2. It would be desirable to delete as many lines as possible by applying this operation. We achieve this as follows, let {a,b} be a line in the set of back edges BE of a graph G, we wish to identify points a and b, so let Adj(a) and Adj(b) be their respective adjacency sets. It is easy to see that if we chose {a,b} such that |Adj(a)´Adj(b)|≥|Adj(x)´Adj(y)|, for all {x,y}ŒBE, then the identification will delete the maximum number of lines. Likewise, in Algorithm.2.1. it would be desirable to delete the less number lines as possible, following the reasoning above we chose points a, b in G such that |Adj(a)´Adj(b)| is minimum. All the considerations above yield the following algorithm. Algorithm 2.4. Input: An undirected connected graph G. Output: A vector containing the coefficients of P(G, l) in the complete basis. Let G = (V, E), p ¨|V|, q ¨|E|.

Let T, K, W be a p-dimensional vectors. T ¨0, K ¨0. if G is dense then Whitney1( G, p, q) else if G is sparse then Whitney2( G, p, q, 1). [| The function TreeToComplete changes the coefficients in the tree basis to the complete basis |] W¨TreeToComplete(T). K¨K+W. Output( K1, K2, ...,Kp). procedure Whitney1( H, n, e) begin if H ≠ Kn, ie. e < (n(n-1)/2 ) then begin [| We use 1.1 |] Find a and b non-adyacent points of H, such that |Adj(a)´Adj(b)| is minimum over V. [| where Adj(v) is the adjacency set of v ŒV |] Add line {a, b} to H. Whitney1( H, n, e + 1). e ¨e-|Adj(a)´Adj(b) |. Identify a and b in H. if H = Tn, ie. (n-1) = e then Tn ¨Tn+1 else Whitney1( H, n-1, e). end else Kn ¨Kn+1. end. procedure Whitney2( H, n, e, sign) begin if H=Tn, ie. (n-1)=e then Tn ¨Tn+sign else if H=, ie. e=n then begin compute r and m of the hanged cycle H, using DFS search. [| We use 1.3 to calculate P(H, l) |] s ¨sign. for i ¨ r+m downto m+2 do begin Ti ¨ Ti+s. s¨ -s. end. end else begin [| We use 1.2 |] Find {a, b}ŒBE of a DFS tree of H, such that |Adj(a)´Adj(b)| is maximum over BE. Delete line {a, b} in H. Whitney2( H, n, e - 1, sign). e¨e-|Adj(a)´Adj(b) |. Identify a and b in H. if H=Kn, ie. e = (n(n-1)/2 ) then Kn¨Kn-sign else Whitney2( H, n-1, e, -sign). end end. Algorithm.2.4. behaves in the worst case as Algorithm.2.3.

By counting the number of leaves L(G), we can calculate how many graphs N(G) were generated, in the search tree of each algorithm with input a graph G. By Knuth [4] N(G) = 2(L(G) - 1). As an example we use the Heawood graph (Fig.2.4.) as G. The results are in Table.2.1. The number of leaves L(G) in Algorithms 2.1.-2.2. are the sums in absolute value of the coefficients of P(G, l) in the factorial and tree basis respectively [5]. Figure 2.4. Algorithm 2.1. 2.2. 2.3. 2.2.1. 2.2.2. 2.4.

L(G) 9206037 16161 16161 5421 5397 4857

N(G) 18412072 32320 32320 10840 10792 9712

TABLE 2.1. In the above table the Algorithms.2.2.1.-2.2.2. represent the Algorithm.2.2. with hanged cycle detection and Algorithm 2.2. with hanged cycle, tree and complete graph detection, respectively. From Table.2.1. we can appreciate an improvement of 30.05%, of Algorithm.2.4. over Algorithm.2.3. for the Heawood graph. The two major bottlenecks found by the authors while implementing the algorithms are the following. (i) A copy of a graph (the one that is in the current recursion step) must pass to the next step of the recursion. Therefore, the representation of graphs must be as small as possible, and easy to manipulate. We have used an adjacency matrix of the graph represented as a 32 x 32 bit array, and logical and, or, not, and shifts, to implement the operations of adding, deleting and identifying points. The speed lost with this representation in some parts of the algorithms, such as the DFS traversal of a graph G with p points and q lines, becomes an O(p2 ) algorithm, instead of a O(p+q) one, however this lost is compensated by the representation's other virtues. (ii) The identification of points must be implemented as carefully as possible, being a relatively complicated operation. Finally, in the process of studying the possible ways of calculating the chromatic polynomial of a graph a graphic program Whitney was developed that allowed us to study, by actually seeing the binary search tree, while it is being created and analyzing all the graphs involved in the Whitney's process. In this program one can see the most relevant properties of the graphs under observation, so that the user may choose the points to be joined (or disconnected), and identified, and all the graphs located in the leaves of the tree may be stored or printed. A graphic graph editor, Graph Edit was also created and some of the figures shown in this paper were made with it. All algorithms were implemented using Turbo Pascal, on a Apple Macintosh computer. On a Mac II with 4Mb of RAM memory, it takes roughly 19 seconds to compute the

chromatic polynomial of the Heawood graph. Using the notation given in [1], the coefficients obtained are the following. N: 16161 76685 171318 242494 245133 188020 112927 53816 20321 5985 1330 210 21 1 T: 0 317 1339 2662 3418 3243 2431 1492 764 330 120 36 8 1 F: 0 1 350 29610 452655 1919869 3153245 2426748 976192 217812 27545 1939 70 1

ACKNOLEDGEMENT The authors gratefully wish to thank Professor Claudio Margaglio for providing the highly efficient code used, for the chromatic polynomial basis transformations. BIBLIOGRAPHY [1] Giudici, R.E. and Vinke, R.M., A Table of Chromatic Polynomials, J. of Comb. Infor. and Syst Sc., 5 (1980) 323-350. [2] Harary, F., Graph Theory (Addison-Wesley, Reading, MA, 1969). [3] Karp, R.M., Reductibility among combinatorial problems, in Complexity of Computer Computations, Miller, R.E. and Thatcher, J.M., eds. (Plenum Press, 1972) 85-104. [4] Knuth, D.E. The Art of Computer Programming: Fundamental Algorithms, Volume 1, (Second Edition, Addison-Wesley, 1973). [5] Loerinc, B.M., Computing chromatic polynomials for special families of graphs, Courant Computer Science Report No. 19 (Courant Inst. of Math. Sciences, Computer Science Dept., New York Univ. February 1980) [6] Margaglio, C., Un Programa para el Cambio de Base de Polinomios Cromáticos, Reporte No. 89-04 Dpto. de Matemáticas Puras y Aplicadas Universidad Simón Bolívar (1989). [7] Nijenhuis, A. and Wilf, H.S., Combinatorial Algorithms for Computers and Calculators, (Second Edition, Academic Press, 1978). [8] Read, R.C., An introduction to chromatic polynomials, J. Combin. Theory, 4 (1962) 52-71. [9] Reingold, E.M., Nievergelt, J. and Deo, N., Combinatorial Algorithms (Prentice-Hall, Englewoods Cliffs, NJ, 1977). [10] Whitney, H., The coloring of graphs, Ann. Math.,33(1932) 688-718. [11] Zykov,A.A., On some properties of linear complexes, Amer. Math. Soc. Transl. Nº79 (1952); translated from Math. Sb., 24, Nº66 (1949),163-188.

Suggest Documents