5
Information Processing Letters 66 (1998) 209-213 Linear time algorithms for graph search and connectivity determination on complement graphs Hiro Ito *. Mitsuo Yokoyama Received 27 January 1997; received in revised form 10 December 1997 Communicated by T. Asano Abstract This paper presents a storage method to represent a simple undirected graph, that is, to maintain in a data structure the original graph if m < n(n - 1)/4, and the complement graph if m > n(n - 1)/4. The paper also considers the linear time solvability of some problems based on this storage method. It shows that a breadth first search tree and a depth first search tree on the complement graph of a given graph can be constructed in linear time. It also shows that legal node ordering and sparse subgraphs preserving connectivity properties of the complement graph of a given graph can be found in linear time. By using this procedure, we can solve the problems on complement graphs for determining k-node (k-edge) connectivity for k < 3, and constructing a minimal 2-node (Z-edge) connected spanning subgraph in linear time. 0 1998 Elsevier Science B.V. All rights reserved. Keywords: Algorithms: Computational complexity: Complement graph: Graph search; Graph representation: Connectivity 1. Introduction Compact representations of graphs are very impor- tant not only for practical purposes but also for theo- retical purposes. For example, of theoretical purpose, calculating time complexity of algorithms should be based on a compact representation of input data. To represent a simple undirected graph G = (V, E), where V is a node set and E is an edge set, the ad- jacency list method is generally used, thus O(n + m) space is required, where IZ = 1 VI and m = 1 E I. But for simple undirected graphs G, it should be noted that the complement graph GC of G is sufficient for representing G. For a very dense G, the size of the edge set of the complement graph may be much less * Corresponding author. Email: [email protected]. 002U-0190/98/$19.00 Q 1998 Elsevier Science B.V. All rights reserved PII: SOO20-0190(98)00071-4 than m. Therefore, we propose a storage method so that we maintain in a data structure the original graph if m 6 n(n - 1)/4, and the complement graph if m P- n(n - 1)/4. This storage method requires O(n + min(m, mC}) space to represent a simple undirected graph,wheremC=n(n-1)/2-m. Recall two famous graph problems, the maximum clique problem and the maximum independent set problem [7], which can be regarded as essentially the same problem in the sense that the two problems can be converted into each other just by replacing the graph instance with its complement one. Note that they cannot be reduced into each other in linear time when the instances are represented by the traditional storage method because even if an instance of the maximum clique problem is a sparse graph, the corresponding instance of the maximum independent set problem

Linear time algorithms for graph search and connectivity determination on complement graphs

Embed Size (px)

Citation preview

Information Processing Letters 66 (1998) 209-213

Linear time algorithms for graph search and connectivity determination on complement graphs

Hiro Ito *. Mitsuo Yokoyama

Received 27 January 1997; received in revised form 10 December 1997 Communicated by T. Asano

Abstract

This paper presents a storage method to represent a simple undirected graph, that is, to maintain in a data structure the original graph if m < n(n - 1)/4, and the complement graph if m > n(n - 1)/4. The paper also considers the linear time solvability of some problems based on this storage method. It shows that a breadth first search tree and a depth first search tree on the complement graph of a given graph can be constructed in linear time. It also shows that legal node ordering and sparse subgraphs preserving connectivity properties of the complement graph of a given graph can be found in linear time. By using this procedure, we can solve the problems on complement graphs for determining k-node (k-edge) connectivity for k < 3, and constructing a minimal 2-node (Z-edge) connected spanning subgraph in linear time. 0 1998 Elsevier Science B.V. All rights reserved.

Keywords: Algorithms: Computational complexity: Complement graph: Graph search; Graph representation: Connectivity

1. Introduction

Compact representations of graphs are very impor- tant not only for practical purposes but also for theo- retical purposes. For example, of theoretical purpose, calculating time complexity of algorithms should be based on a compact representation of input data. To represent a simple undirected graph G = (V, E), where V is a node set and E is an edge set, the ad- jacency list method is generally used, thus O(n + m) space is required, where IZ = 1 VI and m = 1 E I. But for simple undirected graphs G, it should be noted that the complement graph GC of G is sufficient for representing G. For a very dense G, the size of the edge set of the complement graph may be much less

* Corresponding author. Email: [email protected].

002U-0190/98/$19.00 Q 1998 Elsevier Science B.V. All rights reserved PII: SOO20-0190(98)00071-4

than m. Therefore, we propose a storage method so that we maintain in a data structure the original graph if m 6 n(n - 1)/4, and the complement graph if m P- n(n - 1)/4. This storage method requires O(n + min(m, mC}) space to represent a simple undirected graph,wheremC=n(n-1)/2-m.

Recall two famous graph problems, the maximum clique problem and the maximum independent set problem [7], which can be regarded as essentially the same problem in the sense that the two problems can be converted into each other just by replacing the graph instance with its complement one. Note that they cannot be reduced into each other in linear time when the instances are represented by the traditional storage method because even if an instance of the maximum clique problem is a sparse graph, the corresponding instance of the maximum independent set problem

210 H. Ito, M. Yokoyama /Information Processing Letters 66 (1998) 209-213

may be a dense graph. By adopting our storage method, however, the corresponding instances require the same amount of space; we can thus reduce one problem to another problem in linear time.

Obviously, our storage method does not effect the polynomial solvability of graph problems, but it causes an important issue on the running time of polynomial

time algorithms, particularly linear time algorithms, since the time complexities are measured by II and m. That is, a linear time algorithm using the input of an

original graph G may be unable to run in linear time if an instance is represented by our storage method. This occurs by the same reason of that linear time algorithms on input of the incidence matrix method may not run in linear time on input of the adjacency list method, which is more compact.

Therefore this paper studies linear time solvability from the view point of our storage method. Compact

representations of graphs and algorithms on them have been examined in some papers. Feder and Motwani [3] showed that the clique compression method reduces running times for some graph problems. Kao and Teng [ 121 proposed two compression schemes for adjacency lists and also propose O((n + m)a(n, rz + m)) time breadth first search and depth first search algorithms on these inputs, where (II is the inverse Ackerman function.

On our storage method, the linear time solvability is trivial when an instance is represented by the original graph; it is thus sufficient to consider the case where an instance is represented by its complement graph. Thus, put it in other words, we will consider the algorithms which treat the complement graphs of input graphs.

First, we consider graph search, which is the funda- mental technique used for designing numerous graph algorithms: the most important graph search tech- niques are breadth first search (BFS) and depth first search (DFS). Many linear time algorithms for graph problems rely on BFS and/or DFS, where the ordering of nodes visited by such graph searches plays a key role. Thus we present algorithms for finding both BFS and DFS trees of the complement graph GC in linear time with respect to the size of an input graph G. Next, legal node ordering and sparse subgraphs preserving connectivity properties [2] are considered. These ideas are proposed by Nagamochi and Ibaraki [13] and ex- tended by Frank, Ibaraki and Nagamochi [2]. We also show a linear time algorithm for obtaining a legal node

ordering and a sparse subgraphs preserving connec- tivity properties of the complement graph of a given graph. Finally, we consider some other problems on complement graphs that can be solved in linear time by using these search algorithms. They are determining k- node (k-edge) connectivity for k < 3 [9,14], and con- structing a minimal 2-node (2-edge) connected span-

ning subgraph [8]. This paper shows that they can be solved in linear time.

Although this paper treats only simple undirected graphs, the same argument can be applied to simple directed graphs.

2. Breadth first search and depth first search

In this section we propose linear time algorithms for finding a BFS tree TB and a DFS tree TD of the

complement graph of a given graph. We explain an algorithm for DFS mainly, because it is more difficult

than one for BFS. The linear time computability of BFS trees are described later.

We define some notations used in this paper. An edge can be expressed as (i, j), where i, j E V are

nodes, to which the edge is incident. A complement graph GC = (V, EC) of G = (V, E) is defined by

EC := {(i, j) 1 (i, j) y! E, i, j E V, i # j}.

In this paper every node is numbered from 1 to n, that is,V=(1,2 ,..., n).

An outline of an algorithm for constructing TD of the complement graph GC = (V, EC) of a given graph G = (V, E) rooted from node i E V is described as follows.

procedure DFS (i )

begin 1 If there is a node j such that (i, j) E EC and

j is not included in TD then 2 let (i, j) be included in TD;

store j in the top of stack S; 3 else remove i from stack S; endif; 4 Select a top node k of stack S; call DFS(k); end.

How to implement line 1 is a key point for realizing a linear time computation: line 1 is called O(n + m) times in the entire algorithm thus if O(n + m) calls of line 1 can be executed in O(n + m) time, TD can be

H. Ito, M. Yohmyama /Information Processing Letters 66 (1998) 209-213 211

constructed in O(n + m) time. Imai and Asano [IO] showed that such operations can be realized by using a preprocess that sorts adjacency lists of (i, j) E E

for each i to be appeared in increasing order of j and the linear time union-find technique proposed by Gabow and Tarjan [5]. In the paper written by Imai

and Asano [lo], BFS and DFS for geometric graphs are examined, but the similar technique can be used for complement graphs. Therefore, we can obtain a linear lime algorithm for constructing DFS trees.

We can show a BFS tree is also constructed in O(n + m) time as DFS trees. It is easy to obtain such an algorithm by modifying procedure DFS. That is, “DFS”, “stack S” and “store j in the top of stack S”

are replaced by “BFS”, “queue Q” and “store j in the bottom of queue Q”, respectively. Now, we obtain the following proposition.

Proposition 1. A depthfirst search tree and a breadth first search tree of the complement graph of a given

graph G = (V, E) can be constructed in O(n + m) time, where n = IV1 andm = [El.

There is a more simple algorithm for constructing a BFS tree of the complement graph of a given graph in O(n + m) time. It requires neither the preprocess for sorting adjacency lists nor Gabow and Tarjan’s linear time union-find algorithm. We show the algorithm as an appendix.

3. Legal node ordering and connectivity

Legal node ordering and sparse subgraphs preserv- ing connectivity properties are useful for examining connectivity of graphs [2,13]. We call an ordering

vi,v2,...,v,ofthenodesofGlegalif

IE(Vi-1, vi)1 3 IE(Vi-1, uj)l

holdsforeachl ti <j~nwhereVh:=(vl,...,vh}. Here E(Y, x), Y 2 V, x E V denotes the set of edges connecting Y and x. For an edge e = (vi, Uj), where i < j, we call vi the tail of e and Uj the head of e and let t(e) := i and h(e) := j. For each i = 1,2,..., n, we give an ordering e!, ef, . . , er of

the edges of E(Vi_1, vi) such that t(ej) < t(e!‘) for 1 6 j < j’ 6 r = IE(Vi-1,vi)I. We define Fj by

{eij 1 i = 1,2, . . , n}. Let Ek := Fl U F2 U ... U Fk

and Gk := (V, Ek). Nagamochi and Ibaraki [13] have shown that

h(x, y; Gk) 3 min {h(x, y; G), k} and

K(X, Y; Gk) 3 mh {x(x, y; G), k}

for every pair x, y E V, where h(x, y; G) and K(X, y; G) mean the edge connectivity and node connectiv- ity between x and y in G, respectively. Gk is called a spanning subgraph preserving k-connectivity prop- erties. Nagamochi and Ibaraki [ 131 also presented an algorithm for finding one of the spanning subgraphs preserving k-connectivity properties in O(n +m) time. In this section we implement it on complement graphs. We consider the problem for finding a spanning sub- graph preserving k-connectivity properties of comple- ment graph GC of input graph G and present a linear time algorithm. Note that the output of this problem is G& = (V, Ei) that requires O(n + 1 EiI) spaces, where (ELI =O(min{lECI =n(n - 1)/2-m, kn}) thuslin- ear time means O(n + m + min{n(n - 1)/2 -m, kn})

time. Note that it is difficult to construct this algorithm

by using Imai and Asano’s technique [lo] applied for BFS and DFS in Section 3: In the technique presented by Imai and Asano, all edges incident to a searched node are deleted from the graph (this operation is called DELETE in the paper [lo]). This is sufficient to construct BFS or DFS trees but it is certainly inappropriate for our purpose.

First, we show an algorithm for the problem as follows. The correctness of this procedure can be directly shown from [2,13].

procedure PRESERVE(G, k) begin

Fi:=PIfori=1,2,...,k; level(i) := 0 for i = 1,2, . . . , n; let all nodes and edges be unscanned; Select one node i; call SCAN(i);

end.

procedure SCAN(i) begin 1 for (i, j) E EC such that (i, j) is unscanned and

level(j) < k do 2 Let (i, j) be included in Fle”,l(j)+l

3 if level(i) = level(j) then level(i) := level(i) + 1;

212 H. Ito, M. Yokoyama /Information Processing Letters 66 (1998) 209-213

4 level(j) := level(j) + 1; 5 Let (i, j) be scanned;

6 enddo; 7 Let i be scanned; 8 Select a node i’ such that

level(i’) = max{level(i”) 1 i” E V is unscanned};

9 call SCAN(i”); end.

To make this procedure run in linear time for a given graph G = (V, E), we do not use an array level(i) explicitly. We realize it by using an n-dimensional array levelcomp(i) defined by levelcomp(i) = n, - level(i), where n, is the number of scanned nodes. Initially, Zevelcomp(i) := 0 for all i E V. When node i is scanned, levelcomp(j) is not changed for j such that (i, j) E EC thus updating time of levelcomp does not depend on the number of edges of the comple- ment graph. We also prepare n buckets such that each unscanned node i is contained in the levelcomp(i)th

bucket. All nonempty buckets are doubly linked by pointers so that an unscanned node i with the small- est levelcomp(i), i.e., the largest level(i), can be found in O(1) time and the link update after increasing levelcomp, i.e., not increasing level, of a node by one can also be done in O(1) time. We also use an rz- dimensional array check(j), which is used for check- ing whether or not node j is adjacent to a node be- ing scanned. Now we explain the detail of the algo- rithm. In the operation of line 1 of procedure SCAN, increase Zevelcomp( j) by one and let check(j) := i for all (i, j) E E and scan nonempty buckets from n - 1 to n, - k + 1 in the decreasing order. Here increasing levelcomp(j) by one for all (i, j) E E is equivalent to increasing Zevel(j) by one for all (i, j) E EC. More- over, scanning nonempty buckets from n - 1 to ns - k + 1 in the decreasing order is equivalent to scanning nodes from level(O) to level(k - 1) in the increasing or- der. (Note that for any h such that n - 1 > h > nS, hth backet is empty.) If a node j such that check(j) # i

is found by this scan, it means that (i, j) E EC such that (i, j) is unscanned and level(j) < k is found in line 1. Using the above technique, the operations in lines l-6 of procedure SCAN can be executed in O(n + m + 1 Ez I) time in the entire algorithm. There- fore, we obtain the following theorem.

Theorem 2. A spanning subgraph preserving k-con- nectivity properties for the complement graph of a

given graph G = (V, E) can be found in linear (O(n + m + min{n(n - 1)/2 - m, kn))) time, where n = IVJ,

m = JEl.

Note that min{n(n - 1)/2 - m, kn} is the space re- quired to represent the output and that the computation time is O(n + m) if k is fixed. Thus we can get the fol- lowing corollary from Theorem 2.

Corollary3. For a fixed positive integer k, tf the

problem for determining whether or not a given graph

is k-node (k-edge) connected can be solved in f (n, m)

(= S2(n + m)) time, the problem for determining whether or not the complement graph of a given graph

is k-node (k-edge) connected can be also solved in

0( f (n, m)) time.

We know that the problem for determining whether or not a given graph is k-node connected can be solved

in O(n + m) time for k 6 3 [9], in O(m + n a(n, n))

timefork=4[11]andO(m+n2)forotherfixedk[1, 141. Moreover, the problem for determining whether or not a given graph is k-edge connected can be solved in O(n + m) time for k < 3 [14], in O(m + na(n, n))

time for k = 4 [6,1 l] and O(m + n logn) for other fixed k [4,14]. From Corollary 3, these problems on complement graphs are solved in the same time order, respectively. From the similar discussion, the problem for finding a minimal 2-node (2-edge) connected

spanning subgraph [8] on the complement graph of a given graph can be solved in linear time.

4. Concluding remarks

We examined a storage method to represent a simple undirected graph. The method is to maintain in a data structure the original graph if m < n(n - 1)/4, and the complement graph if m > n(n - 1)/4. We also considered the linear time solvability of some problems based on this storage method. We showed that breadth first search tree and depth first search tree on the complement graph of a given graph can be constructed in linear time. We also showed that legal node ordering and sparse subgraphs preserving connectivity properties of the complement graph of a given graph can be found in linear time. By using this procedure, we can solve the problems on complement

graphs for determining k-node (k-edge) connectivity fork < 3, and constructing a minimal 2-node (2-edge) connected spanning subgraph in linear time.

Some interesting problems remain on the algo- rithms of complement graphs. For example, on some problems, the computational time may be reduced by using the algorithms of complement graphs.There may be some problems which can be solved in linear time

but their complement graph versions cannot be solved in linear time. But if there is such a problem, it seems difficult to prove it.

Acknowledgements

I would like to express my appreciation to Profes- sor Ibaraki Toshihide and Associate Professor Nag- amochi Hiroshi of Kyoto University for their valuable comments. I also wish to thank Professor Masuyama Shigeru of Toyohasi University of Technology for his

helpful advice.

Appendix A. A more simple BFS algorithm

procedure BFS(i) comment F is a doubly-linked list of nodes that is not

scanned yet, i.e., F = V - V(TB); begin 1 for all j such that (i, j) E E do check(j) = i enddo; 2 for all j E F do 3 if check(j) # i then 4 Let (i, j) be included in TB; store j in the

bottom of queue Q; remove j from F; endif

5 enddo 6 Remove i from queue Q; Select a top node k of

queue Q; call BFS(k);

end.

H. Ito, M. Yokoyama /Information Processing Letters 66 (1998) 209-213 213

References

[I] S. Even, An algorithm for determining whether the connectiv-

ity of a graph is at least k, SIAM .I. Comput. 4 (1975) 393-396.

[2] A. Frank, H. Nagamochi, H. Ibaraki, On sparse subgraphs

preserving connectivity properties, .I. Graph Theory 17 (1993) 275-281.

[3] T. Feder, R. Motwani, Clique partition, graph compression and

speeding-up algorithms, in: Proc. 23rd ACM Symp. Theory of

Computing, 1991, pp. 123-133.

[4] H.N. Gabow, A matroid approach to finding edge connectivity

and packing arborescences, in: Proc. 23rd ACM Symp. Theory

of Computing, 1991, pp. 112-122.

[5] H.N. Gabow, R.E. Tarjan, A linear-time algorithm for a special

case of disjoint set union, J. Comput. System Sci. 30 (1985)

209-22 1,

[6] 2. Galil, G.F. Italiano, Reducing edge connectivity to vertex

connectivity, SIGACT News 22 (1991) 57-61.

[7] M.R. Garey, D.S. Johnson, Computers and Intractability:

A Guide to the Theory of NP-completeness, Freeman, San

Francisco, 1979.

[S] X. Han, P. Kelson, V Ramachandran, R.E. Tarjan, Computing

minimal spanning subgraphs in linear time, in: Proc. 3rd ACM-

SIAM Symp. on Discrete Algorithms, 1992, pp. 146156.

[9] J.E. Hopcroft, R.E. Tarjan, Dividing a graph into triconnected

components, Inform. and Comput. 79 (1988) 43-59.

[lo] H. Imai, T. Asano, Efficient algorithms for geometric graph

search problems, SIAM J. Comput. 15 (1986) 478494.

[l l] A. Kanevsky, R. Tamassia, G.D. Battsia, J. Chen, On-line

maintenance of the four-connected components of a graph, in:

Proc. 32nd IEEE Symp. Found. Comp. Sci., 1991, pp. 793-

801.

[12] M.Y. Kao, S.H. Teng, Simple and efficient graph compression

schemes for dense and complement graphs, in: Proc. of ISSAC-

94, Lecture Notes in Comput. Sci., Vol. 834, Springer, Berlin,

1994, pp. 451-459.

[ 131 H. Nagamochi, T. Ibaraki, A linear-time algorithm for finding a

sparse k-connected spanning subgraph of a k-connected graph,

Algorithmica 7 (1992) 583-596.

[14] H. Nagamochi, T. Ibaraki, A linear time algorithm for com-

puting 3-edge-connected components in a multigraph, Japan

J. Industrial Appl. Math. 9 (1992) 163-1 SO.