Complexity of Computation of a Spanning Tree ... - Computer Science

17 downloads 0 Views 1018KB Size Report
spanning trees of an undirected graph G. This algorithm starts with a known initial ..... For an n-vertex connected graph with maximum degree n - 1, to < t for any ...
IEEE TRANSACTIONSON CIRCUITSAND SYSTEMS, VOL. CAS-31, NO. lo, OCTOBER1984

853

Complexity of Computation of a Spanning Tree Enumeration Algorithm R. JAYAKUMAR,

K. THULASIRAMAN,

Absrracr -In l!X3, Char [4] presented an algorithm to enumerate all the spanning trees of an undirected graph G. This algorithm starts with a known initial spanning tree of G, and generatesall the other spanning trees along with certain spanning non-tree subgraphs of G. In this paper a detailed complexity analysis of char’s algorithm and methods to speed up the algorithm are discussed.Two heuristics for the selection of the initial spanning tree are suggested. These heuristics result in a considerable reduction in the number of spanning non-tree subgraphs generated. A technique called path compression, aimed at reducing the actual number of comparisons, is described. Computational results on several randomly generated graphs are presented to illustrate the improvement achieved.

I. INTRODUCTION NUMERATING all the spanning trees of a graph without duplication is one of the widely studied graph problems in Electrical Engineering and Computer Scienceliterature. Since the number of spanning trees of a graph increasesrapidly with the size of the graph, a highly efficient algorithm is desired to enumerateall the spanning trees of a graph. Several algorithms of varying efficiency have beenproposed in the literature. One of the well-known algorithms is due to Minty [l], which has been shown [2] to be of complexity O(m + n + mt), where m and II are the number of edgesand the number of vertices of the graph, respectively, and t is the number of spanning trees of the graph. Another efficient algorithm of complexity O(m + n + nt) is due to Gabow and Myers [3]. In 1968, Char [4] had presented a conceptually simple and elegant algorithm to enumerate all the spanning trees of a graph. However, Char had not presenteda complexity analysis of his algorithm. The recent analysis of Char’s algorithm presented in [5] suggests that this algorithm might be the best of all the algorithms available so far for the spanning tree enumeration problem. In this paper, we not only present a more detailed complexity analysis of Char’s algorithm but also discuss different methods to further improve the speedof the algorithm. In Section II we give a formal description of Char’s algorithm and summarisesome of its interesting properties reported in [5]. In Section III we give a detailed complexity analysis of this algorithm and present severalof its quantitative and qualitative properties. In Section IV we develop two heuristic procedureswhich help speedup Char’s algo-

E

Manuscriot received March 31. 1983: revised Seotember 6. 1983 and November 25 1983. This work was su’ ported by ihe Naturh Sciences and Enzineer& Research Council of 8 anada under Grant A-7739 and under &ant A-2680. The authors are with the Facult of En ‘neering and Computer Science, Concordia University, Montreal, S.Q., HTG lM8 Canada.

AND M. N. S. SWAMY, FELLOW, IEEE

rithm by minimizing the number of non-tree subgraphs generated by the algorithm. Finally, in Section V, we discuss a general technique called path compression,which can be used for an efficient implementation of Char’s algorithm to reduce the actual number of comparisons made by the algorithm. For graph theory terms and notation not defined here, see[6]. Without any loss of generality we also assumethat the graphs considered in this paper are simple biconnected undirected graphs. II.

CHAR'SALGORITHMTO ENUMERATEALLTHE SPANNINGTREES

Consider a connected undirected graph G = (V, E) with IZ= JV] vertices and m = ]E] edges.Let the vertices of G be denoted as 1,2; . 0,n. Let h = (DIGIT(l), DIGIT(2); . ., DIGIT(n - 1)) denote a (II - 1)-digit sequenceof vertices such that DIGIT is a vertex adjacent to vertex i in G. With each such sequenceA we can associate a subgraph Gx = (V,, Eh) of G such that and E,= {(~,DIGIT(~)),

(~,DIGIT(~)),..., (n -l,DIGIT(n

-1))).

Char’s algorithm first performs a Breadth-First Search [6] on G and finds a spanning tree called the initial spanning tree. During this search,the vertices of G are also renumbered as n, n - 1,. . . , 1 in the order in which they are visited. Let h, = (REF(l), REF(2), * . . , REF( n - 1)) be the sequencecorresponding to this spanning tree. Starting with h,, the algorithm enumeratesall the other spanning trees of G by generating the sequencescorresponding to the spanning trees of G. During this enumeration, the algorithm also generatescertain sequenceswhich correspond to spanning non-tree subgraphs of G. The sequencescorresponding to spanning trees are referred to as tree sequences and those corresponding to spanning non-tree subgraphs are referred to as non-tree sequences.The sequenceh, is called the initial tree sequence. Char’s algorithm classifiesa generatedsequenceas a tree sequenceif it satisfies the following. Tree Compatibility Property The sequence(DIGIT(l), DIGIT(2), * . . , DIGIT( n - 1)) represents a spanning tree of graph G if and only if

0098-4094/84/1000-0853$01.00 01984 IEEE

854

IEEE TRANSACTIONSON CIRCUITSAND SYSTEMS,VOL.CAS-31,N0. 10, OCTOBER1984

for each j 6 n -1 there exists, in G, a sequence of edges (chosen from among the edges (1, DIGIT(l)), (2, DIGIT(2)); . . , (n - 1, DIGIT(n - 1))) with ( j, DIGIT( j)) as the starting edge,which leads to a vertex 0 k > j. If a sequencedoes not have the above property, then it is a non-tree sequence. Char’s algorithm can be presentedin ALGOL-like notation as follows.

Theorem 1 For a complete graph, the number to of spanningnon-tree subgraphsgeneratedby Char’s algorithm is independent of the initial spanning tree. cl Theorem 2 Let G(“-i) be the set of all connected n-vertex graphs having at least one vertex of degree n - 1. For any graph G E G(“-l), to 6 t, if the initial spanning tree is a star tree. cl

Char’s Algorithm to Enumerateall the Spanning Trees A characterization of each spanning non-tree subgraph procedure CHAR; generated by Char’s algorithm is also given in [5]. comment The graph G is representedby the adjacencylists of its vertices. SUCC(DIGIT(i)) is the entry next III. COMPUTATIONAL COMPLEXITY OF CHAR'S to DIGIT(i) in the adjacency list of vertex i. ALGORITHM

begin

find the initial spanning tree and obtain the initial tree sequenceX, = (REF(l), REF(2), . . . , REF( n - 1)); renumber the vertices of the graph using the initial spanning tree; initialize DIGIT(i):= REF(i), 1~ i G n - 1; output the initial spanning tree; k:=n -1; while k f 0 do begin if SUCC(DIGIT(k)) # nil then begin

DIGIT(k): = SUCC(DIGIT(k)); if DIGIT(i), 1~ i 6 n - 1, is a tree sequence then begin

output the tree sequence; k:=n -1 end end else begin

DIGIT(k): = REF( k); k:=k -1

/

Since the computational complexity of Char’s algorithm is O(m + n + n(t + to)), any complexity analysis of this algorithm would require a study of the number (t + to). With this objective in view, we first obtain an expression for (t + to). Let n-l

T= u q I=0 be the set of all the tree sequencessuch that (i) To= {A,,}, and (ii) T., l