Efficient parallel algorithms for series parallel graphs

Efficient parallel algorithms for series parallel graphs

JOURNAL OF ALGORITHMS 12, 409-430 (1991) Efficient Parallel Algorithms for Series Parallel Graphs XIN HE” Department of Computer of New Scienc...

1MB Sizes 0 Downloads 108 Views

JOURNAL

OF ALGORITHMS

12, 409-430 (1991)

Efficient Parallel Algorithms

for Series Parallel Graphs

XIN HE” Department

of Computer

of New

Science, State University Buffalo, New York 14260

York at Buffalo,

Received November 1988; accepted November 1990

We present efficient parallel algorithms for solving three problems for series parallel graphs: 3-coloring, depth-first spanning tree, and breadth-first spanning tree. If the input is given by the decomposition tree, the first two problems can be solved in O(log n) time with O(n/log n) processors, the last problem can be solved in O(log n log log n) time with O(n) processors. We also present a parallel algorithm for recognizing series parallel graphs and constructing decomposition trees. This algorithm takes O(log’ n + log m) time with O(n + m) processors, where n (m) is the number of vertices (edges) in the graph. Q 1991 Academic press, Inc.

1.

INTRODUCTION

Series Parallel (SP) graphs find applications in the fields of electric networks and scheduling problems [Du,VTL]. Algorithms for solving various SP graph problems have been studied by a number of authors [BLW, Du, HT, HYl, HY2, TNS, Ts, VTLI. In ‘this paper we present a parallel algorithm for recognizing SP graphs. If the input graph G is an SP graph, the algorithm constructs a decomposition tree for G. This algorithm takes O(log2 n + log m) time with O(n + ml processors, where n (ml is the number of vertices (edges) in G. We also present efficient parallel algorithms for solving three basic problems on SP graphs: 3-coloring, depth-first spanning tree, and breadth-first spanning tree. If the graph is given by its decomposition tree, the first two problems can be solved in O(log n) time with O(n/log n> processors, the last problem can be solved in O(log n log log n> time with O(n) processors. These algorithms are based on the tree contraction algorithm [MR]. If the input is not given by the decomposition tree, we *Research supported in part by NSF grant CCR-9011214.

409 Copyright0 AI1 rights

0196-6774/91 $3.00

1991 by Academic Press, Inc. of reproduction in any form reserved.

410

XIN HE

construct the decomposition sition algorithm. The parallel computation

tree by calling the recognition

and decompo-

model we use is a concurrent read concurrent write parallel random access machine (PRAM). The model consists of a common memory and a number of processors. In each time unit, a processor can read a memory cell, perform an arithmetic or logic operation, and write into a memory cell. Both concurrent read and concurrent write to the same memory cell are allowed. In case of a write conflict, an arbitrary processor succeeds. The present paper is organized as follows. Section 2 introduces the definitions and background. The recognition and decomposition algorithm is presented in Section 3. Section 4 reviews the tree contraction algorithm. In Sections 5, 6, and 7, we present the algorithms for solving 3-coloring, depth-first spanning tree, and breadth-first spanning tree problems.

2. DEFINITIONS

AND BACKGROUND

Most of the graph definitions we use are standard [BMI. Unless stated otherwise, the term “graph” always means a multigraph. Let G = (V, E) be a graph. We say two edges e, = (u, w> and e2 = (w, u) of G are in series if their common vertex w has degree 2. Two edges e, and e2 are parallel if they have the same set of end vertices. By a seriescomposition of an edge e = (u, u) we mean the replacement of e by two edges in series, i.e., by (u, w> and (w, v>, where w is a new vertex. By a parallel composition of an edge e = (u, u), we mean the replacement of e by two parallel edges e, and e2 having u and u as end vertices. By a series reduction of two edges in series e, = (u, w> and e2 = (w, v), we mean the replacement of e, and e2 by a new edge e = (u, u>. By a parallel reduction of two parallel edges e, = (u, v> and e2 we mean the replacement of e, and e2 by a new edge e = (u, v). Let s and t be two vertices of G. If G can be obtained by a sequence of series and parallel compositions from a single edge (s, t>, G is called a two terminal seriesparallel CITSP) graph with respect to s and t. Alternatively, G is a TTSP graph with respect to s and t if it can be reduced to a single edge (s, t) by a sequence of series and parallel reductions. G is called a series parallel (SP) graph, if there exists two vertices s and t so that G is a TTSP graph with respect to s and t. An SP graph G can be represented by a decomposition tree T, which is constructed with the process that reduces G to a single edge (s, t), as follows. During the reduction process, each edge is associated with a tree structure. When the reduction process terminates, the tree associated with the single remaining edge (s, t) is the decomposition tree of G. Originally

SERIES PARALLEL

G

GRAPH.5

411

T

FIG. 1. An SP graph G and its decomposition tree T.

each edge e of G is associated with a tree consisting of a single node. When a series reduction is performed on two edges e, and e2 we create a new “s-node” u and make the tree associated with e, (e,) the left (right) child of u. When a parallel reduction is performed on e, and e2 we create a new “p-node” u and make the tree associated with e, (e2) the left (right) child of u. Figure 1 shows an SP graph G (ignore the direction of the edges) and its decomposition tree T. The edges of an SP graph G can be oriented as follows. Consider the process that generates G from a single edge (s, t). Direct this edge from s to t. When a series composition is performed on a direct edge (u, u), we generate two direct edges (u, w) and (w, u). When a parallel composition is performed on a directed edge (u, v), we generate two directed edges from u to u. It is easy to show that the resulting directed graph c is acyclic and has s as the only source (a vertex with no incoming edges) and t as the only sink (a vertex with no outcoming edges). We call c a directed TISP graph with source s and sink t. Figure 1 shows a directed TTSP graph G. The following lemma is well known [DU, VI’L].

FIG. 2. The forbidden subgraph of directed TTSP graphs.

412

XIN HE

LEMMA 1. (a) Let G be a biconnected undirected graph. G is an SP graph if and only if G does not contain a subgraph homeomorphic to K, (the complete graph of 4 vertices).

(b) Let G be a biconnected SPgraph and (s, t> be any edge of G. Then G is a TTSP graph with respect to s and t. Cc) Let G be a directed acyclic graph with one source and one sink. G is a directed TTSP graph if and only if G does not contain a subgraph homeomorghic to the graph in Fig. 2.

3. RECOGNITION AND DECOMPOSITION ALGORITHM

FOR SP GRAPHS

A parallel algorithm for recognizing and decomposing directed TTSP graph was presented in [HYl]. Given a directed acyclic graph G, this algorithm determines if G is a directed TTSP graph or not. If the answer is yes, the algorithm constructs a decomposition tree T for G. This algorithm takes O(log’ n + log ml time with O(n + ml processors. The assumption that G is a directed acyclic graph is essential for the algorithm. A parallel recognition and decomposition algorithm for SP graphs was developed in [Ts]. This algorithm takes 000g3 m) time with O(m4) processors. In this section we present an algorithm for this problem which takes O(log* n + log m> time with O(n + m) processors. The basic idea of the algorithm is as follows: First, identify two vertices s and t in G so that G is a TI’SP graph with respect to s and t. Second, orient the edges of G so that the resulting directed graph ?? is acyclic and has s as the only source and t as the only sink. Third, apply the recognition and decomposition algorithm in [HYl] to G. We first prove several lemmas needed by our algorithm. Let G be a connected undirected graph. Suppose a, . * . ak are the cut vertices of G and B, * * * B, are the biconnected components of G. Define the reduction tree RT of G as follows: The node set of RT is {aI * . . ak, b, * * . b,). (ai, bj) is an edge in RT if and only if a, is a vertex in Bj (Fig. 3). It can be shown that RT is a tree and all leaf nodes of RT are bj nodes [AHU]. LEMMA 2. Let G be a connected unidirected graph. Let B, * . . BI be the biconnected components of G and let RT be the reduction tree of G. G is an SP graph if and only if the following two conditions hold:

(1) RT is a path: b, -+ a, + b, -+ a2 *. * al-, -+ b, (reorder Bj’s if necessary). Namely each cut vertex ai (1 5 i 5 1 - 1) is contained in two components Bi and Bi + 1. Each component Bj (2 5 j _< 1 - 1) contains two

SERIES

PARALLEL

GRAPHS

413

FIG. 3. A graph G and its reduction tree RT.

cut vertices aidI and aj. B, contains one cut vertex a,. B, contains one cut vertex a,- I (Fig. 3). (2) For any vertex s in B, adjacent to a, and any vertex t in B, adjacent to a,- 1, G is a TTSP graph with respect to s and t.

If. Condition (2) alone implies that G is an SP graph. Only if. Suppose G is an SP graph. Then G can be reduced to a single edge (so, to) (for some vertices s0 and t, of G) by a sequence S of series and parallel reductions. This implies that there exists an orientation F, of G such that the resulting directed graph 5 is acyclic and has se as the only source and t, as the only sink. Toward a contradiction, suppose RT is not a path. Then RT contains at least three leaf nodes. In any acyclic orientation of G, each biconnected component of G that corresponds to a leaf node of RT must contain at least one sink or one source. So there can be no orientation of G that contains only one source and one sink. Hence F,, cannot exist, a contradiction. Suppose condition (1) holds and let B, and B, be the two components corresponding to the two leaf nodes of RT. Without loss of generality, assume B, contains sa and B, contains t,. The reduction sequence S can be divided into sub-sequences s 1. * * s,, &+1 as follows: S, reduces B, to a single edge (so, a,); S, reduces B, to a single edge (a,, a,); - - * S, reduces B, to a single edge (a,-,, toI; Sl+l reduces the resulting path s,, -+ a, + a2 + *. * --f al-, + t, to a single edge (sa, to). Let s be a vertex in B, adjacent to a, and t be a vertex in B, adjacent to al-, (Fig. 3). Because the existence of the reduction sequence S,, B, is an SP graph. Since B, is biconnected, there is a reduction sequence S; that reduces B, to a single edge (s, a,) by Lemma l(b). Similarly there is a reduction sequence S; that reduces B, to a single edge (al- 1, t). Let S’ be the reduction sequence obtained from S by replacing S, with S; and Proof.

414

XIN

HE

replacing SI and S;. Then S’ reduces G to a single edge (s, t>. This implies condition (2). 0 Let G be an undirected connected graph and let s and t be two vertices of G. An s-t orientation of G is an orientation of the edges of G so that the resulting directed graph c is acyclic and has s as the only source and t as the only sink. LEMMA 3. Let G be a TTSP graph with respect to s and t. Then there exists a unique s-t orientation for G. Proof: The existence of the s-t orientation follows from the remark in the paragraph preceding Lemma 1. We need to show the s-t orientation is unique. If (s, t) is not an edge of G, adding an edge (s, t) into G will result in a graph that is still a TTSP graph with respect to s and t. Thus, without loss of generality, we assume (s, t) is an edge in G. Toward a contradiction, suppose G has two distinct s-t orientations F, and F2. Suppose an edge (u, U> of G is oriented from u to u in the orientation Fl sd oriented from u to u in the orientation F2. In the directed graph G, obtained from Fl there exists a path P,(v) from u to t since t is the only sink of E, (Fig. 4). Similarly there exists a path P,(u) from s to U. Applying the same argument to the directed graph c1 obtained from F,, it can be shown that there exists a path P,(u) from u to t and a path P,(u) from s to U. The subgraph induced by the edges in P,(u), P,(u), P,(u), P,(u), the edge (u, u), and the edge (s, t> contains a subgraph homeomorphic to K,. This contradicts Lemma 1 (a>. So the s-t orientation of G is unique. q

Let G = (V, E) be an undirected graph with n vertices and let s, t be two vertices of G. An s-t numbering of G is a one-to-one function f: v-, {1,2... n} satisfying: (al f(s) = 1 and f(t) = n; (b) for each u E V (s, t} there exist two vertices ui and v2 adjacent to u such that f(v,> < f(u) < f(u,>. We can orient the edges of G from an s-t numbering f as follows: For each edge e = (x, y>, if f(x)
FIG. 4.

The proof

of Lemma

3.

SERIES PARALLEL

415

GRAPHS

y. It is easy to see this gives an s-t orientation was proved in [MSV].

for G. The following lemma

LEMMA 4. Let G be a biconnected undirected graph and let (s, t) be an edge of G. An s-t numbering exists and can be constructed in O(log n) time with O(n + m) processors.

We are now ready to present the recognition rithm for SP graphs: ALGORITHM

1 (SP graph recognition

and decomposition

algo-

and decomposition).

(1) Find biconnected components B, . . . B,of G. (2) Construct the reduction tree RT for G. If RT is not a path, G is not an SP graph. Stop. (3) Let B, and B, be the two biconnected components of G corresponding to the two leaf nodes of RT. Let a, be the cut vertex in B, and a,- r be the cut vertex in B,. Let s be a vertex in B, adjacent to a, and t be a vertex in B, adjacent to al-,. Add a dummy edge (s, t) into G and let G’ be the resulting graph. G’ is clearly biconnected. Compute an s-t numbering of G’ (Lemma 4) and obtain an s-t orientation of G’. Remove the dummy edges (s, t). This gives an s-t orientation for G. Let c be the resulting directed graph. (4) Apply the recognition and decomposition algorithm in [HYll for directed TTSP graphs to I??. (5) If G is not a directed TISP graph, G is not an SP graph. If G is a directed TI’SP graph, G is an SP graph. The decomposition tree for G constructed in step (4) is also a decomposition tree for G. End. THEOREM 5. Algorithm 1 correctly solves the recognition and decomposition problem for SP graphs in O(log2 n + log m> time with O(n + m) processorson a PRAM.

Proof. We first show the correctness. Suppose G is an SP graph. By Lemma 2, the reduction tree RT is a path and G is a TTSP graph with respect to s and t. By Lemma 3, there is a unique s-t orientation of G so that the resulting graph is a directed TTSP graph. Since step (3) constructs an s-t orientation for G, the graph c obtained in step (3) is a directed TISP graph. Therefore, G will be recognized as an SP graph at step (5). Suppose G is not an SP graph. Then either condition (1) or (2) of Lemma 2 fails. In the first case, the algorithm rejects G at step (2). In the second case, the algorithm rejects G at step (5). So the algorithm is correct. Step (1) can be done in O(log n) time with O(n + m) processors by using the algorithm in [TV]. The reduction tree can be constructed in O(1)

416

XIN HE

time with O(n + ml processors. The complexity of Step (3) is dominated by the computation of an s-t numbering of G’, which takes O(log n> time with O(n + m) processors by Lemma 4. Step (4) takes O(log2 n + log m> time with O(n + m) processors [HYl]. Step (5) takes constant time with one processor. So the algorithm takes O(log* n + log m> time with O(n + m) processors in total. Cl

4. TREE CONTRACTION ALGORITHM

We will use the tree contraction algorithm to solve various problems for SP graphs. The tree contraction algorithm was originally introduced by Miller and Reif [MR] with O(log n) running time and O(n) processors. Several authors have improved this algorithm to run in O(log n) time with O(n/log n) processors [GMT, ADKP, KD]. In this section we briefly describe the version developed in [ADKP]. A structure is a triple (S, NF, EF) consisting of a set S, a node function set NF c (flf: S X S + S], and an edgefunction set EF G {f If: S + Sl. A bottom-up algebraic computation tree on (S, NF, EF) is a binary tree T such that: each leaf node u of T is labeled by a value L(v) E S; each internal node u of T is labeled by a function F(u) E NE; and each edge e of T is labeled by a function F(e) E EF. The bottom-up algebraic tree computation (B-ATC) problem on T is as follows: Let u be a node of T whose left child ui and right child v2 are leaf nodes. Let e, = (vi, u) and e2 = (vz, u). Compute a value L(u) E S defined by

L(u) = F(u)[F(e,)(L(v,))yF(e2)(L(v2))1 and delete vi, v2, er, e2 from T. (Thus u becomes a new leaf node.) Repeat this operation until all nodes of T receive a value in S. The top-down algebraic tree computation (T-ATC) problem is defined similarly. A top-down algebraic computation tree is a binary tree T such that: the root r of T is labeled by a value L(r) E S; each edge e of T is labeled by a function F(e) E EF. The T-ATC problem on T is as follows: Let vi, v2 be the two children of the root r and let e, = (vi, r), e2 = (v2, r). Compute values L(v,l = F(e,XL(r)) and Uv,) = F(e,XL(r)). Delete r. (Thus vi and v2 become new roots.) Repeat this operation until all nodes of T receive a value in S. In order to solve the B-ATC and T-ATC problems in parallel, [ADKPI introduced the following shunt operation: Let u be a node of T with left child vi, right child v2 and parent w. Let e, = (vi, u), e2 = (vz, u), and e, = (u, w>. Suppose vi is a leaf node (Fig. 5). A shunt operation on vi is as follows: Delete v1 and u from T and make v2 the left child of w. Let

SERIES PARALLEL

417

GRAPHS

FIG. 5. Shunt operation: (a) before; (b) after.

e’ = (uz, U> be the new edge. For the B-ATC problem, F(e’) defined by

For the T-ATC

problem,

assign e’ a function

assign e’ a function

F(e’) defined by

If the right child u2 of u is a leaf node, a shunt operation performed on u2 is defined similarly. Clearly, a shunt operation does not affect subsequent evaluation on T. The following elegant algorithm solves the B-ATC and T-ATC problems [ADKP]: ALGORITHM

2 (Tree contraction).

(1) Number the leaf nodes of T by 1,2,. . . from the left to the right. (2) For all leaf nodes u with an odd number, in parallel, do: Let w be the parent of U; (2.1) if u is the left child of w then Shunt v; (2.2) if u is the right child of w then Shunt u; Let T’ be the resulting tree. (3) Recurse on T’ to compute the values for the nodes in T’. (4) Extend the result to all nodes of T. End. The following theorem was proved in [ADKP]. For detailed implementation and analysis of Algorithm 2, we refer the reader to [AD-]. THEOREM 6. Algorithm 2 correctly solves T-ATC or B-ATC problems. Moreouer, if the shunt operation can be performed by one processor in O(l) time, Algorithm 2 can be implemented in O(log n) time with O(n/log n) processors, where n is the number of nodes in T.

418

XIN HE 5. THREE-COLORING

PROBLEM

In the next three sections we will use the tree contraction algorithm to solve various problems on SP graphs. For all three problems discussed in this paper, multiple edges in the graph are irrelevant. So we assume the input SP graph G contains no multiple edges. Since SP graphs are clearly planar, the number of edges in G is O(n) [BM]. We assume G is given by its decomposition tree T. Since T is a binary tree and the number of leaf nodes in T equals the number of the edges in G, T contains O(n) nodes. Each node u of T represents a subgraph of G. The root r of T represents the original graph G. The subgraph represented by node u will be denoted by G(u). There are two special vertices in G(u): the source and the sink in the directed version of G(u). We call these two vertices the left and the right terminals of G(u) and denote them by l(u) and T(U), respectively. A coloring of a graph G is an assignment of colors to the vertices so that no two adjacent vertices have the same color. We present an algorithm for 3-coloring SP graphs in this section. An SP graph G can be 3-colored sequentially as follows [Dul. Let (1,2,3} denote the three colors. Consider the process that generates G from a single edge (s, t). Initially, color the vertex s and t by two distinct colors. When a series composition is performed on an edge (u, v), the colors of u and u remain unchanged and the third color is assigned to the new vertex w. When a parallel composition is performed on an edge (u, u), the colors of u and u remain unchanged. After this process terminates, a 3-coloring of G results. In order to construct a 3-coloring for G in parallel, we make a “top-down” traversal on its decomposition tree T. When a node u of T is visited, we assign colors to the two terminal vertices I(U) and T(U) of the subgraph G(u). During this coloring process, it is required that the colors assigned to I(U) and T(U) are distinct. For the root r, assign left terminal of G(r) color 1 and the right terminal of G(r) color 2. Consider a node u of T with left child LI, and right child u2. Suppose that the left terminal I(U) and the right terminal I(U) of G(u) have been colored by i and j (1 < i, j 5 3, and i # j), respectively. If u is a p-node, the left and the right terminal of G(u,) and G(u,) are I(U) and T(U), respectively, and they inherit the colors i and j, respectively. If u is an s-node, the left terminal of G(v,) is I(U) and its inherits color i. The right terminal of G(u,) is r(u) and it inherits color j. The right terminal of G(u,) (which is also the left terminal of G(v,)) will be assigned the color k = 6 - i - j. (Note that 1 I k I 3 and k # i and k # j.) After all nodes of T have been visited, we obtain a 3-coloring for G. Figure 6 shows an example of this coloring procedure.

SERIES

PARALLEL

419

GRAPHS P U,2)

1 1 2

G

a(1

FIG. 6. An example of 3-coloring algorithm.

This coloring procedure can be translated to a top-down algebraic tree computation on T as follows. Define S = {(i, j)ll I i, j I 3 and i # j} and three functions on S as follows: (1) f&, j) = (i, j) for all (i, j> E S. (2) fl(i, j) = (i, 6 - i - j) for all (i, j> E S. (3) f&i, j) = (6 - i - j, j) for all (i, j) E S. For each node u of T, we compute a label L(U) = (i, j> E S with the meaning that the left terminal l(u) of G(u) is colored by i and the right terminal r(u) of G(u) is colored by j. These labels can be computed by the following algorithm. ALC~ORII-HM

3 (3-coloring).

Input. An SP graph G given by its decomposition tree T. Output. A 3-coloring of G. (1) Label the root r of T by L(r) = (1,2). Consider a node u of T with

left child ui and right child u2. If u is an s-node, label the edge e, = (ur, u) by F(el) = fi and the edge e2 = (uZ, u) by F(e,) = fi. If u is a p-node, label He,) = F(e,) = f,,. Label all edges of T in this way. Thus T becomes a top-down algebraic computation tree. (2) Perform the T-ATC on T, by calling the tree contraction algorithm, to compute a label for each node of T. The labels of the leaf nodes of T give a 3-coloring of G. End. It is easy to see that T-ATC performed on T simulates the coloring procedure described above. Since the size of T is O(n), step (1) takes O(log n) time with O(n/log n) processors. For step (2), observe that the

420

XIN HE

shunt operation involves the evaluation of an edge function and the composition of two edge functions. Since the domain set S of the edge functions consists of only six elements, each edge function can be represented by a 6-element vector. The evaluation and the composition of the edge functions can be done in O(1) time with one processor. So the shunt operation takes O(1) time with one processor and step (21 takes O(log n) time with O(n/log n> processors by Theorem 6. Hence we have: THEOREM 7. Let G be an SP graph with n vertices given by its decomposition tree. Then G can be j-colored in O(log n) time with O(n/log n) processors on a PRAM.

6. DEPTH-FIRST SPANNING TREE PROBLEM Let G = (V, E) be a connected undirected graph and let s be a vertex of G. Let H be a spanning tree of G rooted at s. (All edges of H are oriented towards the root.) H is called a depth-first spanning tree (DFST) if for any non-tree edge (u, v) of G either u is an ancestor of u or v is an ancestor of u in H [AHU]. The DFST problem for general graphs is an outstanding open problem in parallel algorithm design. In spite of extensive study, this problem is not known to be in NC [AgAn]. For planar graphs, the DFST problem can be solved in O(log’ n> time with O(n) processors [GSP, HY4]. In this section we present an optimal DFST algorithm for SP graphs. Let G be an SP graph and s be a vertex of G. We want to construct a DFST for G rooted at s. Let B,, B, . . . BI be the biconnected components of G. From the proof of Lemma 2, each Bi is an SP graph. Also by Lemma 2, the reduction tree RT of G is a path. Assume that B, - + * Bl appear in RT from the left to the right in this order. Suppose that s is a vertex of B, for some k. Let Ti (1 5 i I k - 1) be a DFST of Bi rooted at the right terminal of Bi. Let Ti (k + 1 I i I 0 be a DFST of Bi rooted at the left terminal of Bi. Let Tk be a DFST of B, rooted at the vertex s. It is easy to show that the union of Ti (1 < i I I> is a DFST of G rooted at s. Let (s, t> be an edge in Bk incident to the specified vertex s. Since Bk is biconnected, G is a TTSP graph with respect to s and t by Lemma l(b). This implies that we can make s the left terminal and t the right terminal of B,. Thus the construction of a DFST of G rooted at an arbitrary vertex s is reduced to the construction of the DFST I;: of Bi (1 I i I 0 rooted either at the left terminal or at the right terminal. Therefore, without loss of generality, we assume that the specified vertex s is the left terminal of G.

SERIES

PARALLEL

421

GRAPHS

Let G be an SP graph and T be its decomposition tree with root r. We assume the specified vertex s is the left terminal of G(r) = G. Define S = {(I, R),(r, L), (1, A), (r, A)}. We will compute, for each node u of T, a label L(u) c S with the following meaning: (a) If L(U) = (I, A), we construct a DFST T(u) in G(u) that is rooted at the left terminal of G(u) and includes all vertices in G(u). (b) If L(U) = (r, A), we construct a DFST T(u) in G(u) that is rooted at the right terminal of G(u) and includes all vertices in G(u). (c) If L(U) = (I, R), we construct a DFST T(u) in G(u) that is rooted at the left terminal of G(u) and includes all vertices in G(u) except the right terminal of G(u). (d) If L(U) = (r, L), we construct a DFST T(u) in G(u) that is rooted at the right terminal of G(u) and includes all vertices in G(u) except the left terminal of G(u). The label for the root r of T is L(r) = (1, A) since we want to construct a DFST for G(r) that is rooted at the left terminal of G(r) and includes all vertices in G(r). Consider a node u in T with left child u1 and right child ZJ~. The labels L(v,) and L(u,) will be determined from the label L(U) by the following rules: (1) If u (1.1) (1.2) (1.3) (1.4) (2) If u (2.1) (2.2) (2.3) (2.4)

is If If If If is If If If If

a p-node: J!,(U) = (1, R) L(u) = (I, L) L(u) = (I, A) L(U) = (r, A) an s-node: L(u) = (1, R) L(u) = (r, L) L(u) = (I, A) L(u) = (r, A)

then then then then

L(v,) ZAu,) L(v,) Uv,)

= (1, R) = (r, L) = (1, A) = (I, R)

akd and and and

L(u2) L(u,) L(v,) L(v,)

= (I, R). = (r, L). = (r, L). = (r, A).

then then then then

L(u,) Uv,) L(u,) L(v,)

= (I, A) and L(Q) = (1, R). = (r, L) and L(u,) = (r, A). = (I, A) and L(u,) = (I, A). = (r, A) and L(v,) = (r, A).

We will illustrate the correctness of rules (1.3) and (2.2). Other cases are similar. Case (1.3). Consider the graph shown in Fig. 7(l). In order to obtain a DFST T(u) for G(u) rooted at the left terminal a of G(u) that includes all vertices of G(u), we construct a DFST T(u,) for G(u,) rooted at the left terminal a that includes all vertices in G(u,), and a DFST T(u,) for G(v,) rooted at the right terminal 6 that includes all vertices of G(v,) except the left terminal a. The union of T(u,) and T(v,) is the required DFST T(u) for G(u).

422

XIN

a

b

(1)

HE

a

b

(2) FIG. 7. Construct depth-first spanning tree.

Case (2.2). Consider the graph shown in Fig. 7(2). In order to obtain a DFST T(u) for G(u) rooted at the right terminal b that includes all vertices of G(u) except the left terminal a, we construct a DFST T(v,) for G(v,) rooted at the right terminal c (which is also the left terminal of G(v,)) that includes all vertices of G(v,) except the left terminal a, and a DFST T(u,) for G(v,) rooted at the right terminal b that includes all vertices of G(u,). The union of T(u,) and T(v,) is the required DFST T(u) for G(u). After L(U) has been computed for all nodes U, a DFST H of G can be determined from the labels of the leaf nodes of T as follows. For each leaf node u let e(u) be the edge of G represented by U. If L(U) = (r, L) or (I, R), the edge e(u) is not included in H. If L(U) = (r, A), e(u) is included in H directed from the left to the right. If L(U) = (1, A), e(u) is included in H directed from the right to the left. It is easy to verify that H is a DFST of G(r) rooted at the left terminal of G(r). Figure 8 shows an example of this procedure. We next convert the above procedure to a T-ATC computation problem. Define four functions on S as follows: (3) (4) (5) (6)

fp’(r, f$, f,‘(l, f>(r,

A) A) R) L)

= (1, R) and f,‘(x) = x f or all other = (r, L) and f;(x) = x f or all other = (I, A) and f:(x) = x f or all other = (r, A) and f:(x) = x for all other

elements elements elements elements

x in S. x in S. x in S. x in S.

4 (DFST). Input. An SP graph G given by its decomposition tree T. Output. A depth-first spanning tree for G rooted at the left terminal G(r) = G. ALGORITHM

of

SERIES PARALLEL

+

: edges

-

: non-tree

GRAPHS

423

in DFST edges

b(r.‘-)

c(r,A)

G

T

FIG. 8. An example of depth-first spanning tree algorithm.

(1) Label the root r of T by L(r) = (I, A). Let u be a node of T with left child u1 and right child ut. If u is a p-node, label the edge e, = cur, u) by F(e,I = fi and the edge e2 = (uz, u) by F(e,) = f;. If u is an s-node, label He,) = f,’ and He,) = f,“. Label all edges of T in this way. Thus T becomes a top-down algebraic computation tree. (21 Perform the T-ATC on T by calling the tree contraction algorithm. A DFST of G can be constructed from the labels of the leaf nodes of T. End. The correctness of this algorithm follows from the above discussion. Its complexity analysis is similar to the 3-coloring algorithm. In summary we have: THEOREM 8. Let G be an SP graph given by its decomposition tree. A depth-first spanning tree of G can be constructed in O(log n> time with O(n/log n) processorson a PRAM.

7. BREADTH-FIRST

SPANNING

TREE

PROBLEM

The breadth-first spanning tree is a useful tool for solving many graph problems [AHU]. For general graphs this problem can be solved in O(log2 n) time with M(n) processors, where M(n) is the sequential time needed for multiplying two n X n matrices [GM]. The best known bound

424

XIN

HE

for M(n) is O(n2.376) [CW]. We present an O(log n log log n) time with O(n) processors parallel algorithm for this problem on SP graphs. We will solve a more general shortest distance spanning tree (SDST) problem. Let G = (V, E) be a connected undirected graph with a specified vertex s. Suppose each edge e of G is given a non-negative length length(e). For each vertex x let d(x) denote the shortest distance from x to s in G. For each vertex x there exists a vertex y such that d(x) = d(y) + length((x, y>>. Designate y as the parent of x. These parent pointers from an SDST H of G. (For any vertex x, the path in H from x to s is a shortest distance path from x to s.> If every edge of G has length 1, an SDST of G is a breadth-first spanning tree [AHU]. Let G be an SP graph and T be its decomposition tree with root node r. Let s be a vertex of G and we want to construct an SDST of G rooted at s. By the same argument made at the beginning of Section 6, we assume that, without loss of generality, the specified vertex s of G is the left terminal of G(r) = G. For each node u of T, define: (a) P(u) = the length of the shortest path in G(u) between its left terminal I(u) and its right terminal T(U). (b) X(u) = d(h)) - d(l(uN. Note that -P(u) I X(u) I P(u) for all nodes u of T. Our algorithm is divided into four stages. Stage 1 computes P(u) for all nodes u of T. Stage 2 computes X(u) for all u. Stage 3 computes d(l(u)) and d(h)) for all u. Stage 4 constructs an SDST for G. Stages 1,3, and 4 are simple. Stage 2 is more involved. 7.1. Compute

P(u)

This stage can be implemented by a B-ATC on T as follows. For each leaf node u of T let e(u) denote the edge represented by u. Assign u a label P(u) = length(e(u)). For each internal node u of T, if u is an s-node assign u a function F(u) = “ + .” If u is a p-node assign u a function F(u) =“min.” Assign all edges of T the identity function. Thus T becomes a bottom-up algebraic computation tree. It is easy to verify that after performing the B-ATC on T, the label P(u) is the shortest distance in G(u) between I(u) and r(u) for all nodes u. So this stage can be implemented by using the tree contraction algorithm. The internal nodes of T are labeled by the functions in {+, min). The edges of T are labeled by the functions of the form {a + min(b, x)la and b are real numbers). The shunt operation involves the evaluation and the composition of these functions. It is easy to see the shunt operation can be performed in O(1) time with one processor. Hence stage 1 can be implemented in O(log n) time with O(n/log n) processors by Theorem 6.

SERIES

PARALLEL

425

GRAPHS

b

FIG.

9. Construct shortest distance spanning tree.

7.2. Compute X(u)

X(u)% will be computed by the T-ATC on T. For the root I of T we have X(U) = d(r(r)) - &l(r)) = P(r) - 0 = P(r). Let u be a node of T with left child ui and right child u2. X(v,) and X(v,) are determined from X(U), P(u,), and P(Q) by the following rules: (1) If u is a p-node, then X(u,) = X(u,) = X(u). (2) If u is an s-node, then: (2.1) If X(u) < P(u,) - P(u,), then X(u,) If P(u,) - P(u,) I X(u), then X(u,) (2.2) If X(u) < P(ui) - P(u,), then X(u,) If Hu,) - P(u,) I X(U), then X(u,)

= X(u) + P(Q). = P(u,). = -P(u,). =X(u) - P(u,).

We next verify the correctness of these rules. For rule cl), since the left terminal and the right terminal of G(u) is also the left and the right terminal of G(u,) and G(u,), respectively, rule (1) is obviously correct. Suppose u is an s-node. Let u be the left terminal of G(u,) (= the left terminal of G(u)). Let b be the right terminal of G(u,) (= the right terminal of G(u)). Let c be the right terminal of G(u,) (= the left terminal of G(u,)) (Fig. 9). In the rule (2), the comparison of X(u) with P(u,) - P(u,) determines whether the shortest path to c is through a or through b. For rule (2.1) we distinguish between two cases. Case (i). X(u) < P(u,) - P(u,). Since d(b) - d(a) + P(u,> = X(u) + P(u,) < P(u,), we have d(b) + P(u,) < d(u) + P(u,>. So the shortest path from s to c is the concatenation of the shortest path from s to b and the shortest path in G(u,) from b to c. Thus d(c) = d(b) + P(u,) and X(u,)

= d(c) - d(u) = d(b) - d(u) + P(u,> = X(u) + P(u,).

Case (ii). P(u,) - P(u,) I X(u). Since d(b) - da) + P(u,) 2 P(u,), we have d(b) + P(u,) 2 d(u) + P(u,). path from s to c is the concatenation of the shortest path the shortest path in G(u,) from a to c. Therefore d(c) and X(u,) = d(c) - d(u) = P(u,>.

+ P(u,) = X(u)

So the shortest from s to a and = d(a) + P(u,)

426

XIN

For rule (2.21, we distinguish Case (iii). d(b) + P(v,)

HE

between two cases.

X(u) < P(o,> - P(u,>. As in Case (9 we have d(c) = and X(v,) = d(b) - d(c) = d(b) - d(b) - Z’(u,l =

- P(v,>. Case (iv). P(u,> - P(u,) I X(u). As in Case (ii> we have d(c) = d(a) + P(u,) and X(v,l = d(b) - d(c) = d(b) - d(a) - P(v,) = X(u) P(q).

In order to convert the above computation to the T-ATC problem, define the following functions on real numbers (where (Y and /? are arbitrary real numbers): (3) f,,(x) = x for all real numbers x. (4) f,‘“JQ(x> = x + p if x < LY- p; and f{“‘%> = (Y if x 2 (Y - p. (5) f2(oL,p)(x) = -p if x < cy - p; and fJ”,a)(x> =x - (Y if x 2 ff - p. Label the root r of T by X(r) = P(r). Let u be a node of T with left child u1 and right child u2 and let e, = (u,, u>, ez = (v,, u). Suppose P(u,> = cy and P(u,> = p. (These values have been computed in stage 1.1 If u is a p-node, label e, and e2 by the identity function fO. If u is an s-node, label ei by the function f[“‘@’ and e2 by the function fiaYB). Thus T becomes a top-down algebraic computation tree. It is easy to verify that after performing the T-ATC on T, X(u) = &r(u)) - d@(u)) for all nodes u. In order to use the tree contraction algorithm, we must implement the shunt operation. Unfortunately, the shunt operation cannot be performed in O(1) time by one processor in this case because of the structure of the edge functions of T. We will describe how to represent the edge functions so that the shunt operation can be implemented efficiently. The edges of T are associated with the functions in EF = {fica*p)li = 1,2 and (Y,/3 are real numbers}. Let A = {gi 0 g, 0 . . . 0 g,lfor some k 2 0 and g, E EF}. If a function g E A is a composition of k functions in EF, g is called a k-fold function. During the computation, the edges of T will be associated with the functions in A. The functions in EF are ‘non-decreasing piece-wise linear functions. Since a function g E A is a composition of the functions in EF, it can be shown by induction that g is also a non-decreasing piece-wise linear function. We will represent g by an interval representation, denoted by Z(g), as follows. Partition the domain set of g into ordered intervals {[a,, b,]. . .[a/, &I) (where a, = --m and b, = +a) such that the value of g on each [a,, bJ is a linear function hi. (Namely hi(x) = cix + di for some ci and dJ Define Z(g) = ([a,, b,, h,]. . . [a,, b,, h,]), where each hi

SERIES

PARALLEL

GRAPHS

427

is represented by its coefficients. By induction on k, it can be shown that if g is a k-fold function, Z(g) consists of at most k + 1 intervals. If we have k processors, the evaluation of a k-fold function g can be done in O(1) time by searching the intervals in Z(g). Let g, be a k-fold function and g, be an l-fold function and let g = g, 0 g,. The interval representation Z(g) can be obtained by merging the intervals in Z(g,) and Z(g,). If we have k + 1 processors, this can be done in O(log log(max(k, 1))) = O(log log n) time [BH]. (A similar idea was used in [HY3] for solving some tree problems. See [HY3] for a more detailed discussion.) We implement the tree contraction algorithm as follows. During the computation, each edge e of T is associated with a k-fold function F(e) E A for some k. F(e) is represented by its interval representation Z@(e)). During the computation if an edge e is associated with a k-fold function, k processors are assigned to e. This is done by using the following processor allocation scheme. Originally, each edge of T is associated with a one-fold function and is assigned one processor. Consider a node u of T with left child ur, right child v2 and parent w. Let e, = (vi, u), e2 = (v2, u), and e,, = (u, WI. Suppose that e2 is associated with a k-fold function and e, is associated with an I-fold function. We have k and 1 processors assigned to e2 and e,, respectively. Suppose vi is a leaf node and a shunt operation is performed on vi. In the resulting tree, the new edge e’ = (v2, w) will be associated with the composite function F(e,)o F(e,), which is a (k + &fold function. The processors that were assigned to e2 and e, are re-assigned to e’. Thus k + 1 processors are assigned to e’ and the computation of the interval representation Z(F(e’)) can be done by these processors in O(loglog n) time. Thus each iteration of the tree contraction algorithm takes O(loglog n) time with O(n) processors. Since the recursion depth of the algorithm is O(log n), Stage 2 takes 00og n log log n) time with O(n) processors in total.

7.3. Compute

d(x)

for the Vertices in G

This stage can be implemented by a T-ATC on T. We will compute, each node u of T, a label L.(U) = (i, j) such that i = dU(u)) and d(r(u)). The label for the root r is L(r) = (0, P(U)>. The label of other node is determined from its parent’s label. Consider a node u of T with left child vi and right child v2. e, = (vr, U> and e2 = (v2, u). If u is a p-node, the left terminal and right terminal of G(u) is also the left and the right terminal of G(v,) G(v,), respectively. Therefore L(v,) = L(v,) = L(u).

for j = any Let the and

428

XIN HE

Suppose u is an s-node. Let a be the left terminal of G(u,) (which is also the left terminal of G(u)) and b be the right terminal of G(u,) (which is also the right terminal of G(u)). Let c be the right terminal of G(u,) (which is also the left terminal of G(u,)) (Fig. 9). Since d(c) = (d(c) d(u)) + d(a) = X(u,> + d(u), we have L(u,) = (d(a), d(a) + X(u,I). Similarly, d(c) = d(b) - (d(b) - d(c)) = d(b) - X(r!,) and L(v,) = (d(b) X(v,>,d(b)). Note L(u,) and t(v,> only depend on X(u,l, X(v,>, and L(u) = (d(a), d(b)).

Using similar methods as in Sections 5 and 6, this computation can be converted to a T-ATC problem on T and implemented in O(log n> time with O(n/log n) processors. 7.4. Construct a Shortest Distance Spanning Tree

In order to construct a shortest distance spanning tree of G, we need to find, for each vertex x of G, a vertex y such that d(x) = d(y) + length((x, y>> and designate y as the parent of x. These parent pointers constitute a SDST of G. Suppose yi . . . yk are the neighbors of x in G. We assign k processors to x. Compute the sums d(yJ + I((x, yi)l (1 < i 5 k) and select a yi whose corresponding sums equals d(x). Perform this operation for all vertices x of G in parallel. This takes O(1) time with 2m = O(n) processors. This completes the description of the shortest distance spanning tree algorithm. In summary we have: THEOREM 9. Let G be an SP graph given by its decomposition tree. A shortest distance spanning tree (in particular a breadth-first spanning tree> can be constructed in O(log n log log n) time with O(n) processors on u

PRAM.

CONCLUSION

Efficient parallel algorithms for solving the recognition, 3-coloring, depth-first spanning tree, and breadth-first spanning tree problems for series parallel graphs are presented. The bottleneck is the recognition problem. If a more efficient algorithm for this problem can be found, the efficiency of the algorithms for the other three problems can also be improved. The latter three problems are solved by applying the tree contraction method to the decomposition trees of SP graphs. We believe the same idea can be used to solve many other important problems on SP graphs.

SERIES PARALLEL

GRAPHS

429

REFERENCES [ADKF’] K. An -SON, N. DADOUN, D. G. KIRKPATRICK AND T. PRZY-NCKA, A simple parallel tree contraction algorithm, J. Algotifhms 10, No. 2 (19891, 287-302. [&An] A. AGGARWAL AND R. ANDERSON, A random NC algorithm for depth first search, in “Proceedings, 19th ACM Symp. on Theory of Comput., 1987,” pp. 325-334. [AHU] A. V. AHO, J. E. HOPCROFT, AND J. D. ULLMAN, “The Design and Analysis of Computer Algorithms,” Addison-Wesley, Reading, MA, 1974. [BLW] M. W. BERN, E. L. LAWLER, AND A. L. WONG, Linear-time computation of optimal subgraphs of decomposable graphs, J. Algorithms 8, No. 2 (19871, 216-235. J. A. BONDY AND U. S. R. MURK, “Graph Theory with Applications,” North-HolEMI land, New York, 1980. Routing, merging, and sorting on parallel models [BHI A. BORODIN AND J. E. HOPCRO~, of computation, J. Compuf. System Sci. 30 (1985), 130-145. [CW] D. COPPERSMITH AND S. WINOGRAD, Matrix multiplication via arithmetic progressions, in “Proceedings, 19th ACM Symp. on Theory of Comput., 1987,” pp. l-7. R. J. DUFFIN, Topology of series parallel networks, 1. Math. Anal. Appf. 10 (1965), [Dul 303-318. [GM] H. GAZIT AND G. L. MILLER, An improved parallel algorithm that computes the BFS numbering of a directed graph, Inform. Process. Lett. 28, No. 2 (1988), 61-65. [GMT] H. GAZIT, G. L. MILLER, AND S.-H. TENG, Optimal tree contraction in an EREW model, in “Concurrent Computations: Algorithms: Architecture and Technology” (S. K. Tewkesbury, B. W. Dickinson, and S. C. Schwartz, Eds.) Plenum, New York, 1988. [GPS] A. GOLDBERG, S. PLOTKIN, AND G. SHANNON,Parallel symmetry-breaking in sparse graphs, in “Proceedings, 19th ACM Symp. on Theory of Comput., 1987,” pp. 315-324. R. HASSIN AND A. TAMIR, Efficient algorithms for optimization and selection on D-IT] series-parallel graphs, SIAMJ. Algebraic Discrete Methods 7, No. 3 (1986), 379-389. X. HE AND Y. YESHA, Parallel recognition and decomposition of two terminal series IHW parallel graphs, Inform. Compuf. 75, No. 1 (19871, 15-38. [HY2] X. HE AND Y. YESHA, Binary tree algebraic computation and parallel algorithms for simple graphs, J. Algorithms 9 (1988), 92-113. [HY3] X. HE AND Y. YESHA, Efficient parallel algorithms for r-dominating set and p-center problems on trees, Algorithmica 5 (1990), 129-145. [HY4] X. HE AND Y. YESHA, A nearly optimal parallel algorithm for constructing depth first spanning trees in planar graphs, SlAM J. Comput. 17, No. 1 (19881, 486-491. S. R. KOSAFNU AND A. L. DELCHER, Optimal parallel evaluation of tree-structured WI computation by ranking, in “VLSI Algorithms and Architectures, 3rd Aegean Workshop on Computing” (J. H. Reif, Ed.), pp. 101-110, Lecture Notes in Computer Science, Vol. 319, Springer-Verlag, New York, 1988. [MSV] Y. MAON, B. SCHIEBER, AND U. VISHKIN, Parallef ear decomposition search (EDS) and s-t numbering in graphs, Theoret. Comput. Sci. 47 (19861, 277-298. [MR] G. L. MILLER AND J. H. REIF, Parallel tree contraction and its applications, in “Proceedings, 26th IEEE Symp. on Foundations of Camp. Sci., 1985,” pp. 478-489. [TNS] K. TAKAMIZAWA, T. NISHIZEKI, AND N. SAITO, Linear time computability of combinatorial problems on series parallel graphs, J. Assoc. Comput. Mach. 29, No. 3 (1982), 623-641. R. TAIUAN AND U. VISHKIN, An efficient biconnectivity algorithm, SLAMJ. Comput. rrvl 14, No. 4 (19851, 862-874.

430 [Tsl [VTL]

XIN

HE

P. TSENG, Parallel computation for edge weighted network problems on series parallel graphs, Working paper #1240, Faculty of Commerce and Business Administration, The University of British Columbia. J. VALDES, R. TARJAN, AND E. L. LAWLER, The recognition of series parallel digraphs, SLlMJ. Comput. 11 (1982), 298-313.