Parallel algorithms for a class of graphs generated recursively

Parallel algorithms for a class of graphs generated recursively

Information Processing Letters 30 (1989) 225-231 North-Holland 13 March 1989 PARALLEL ALGORITHMS FOR A CLASS OF GRAPHS GENERATED RECURSIVELY Wojcie...

794KB Sizes 1 Downloads 79 Views

Information Processing Letters 30 (1989) 225-231 North-Holland

13 March 1989

PARALLEL ALGORITHMS FOR A CLASS OF GRAPHS GENERATED RECURSIVELY

Wojciech RY’ITER and Tomasz SZYMACHA Institute of Informatics, Warsaw University, Palac Kultury i Nauki, sk.poczt. 1210, 00-901 Watszawa, Poland

Communicated by W.M. Turski Received 22 February 1988 Revised 14 September 1988 and 14 October 1988

Keywords: Context-free graph grammars,parallel computations

1. Introduction

Context-free graph grammars (cfgg’s, for short) describe a class of graphs which admit polynomial time algorithms for some problems known to be NP-complete for general graphs. It was shown by Slisenko [12] and Kriauciukas [S]. In this paper we extend their results and we show that the graphs generated by cfgg’s are “easy” from the point of view of parallel computations. In the case of cfgg’s algorithmic techniques can be “borrowed” from the area of recognition and parsing of context-free languages, and computing recursive programs, see [7], [lo] and [ll]. The complexity of several problems for other classes of tree-like graphs were investigated in [2,4,&g]. Our model of parallel computations is PRAM (a parallel random access machine), see [l]. The main parallel instruction we use is the parallel do. It is of the form: for each x in S do in parallel action-depending-on x. NC’ is the clas of problems computable by our PRAM in log% time using a polynomial number of processors. The same type of cfgg’s as defined in [12] is considered. The graphs are undirected (though similar results can be obtained for grammars generating directed graphs). From the point of view of the number of processors (as well as degree of the polynomial expressing the sequential time complexity), the main parameter is the degree of generated graphs; for a given grammar it is bounded by a constant. This constant (or a multiple of it by some small number) will correspond to

the degree of polynomials representing the complexity. We use the terminology from [12]. A star graph is a pair (G, R),where G is a graph and R is the set of edges disjoint with the set of edges of G. We require that each edge of R has exactly one common node with G. The edges of R are called the “legs” of G. A simple star is a pair (5, R),where G is only one vertex. The nodes of G are labelled by terminal or nonterminal symbols. G is called the kernel of the star. The grammar is given by a set of productions of the form X --* Y, where X is a simple star with the kernel labelled by a nonterminal, and Y is a star with the same number of legs as X. T’Le axiom has no legs. (See Fig. 1.) If we have a graph with a subgraph X which is a simple star, then such a subgraph can be expanded. The kernel of X is replaced by the kernel of Y. Thle grammar generates a given graph if it can be derived from the initial star (a nonterminal with zero legs) using some number of the expansions defined above. For ease of the presentation assume that each star on the right-hand side of a production has at most two nodes labelled by a nonterminal. Such an assumption can be easily dropped and the complexity will be essentially the same. The problems still remain in NC. 2. Recognition and parsing problem

We have a fixed cfgg, and we have to decide if a given graph G can be generated by the grammar.

0020-0190/89/$3.50 8 1989, Elsevier Science Publishers B.V. (North-Holland)

225

13 March 1989

INFORMATION PROCESSING LE’ITERS

Volume 30, Number 5

ao-

->

8

;\ \;

1 -0a

a

t

I8

_t/

->

-e

i

\/OB

A

/ -ii\

->

--

ta

1

A

-o-o-

B

m-o-o-

b

Fig. 1. Productions of the grammar.

If so, then a parse tree is to be constructed. The size of our problem is the size n of the graph G. The grammar given in Fig. 1 and the graph in Fig. 2 illustrate the algorithms. Theorem 1. The problemr of the recognition and parsing for graphs generated by cfgg ‘s are in NC2.

Proof. The input is a graph with nodes labelled by terminals. Fist, we number the edges of G. This simple operation is crucial. It allows us to consider edge-labelled stars; the kernels of such stars can be thought of as subgraphs of G contracted to a single node. These subgraphs will be identified by a

19

a

14

Fig. 2. An example graph, which will be the input to the

parsing algorithm(constructed in the proof of Theorem 1). The graph is generatedby our grammar. 226

their legs because the legs correspond to concrete edges of G (they are labelled according to the original numbering of edges). If L is a set of edges (potential legs) then we can choose a set L’ oi endpoints of these edges (one per edge). Let X be a connected component of G - L containing all nodes of L’. If such a component exists then the star corresponding to the set E of legs with endpoints L’ (in the kernel) is X with ~\BJSL. The sizes of sets L are bounded by k = O(f). Hence there is a polynomial number of star subgraphs of G. The connected components algorithm (see [3]) can be d to construct all star subgraphs of G. On other hand, whenever we use productions o e grammar, the labels of legs should be temporarily disregarded (for this purpose the operation unlabel is introduced later). The whole structure of the algorithm is based on different representations of the same object-a subgraph whose connection to the rest of the graph is represented by a set of legs. The rules of the grammar will be applied in the reverse direction, to contract large kernels to single-element kernels (stars to simple stars). Let k be the maximum number of legs of graphs in productions of the grammar. We comset STARS(G) of all edge-labelled star ith at most k legs which are subgraphs of 6; we z-squire that the kernel of each such star be

Volume 30, Number 5

INFORMATION PROCESSING LE’ITERS

13 March 1989

4

2 -A

9

I

18

a

a

1 ao-o / 2 \.3

a8b12

1-m

78 b>

P

b

I 11 1S I \i6 :7 18

a -_ 8 10 b 13

/

18 e-0

6

ia

8\ 14

Fig. 3. Some star graphs whkh are elements of STARS (G) and some of their corresponding simple edge-labelled stars from the set N.

an induced connected subgraph. This set can be computed by an NC* algorithm using the parallel algorithm for connected components, see [3]. The legs are now labelled, as all other edges of G. The whole graph G with the empty set of legs (denoted by G*) is also an element of STARS(G). For each star S in STARS(G) and a nonterminal A define a simple edge-labelled star [S, A] to be the star with the same set of legs as S and the kernel consisting of one node labelled A. The interpretation of the pair [s, A] is: the subgraph S is contracted to a single-node graph (with some number of legs) labelled by a nonterminal A. Let N denote the set of such simple stars. These stars have legs labelled by the original numbers of edges of G. (See also Fig. 3.) Let unlabel[S, A ] be the simple star obtained by removing labels of legs in [S, A1. Hence unlabelIS, A] is a simple star with the kernel labelled A and with the number of legs the same as in [S, A]. We say that a simple star [S, A] Zs realizable iff the star S {possibly a very large subgraph of G) can be derived in our grammar from the simple star [S, A]. Observe that the graph G is generated by the grammar iff the simple star

[G*, A] is realizable, where A is an axiom of the grammar. Hence the problem of the recognition is reduced to the problem of computing all realizable simple stars. An algebraic approach of path systems (see [7]) is used. A path system is given by a Qtuple P ‘;=(N, 7’, GEN, s), where N is the set of elements of the system, T is a subset of N, its elements are called terminal elements, GEN is the generation function GEN: N U iV *N + 2’ and s is an element of N (called the goal, or source element). The system P is solvable iff s is generated from T using the operation GEN. We construct a path system P such that N is the set of all simple edge-labdled stars [S, A], s = [G #, A], where A is the axiom of the grammar, T is the set of all simple edgelabelled stars [S, A] such that the subgraph S of G with its unlabelled legs can be derived using 4

6 s -- t A) 8

8

7 20 -- t A@

12

/

13

a

Fig. 4. The set T of all terminal elements.

INFORMATION PROCESSING LElTERS

Volume 30, Number 5

s

/

10 E

-ill8

12 / -0 B‘\

GEN [

.‘*

E

(JZJ+j

13 18

1 ,

A 9t

Ei / -&1*

10

1

Fig. 5. The generation of the axiom (and the proof of G).

only one production from unlabel[S, A 1. The elements of T are of O(1) size. (See Fig. 4). The operation GEN is defined as follows: [S, A] is an element of GEN[Sl, B], [ S2, C]) iff there is a production whose left-hand side is a simple star unlabel IS, A] and right-hand side is unlabel[Y], where Y is a star graph obtained from S by replacing the subgraph Sl of S by B and the subgraph S2 of S by C. We allow also the unary version of GEN; the only difference is that Y is a star graph obtained from S by replacing a single subgraph Sl of S by B. In this case Y is in GEN([Sl, B]) (see. Fig. 5). It can be easily seen that the constructed path system P is solvable if and only if the graph G is generated by the grammar. It was proved in [7] (see also [ll]) that the set of realizable elements is computable by an “JC2 algorid if the generation tree of each realizable element is of polynomial size. This appIies here because all elements in the generation tree for a given element are distinct. Thus the recognition problem is in NC2. Once we compute all realizable elements, the parsing tree can be constructed in the same way as the parsing tree for context-free languages, see [lo]. This completes the proof. q 3. Parallel computations on graphs generated by cfgg%.

After the parsing phase we have a parse tree T of the input graph G. A small graph g, and a subgraph G, are

(see Fig. 6) of the decomposition

228

13 March lQ89

associated with each node v of the tree T. The graph g, corresponds to the production used. If the sons of v are vl, v2 then g, results from G,, by contracting its subgraphs G,, and GU2to onenode graphs (labellcd by nonterminals). We can view g, as a suucture of the decomposIlion of G, into its subgraphs GUI,G,,. An example of the tree T is presented in Fig. 6. The crucial point is that the relation between any subgraph GUand the rest of the graph is of a very restricted nature. Such a graph is connected with the outside part through a set of edges of size at most k. The constant k depends only on the grammar. Also the structure g, of the decomposition of G,, is of O(1) size. Theorem 2. The following problems are in NC1 if the parsing tree is given: (a) edge colouring; (b) vertex colouring; (c) hamiltonian cycle ; (d) traveling salesman problem; (e) maximal simple path; (f> vnaximal independent set; (g) minimal dominating set; (h) minimal vertex cover.

Observe that all these problems are NP-complete in general. Proof. (a) Let C be the set of colours, k (as

above) be the maximum number of legs of graphs in productions. For ease of the presentation assume that each star has the same number k of legs. We can add also k artificial legs to the axiom and to the input graph. Let G be the graph generated by cfgg, T be the parse tree obtain& by Theorem 1. With each node v of T associate a star graph G, and a simple s+ar g,. The k-aq relation f, GCk is computed for each node v. fU(cI, holds iff there exists a colouring of G, c2 , . . , ck) such that leg ei of Go has the colour ci for each i. The relation f, associated with the root r of T will be nonempty iff the graph is colourable with the given number of colours. Hence the edge colouring problem can be reduced to the computation of the relation f, for the root. We introduce here a parallel pebble game on binary trees (it can be easily extended to arbitrary trees). With each node v of the tree there is q

Volume 30, Number 5

INFORMATION PRCKZSSING LETTERS

13 March 1989

0

ao2;k v;r(”

g,:

Gl=G

0

a

:

I:

I

4

2 -0

6 b/ 7 \

5 B 18 B *o-

\

I

a5b12

b

-0

/ 10 a

5

4

6 --

4

ci : 2

A

5

G4:

Ib

a

10

8

fy-\z b

: I

8,=G5:

18

12

l3 12 ls/ -o-o-

18

B-

: i

1 b

y

12

Fig. 6. The parse tree Tof G (compare Fig. 5). Small graphs g,, and subgraphs G, are associated with each nude u.

associated a node denoted by cond(u). Initially cond( u) = u, for all v. During the game the pairs (u, cond( v)) can be thought of as additional edges. Another notion we shall require is that of “pebbling” a node. Pebbling a node denotes :!T fact that in the current state of the pebble game the processor associated with that node has sufficient information to evaluate this node. At the outset of the game only the leaves of the tree are pebbled. We say that a node u Zs“active” iff cond( u) z u. We also define the 2ku-y conditional relation

r, such that r,(c,, c2,. . . ) ck, dl, . . . , dk) holds iff there exists a good colouring of GU (with Gcond(,,) contracted to one node) such that (i) leg ei of GOhas the colour Ci for each i; (ii) leg e,! of Gcond(ujhas the colour di for each i; (we do not care whether the colouring can be properly extended for the subgraph Gcona(uj). Initially rU is a total relation for all u. The three oper3tions zqtivate, square and pebble are components of a !aove withi], the game and are defined as follows: 229

INFORMATION

Volume 30, Number 5

PROCESSING

activate

for etch nonleaf node v in in InuaMel do IJesin if exactly one of sons v is pebbled then cond(v) := unpebbled son; ib both sons v are pebbled then cond(v) becomes one of them arbitrarily; compute the relation r, end. {the computation of r, uses local information related only to gU and values CL”f for pebbled sons of v; observe that g, is of constant size} for each mde v in paralleldo beI@ cond( v) := cond(cond( v)); r~:= r~o bnd( u) 9 where 0 is the composition of the relations end pebble for each node v ln parallel do if cond(v) is pebbled then be&N pebble v and compute f, as a set of such (Cl, c2, 9 Cd that both fco~&&&, l

d 29 d 2,..., l

l

l

, 4) 4)

l

l

ad

r,(q,

c2,. . . , ck,

dl,

holds

end Algorithm

for eaclmleaf v in praralleldo compute f,; (Go is of constant size if v is a leaf) repeat log,(pt) times (activate,square, sqmre, pebble) end. It was provtd in [S] that the number of iterations is logarithmic. Since the operations are made in constant time, the algorithm requires 9(lcg2( n)) time. After that time the root r of T becomes pebbled. Hence the relation f, will be computed. This completes the proof of this l3oint. (b) We change only the interpretation of relatio;ls f, and rowThe colour ci will be associated with the vertex of G, incident to the leg ei. 230

LETTERS

13 March 1989

(c) The relation f, conttins the sets of pairs of legs {(ei, e(r), such that there exists a I-Iamiltonian path, that ( e, ) are entry points and { ei > are exit points in CU. The relation r,, contains these sets ot quadruples ((e,, e,!, di, dl)}, where { ei} and ( di 1 are entry points in G,, and Gcond(u)(contracted to one node) respectively and {e,!‘> and (dl } are exit points in G, and Gcondo respectively. (d) The proof is similar to (c). With each set {( ei, er )} we store the length of a Hamiltonian path entering the corresponding subgraph through { ei > and exiting through { e,!}. At the root we choose the shortest one. (c) Similar as for (c). (f) With each subgraph GU we consider characteristic vectors of size k; ith element is zero if the endpoint of the ith leg (in Go) is in the independent set. For each node v we compute the function f, such that fv(x) is the size of the maxima; independent set in G with endpoints of legs contained in this set according t., the characteristic vector x. In this case ru is the conditional function such that r,(x,, x2 j is the size of the maximal independent set in G, assuming that the vector x2 represents the endpoints (in GCond~U~) of the legs Of GCond(+ (g) The set X is dominating iff every node is in X or has a neighbour in X. With each endpoint of a leg we can associate a piece of information: O-the node is in a set, l-the node itself is not in the dominating set but has a neighlbour in X, 2-the node is not of a previous type. For each node v of the parse tree T we compute all combinations of values 0,l or 2 realizable for legs of the subgraph GU. Then the computations associated with the moves of the parallel pebble game can be defined similarly as before. (h) Similar as for (f). This completes the proofn

Remark. If a class Kl of graphs is a subclass of a class K generated by a cfgg then all problems considered have also NC algorithms for graphs in Kl. For example the class of Hahn graphs [4] with bounded degree can be KP in this sense.

Volume 30, Number 5

INFORMATION PROCESSLNG LFTTERS

References M S. Fortune and J. Wyllie, Parallelism Z.nrandom access machines, 10th ACM Symp. Theory of Computing, 1978, pp. 114-118. VI A. Ir3ibbons and W. Rytter, Fast parallel algorithms for edge colouring of some tree structured graphs, in: L. Budach, Ed., Fundamentals of Computation Theory, kture Notes Comput. Sci., Vol. 278 (Springer, Berlin, 1987) 101. -109. [31 A. Gibbons and W. Rytter, Efficient Parallel Algorithms (Cambridge University Press, Cambridge, 1988). PI A. Gibbons, A. Israeli and 0:. ?_ytter, Parallel G(log n) time edge colouring trees and I-lalin graphs, Inform Process L.&t. 27 (1988) 43-51.

PI V. Kriauciukas, Tree-like parse and polynomial subclasses of search problems, Inform Process Lett. 22 (1986) 49-54. 161 T. Lengauer and K. Wagner, The corelation between the complexities of the nonhierarchical and hierarchical versions of graph problems, Proc. STACS ‘87.

13 -March 1989

PI W. Rytter, The complexity of two-way pushdown auto::%ta and recursive programs in: A. Apostolic0 and 2. Galil, Eds., Combinatorial Algorithms on Words, NATO AS1 Series F:12 (Springer, Berlin, 198Sj [81 W. Rytter, Remarks on pebble games on graphs. presented at the conference Combinatorial analysis and its applications, Zusgos. Mat. (1985) to appear. PI W. Rytter, Gn efficient parallel computations for some dynamic progr amming problems, Ilteor. Compu:. Sci. 59 (3) (1!.38) 297-307. 001 W Fvtter, Gn the parallel parsing of general contex? free Iangtiges, Theor. Comput. Sci. 47 (1986) 315-321. t111 W. Rytter, Parallel time G(log n) recognition of unam-

biguous context free languages, Infomi. Cam$u?. 75 (1) (1987) 75-86. [121 A. Slisenko, Context-free grammars = a tool fo, describing polynomial time subclasses of hard problems, Inform. Process. I&t. 14 (2) (1982) 52-57.

231