Subtree isomorphism is NC reducible to bipartite perfect matching

Subtree isomorphism is NC reducible to bipartite perfect matching

Information Processing Letters 30 (1989) 27-32 North-Holland 16 January 1989 SUBTREE ISOMORPHISM IS NC REDUCIBLE TO BIPARTITE PERFECT MATCHING Andrz...

843KB Sizes 0 Downloads 41 Views

Information Processing Letters 30 (1989) 27-32 North-Holland

16 January 1989

SUBTREE ISOMORPHISM IS NC REDUCIBLE TO BIPARTITE PERFECT MATCHING Andrzej LINGAS Department of Computer and Information Science, Linkiiping University, 581 83 Linkiiping. Sweden

Mar& ICARPINSICI Department of Computer Science, Bonn University, 5300 Bonn 1, Fed Rep. Germany

Communicated by T. Lengauer Received 3 December 1987 Revised 1 July 1988

A simple NC reduction of the problem of subtree isomorphism to that of bipartite perfect matching is presented. The reduction impl’as the msnbership of the subtree isomorphism problem in random NC3,

Keyword:

Subgwph isomorphism, tree, bipartite graph, perfat matching, parallel random access machine, NC-reducibility

1. Intrthhwtion The subtree isomorphism problem is to decide whether a tree is isomorphic to a subgraph of another tree. Analogously, we define the version of the problem for directed trees. The subtree isomorphism problem is one of the two known restrictions of the general subgraph isomorphism problem to a nontrivial graph family that are sequentially solvable in polynomial time [3]. The other example is the subgraph isomorphism problem for biconnected outerplanar graphs [7]. The subtree isomorphism problem can be solved in the undirected and directed’ case by a recursive reduction to the maximum bipartite matching problem in time 0(n2*‘) [11,14]. Remembering that the latter problem is in random NC [6,12], it is natural to ask whether such a reduction can be performed by a fast parallel algorithm using a polynomial number of processors. The recursive depth of the reduction in the sequential algorithms of Matula and Reynolds [11,14] is unfortunately proportional to the height of the input trees. To obtain an NC reduction, we need to cut the input trees recursively in order to

decrease their height. A straightforward way of cutting by using a vertex “$- 3” separator [lo] in the first tree and guessing its image in the second tree can lead to an unpolynomial number of considered components of the second tree. The main result of the paper is a simple, deterministic NC reduction of subtree isomorphism to bipartite perfect matching. The reduction uses a irec-cutting technique relying on the three following observations. (1) In any isomorphism @ between a rooted tree T and a subtree of another rooted tree U that maps the root of T onto the root of U, the path PI from a given vertex separator v to the root of 2’ is mapped onto the path P2 from +(v) to the root of I!. (2) For i = O,.. ., Cength(PI), each full subtree of T rooted at a son of the ith vertex of P1 not lying on P1 is mapped (by +) into a unique full subtree of U rooted at a son of the i th vertex of P2 not lying on P2. To assign the latter subtrees to the former ones uniquely, we can use a bipartite matching technique analogous to that used in the sequential algorithms for subtree isomorphism [ll, 141.

002O-0190/89/$3.50 0 1989, Elsevier Science Publishers B.V. (North-Holland)

27

Volume 30, Number 1

INFORMATION PROCESSING LETTERS

If we cut T and U by respectively removing the path Pi and & with the adjacent edges, then the resulting subtrees are full subtrees of T and U respectivdy rooted at the sons of vertices on the paths that themselves do not lie on the paths. By the third observation and a straight-forward inductive argumentation, if we apply our tree cutting method recursively then the number of resulting components is not greater than the total number of full subtrees of the rooted trees T and U (the latter zumber is equal to the number of vertices in T and U). Since the problem of subtree isomorphism is easily reducible to that for rooted trees, we obtain an NC3 reduction of subtree isomorphism to maximum bipartite matching, and hence, to bipartite perfect matching. Next, since the general perfect matching problem is in random NC2 [12], we can conclude that the subtree isomorphism problem is in random NC3. Actually, we show that the latter problem is solvable in time O(log3n) in the model of probabilistic CREW PRAM (Theorem 3.3) and argue that our randomized PRAM method can be also implemented by probabilistic NC3 circuits. The above results have recently been confirmed in [4] where an indenendent and different proof technique is used. Interestingly, a reverse reduction can be done by NC’ circuits using straightforward coding (see [8]). By these NC reductions, the intriguing problem of the membership of bipartite perfect matching [6] in NC is equivalent to that of the membership of subtree isomorphism in NC. (3)

2. PreRminaries We shall adhere to a standard graph and set notation (see [1,5]). Specifically, given a set S, the term 1S 1 will stand for the cardinality of ,s. Given a tree T, we shall often denote its set of vertices by T also. If T Is a rooted tree and v is a vertex of T, then the term Tu will denote the full (i.e., largest) subtree of T rooted at v. By a vertex separator of a tree T, we shall mean a vertex v of T whose removal disconnects T into subtrees, none of which has more than two-thirds of the vertices of T. Recall that any tree has at least one 28

16 January 1989

vertex separator [lo]. For the definitions of parallel random access machines, uniform circuit families, the classes NCk, NC, their rddorn versions RNCk, RNC and the corresponding notions of reducibility, the reader is referred to [2,13,15,17]. The NC reduction of the problem of subtree isomorphism to that of bipartite perfect matching will be shown by proving an NC reduction for simple modifications of these two problems. In this section, we shall define the modifications and observe appropriate NC reductions between them and the original problems. The modification of the subtree isomorphism problem will be called the root subtree isomorphism problem. 2.1. Definition. The root subtree isomorphism problem is to decide whether there exists an isomorphism between a rooted tree and a subgraph of another rooted tree mapping the root of the first tree on the root of the second tree. Such an isomorphism will be called a root imbedding . of the first tree in the other one. 2.2. Lemma. The subtree isomorphism problem for undirected trees as we!1as that for directed trees can be reduced to O(n) root subtree isomorphismproblems in time O(log n) by a CREW PRAM with O( n2) processors. Consequently, the two former problems are NC2 reducible to the latter. Proof. Let T and U be the input trees. First, suppose that they are directed. Then T is isomorphic to a subgraph of U if and only if there is a vertex v of U and a root imbedding of T in the full subtree of U rooted at v. In parallel, for each vertex v of U, we construct the subtree rooted at v, in order to test T with the subtree for root imbedding. If T and U are undirected, we root T at an arbitrary vertex. Clearly, T is isomorphic to a subgraph of U if and only if there is a vertex u of U and a root imbedding of the rooted tree T in U rooted at v. Therefore, for each vertex v of U, we root U at v in order to test the rooted tree T with the so rooted U for root imbedding. To construct the full subtree rooted at v in the directed case or to root U at a given vertex in the undirected case, we can use the so-called Euler

Volume 30, rhmber 1

INFORMATION PROCESSING LEITERS

tour technique [18]. It takes O(log n) time using O(n) processors and O(n) space on an exclusiveread exclusive-write parallel random-access machine (EREW PRAM, for short) [18]. It should be clear now that in both cases, the simple many-one reductions can be done by a concurrent-read exclusive-write PRAM (CREW PRAM for short) using O(n*) processors in time O(log n). 0 The modification of the bipartite perfect matching problem will be called the bipartite partly perfect matching problem. 2.3. Definition. Given a bipartite graph G(&, V1, a partly perfect matching of G is a matching of G whose cardinality is eqlual to min( ] V1 1, ] 5 ] >. The bipartite partly perfect matching problem is to decide whether a bipartite graph has a partly perfect matching.

E),

By using dummy vertices, we obtain the following straightforward lemma. 2.4. Lemma. Theproblem of bipartite partly perfect matchkg can be reduced to that of bipartite perfect matching in time O(log n) by an ERE W PRAM with n processors. 3. Sukze isomorphism is NC3 reducible to bipartite perfect matching In this section, we shall show that the problem of root subtree isomorphism can be reduced to that of bipartite partly perfect matching in time O(log*n) by a CREW PRAM with 0(n5) processors. By Lemmas 2.2, 2.4 and [17], this yields an NC3 reduction of subtree isomorphism to bipartite perfect matching. The three observations in the introduction present the idea of the main, recursive, reduction procedure RSI. The procedure uses some preprocessing, and is defined as follows: input: two rooted trees T and U and, for every vertex t of T, the number D(t) of descendants of t in T; output: if there is a root imbedding of T in U then 1 else 0;

16 January 1989

data structures: a matrix M( t, u ), t E TV u E u, the entry M( t, u) to 1 (respectively 0) ~3 denote that there is a (respectively, there is no) root imbedding of T in VU. setting

procedure RSI(T, U, D) distribute the value of I T 1 to all vertices of T; select a vertex separator u of T; find the path PI from u to the root of T and its length I 4 I ; for i=O,..., I PI I do in parallel Ui+ the i th vertex of PI; for all vertices u of U do in parallel begin find the path P2 from u to the root of U and its length I P2 ] ; if lP1l = lP21 then begin for i=O,..., i PI I do in parallel begin Ui+ the ith vertex of P2; if Vi has more sons than ui then begin YES(i) + 0; goto A end; for all pairs ( sl, s2) where s1 is a son of Ui not lying on PI and s2 is a son of Ui not lying on P2 do in parallel M( st, s2) + RWT,,, Us,, D/T,,); G,(M) + the bipartite graph indu& by the matrix M restricted to the sons of Vi and Ui not lying on PI mii P2 respectively (i.e., sons sl, s2 are adjacent in G,(M) iff M(s,, ~2) = 1); YES(i) + if Gi( M) has a partly perfect matching then 1 else 0; A: end; lPll YES(i) then 1 else 0 YES(U) + if Aiend; else YES(u) + 0; end if V UEUYES(u) then return 1 else return 0 The correctness of the procedure RSI(T, U D) immediately follows from the fact that in any root imbedding Q,of T in U, the path PI in T from the 29

Volume 30, Number 1

INFORMATION PROCESSING LE’ITERS

to the root of T is mapped on the path P2 from +(v) to the root of U, and that, for i=O,..., ]P1 1, each full subtree of T rooted at a son of the ith vertex of Pr not lying on PI is root-imbedded into a unique full subtree of U rooted at a son of the ith vertex of P2 not lying on vertex separator

p2-

v

may assume 1T 1 Q 1U J without loss of generality. Let n denote 1U I. TO show that RSl(T, U, D) CLIJbe efficiently reduced to a col&ion of bipartite partly perfect matching tests in the CREW PRAM model, we argue as follows. (a) The distribution of the value 1T I to the vertices of T can be done in time O(l) by a CREW PRAM with n processors. Then we can decide, for each vertex t of T, whether s is a vertex separator of T by computing I T I -D(t) and the maximum of D(s) over the sons s of the vertex t in T. Clearly, it can be done in time O(log n) by a CREW PRAM with O(n2) processors. Finally, we can select a vertex v from these vertex separators in time O(log n) using a CREW PRAM with n processors. (b) The path Pr , and similarly, the path P2, can be found by using a standard O(log n)-time method on a CREW PRAM with O(n2) processors. In the jth iteration of the method we find, for each vertex v in the tree, the path from v to its ancestor in the distance 2i by concatenating the path from v to its ancestor in the distance 2”’ with the copied path between the two above ancestors uf v. (c) For given paths PI and P2, the total number of son pairs (sl, s2) over all i = 0, 1,. . . , 1PI 1 is not greater than the product of I T I and IU I which is at most n2. (d) Tke are O(n) paths PZ constructed in parallel for the unique path P, by RSI. Therefore, by (a), (b) and (c) the body of RSI(T, U, D) can be implemented in time O(log n) by a CREW PRAM with0(rt3) processors if we do not count the recursive calls and bipartite partly perfect matching tests. (e) The recursive depth of RSZ(T, U, D) is O(log 19). (f) Note that the subtrees Ts, and U$ are full subtrees of 7’ and U respectively. Hence, by induction, all 1the subtrees occurring in the recursive We

30

16 January1989

calls of RSI(T, U, D) are also full subtrees of T and U respectively, and the original values of the matrix D can be used there. It follows that the procedure AS&T, T, D) invokes at most IU I IT I

different recursive calls. Hence, the whole procedure can be implemented by filling the entries of the matrix M in a bottom-up manner. By (d), (e), this can be done in time 0(!og2n) by a CREW PRAM with 0(n5) processors if we do not count the cost of the matching tests. (g) For a given path P2, the total size of the matching tests directly applied in the body of RSI(T, T, D) is clearly O(n). Thus, there are O(n) groups of the matching tests, each group of total size O(n), that are directly applied in the body of RSZ. Hence, by (f), the whole procedure RSd(T, T, D) invokes in total 0( n3) groups of matching tests, each group of total size O(n). To estimate the CREW PRAM complexity of the whole reduction, it remains to estimate the cost of preprocessing. We can find, for each vertex t of T, the total number D(t) of descendants of t by using again the Euler tour technique [18]. In result, the preprocessing can be done in time O(log n) using a CREW PRAM with O(n) processors [18]. Thus, the whole reduction can be done in time 0(log2n) by a CREW PRAM with O(n*) processors. Our anaiysis yields the following theorem. 3.1. Theorem An instance of the problem of root subtree isomorphism can be reduced to 0( n3) groups of instances of the problem of bipartite partly perjcct matching, each group of total size O(n), in time O(log2n) by a CREW PRAM with O(n’) processors. Combining Theorem 3.1 with Lemma 2.2 and Lemma 2.4, we obtain the first main theorem. 3.2. Theorem. An instance oj the probiem of subtree isomorphism or the problem of directed subtree isomorphism can be reduced to 0(n4) groups of instances of the problem of bipartite perfect matching, each group of total size O(n ), in time O(log2n) by a CRk3p PRAM with O(n6) processors. Hence, the formmerproblems are NC3 reducible to the latter.

Volume 30, Number 1

INFORMATION PROCESSING LETTERS

Proof. The first part immediately

results from Lemmas 2.2, 2.4 and Theorem 3.1. It follows by [17] that the whole reduction can be implemented by (uniform) circuits of unbounded fan-m, O(log*n) depth and polynomial size. I-Ience, it can be implemented by NC3 circuits with oracle gates (see [2]) for the mztching tests. q We can solve the perfect matching problem for a graph with n vertices and m edges in time O(log*n) using a probabilistic CREW PRAM with O@~~*~rn)processors [12]. Combining the above fact with Theorem 3.2, we obtain the second main theorem. 3.3. Theorem. The problem of subtree isomorphism and that of directed subtree isomorphism can be solved in time O(log3n) in the model of probabilistic CREW PRAM with no(‘) processors. The twoproblems are in random NC3. Proof. We compose our reduction of the subtree isomorphism problems to collections of bipartite perfect matching problems with the randomized algorithm for bipartite perfect matching from [22]. By Theorem 3.2 and the processor bound for the algorithm from [12], the composed algoritlm requires 0(n9-‘) processors. Recall the complexity analysis of the procedure RSI. Now, ti we count the cost of the matching tests and not count the costs of the recursive calls, the body of RSI can be implemented in time O(log*n). Since there are O(log n) recursion levels, the whole procedure runs in tiune 0(log3n), in the probabilistic CREW PRAM model. To show that the two subtree isomorphism problems are in random NC3, we use a similar argument. By Theorem 3.2, the reduction of any of these two problems to a collection of bipartite perfect matching tests can be done by NC3 circuits. These circuits can be so constructed that the oracle gates for the matching tests occur only on O(log n) different levels. On the other hand, the bipartite perfect matching problem is in random NC* [12]. Therefore, we can replace each of the above oracle gates by an appropriate, probabilistic KC’ circuit in order to obtain probabilistic NC3 circuits for the subtree isomorphism problems. 0

16 January 1989

4. Final remarks (1) BY slightly modifying the proof of the NC reductions presented in Sections 2 and 3, we could aho obtain the corresponding NC reduction between the problem of constructing a subtree isomorphism and that of constructing a bipartite perfect matching. (2) Since the problem of constructing a perfect matching in a graph is solvable by a Las Vegas NC algorithm, i.e., a parallel algorithm running a polylog expected time, giving always a correct answer (see 16, Section 4]), the subtree isomorphism problem is also solvable by a Las Vegas NC algorithm by Theorem 3.2. (3) The main contribution of the paper is the new tree cutting technique used in the NC reduction of subtree isomorphism to bipartite perfect matching. Recently, Lmgas and Proskurowski have combined an analogous technique with the ideas from [7] to show that the subgraph isomorphism for bicormected ourierplanar graphs is in NC 191. (4) In [15], Ruzzo observes that the restriction of the subtree isomorphism problem to trees of valence O(log n) can be solved by an auxiliary nondeterministic PDA operating within O(log n) working space and polynomially-bounded pushdown store. Since such an automaton can be simulated by NC circuits 1151, Ruzzo concludes th;t the restriction of subtree isomorphism is in NC. Combining Ruzzo’s observation with the fact that a depth-first search of a tree can be performed by NC circuits 1161,we can easily conclude that the restriction of subtree isomorphism where only the first tree is required to be of valence O(log n ), is also in NC (see [8]). We can also observe that Ruzzo’s method yields the membership of the problem of subtree isomorphism for ordered trees and the problem of deciding whether a term is a subterm of another term in NC* [8].

Acknowledgment

We would like to thank Christos Levcopoulos for a valuable discussion. 31

Vohune 30, Number 1

INFORMATION PROCESSING LETTERS

References 111I A.V. Aho, J.E. Hopcroft and J.D. Uhman, The Design and Anaiysis of Computer Algorithms (Addison-Wesley, Reading MA, 1974). PI I S.A. Cook, The taxonomy of problems with fast paraBe algorithms, Inform, and Control 64 (1985) 2-22. [31I MR. Garey and D.S. Johnson, Computers and Intractability. A Guide to the Theory of NP-completeness (Freeman, San Francisco, 1979). 141I P.B. Gibbons, RM. Rarp, G.L. Miller and D. Soroker, Subtree isomorphism is in random NC, Manuscript, September 1987. I PI F. Harary, Graph Theoqv (Addison-Wesley, Reading, MA, 1969). 161I R.M. Karp, E. UpfaI and A. Wigderson, Constructing a maximum matching is in random NC, In: Proc. 17th Symp. on Theory of Computing (1985) 32-31.

171I A. L&as, Subgraph isomorphism for biconneeted outerplanar graphs in cubic time, In: Proc. 3rd Symp. on Theoretical Aspects of Computer Science (1986) Lecture Notes in Computer Science, Vol. 210 (Springer, Berlin, 1986). PI A. Lingas and M. Karpinski, Subtree isomorphism and biptite perfect matching are mutually NC reducible, Tech. Rept. 8S6-CS, December 1986, Bonn University. PI A. Lmgas and A. Proskurowski, Fast parallel algorithms for the subgraph homeomorphism and the subgraph iso-

32

16 January 1989

morphism problems for classes of planar graphs, In: Proc. 7th Conf on Foundations of Software Technology and Theoretical Computer Science, Puna, India (1987).

[lo] R.J. Lipton and R.E. Tarjan, A separator theorem for planar graphs, SIAM J. Appl. Math. 36 (1979) 177-189. [ll] D.W. Matda, Subtree isomorphism in O(&*), Ann. Discrete Math. 2 (1978) 91-106. [12] K. Mulmuley, U.V. Vazirani and V.V. Vazirani, Matching is as easy as matrix inversion, Combinatorics 7 (1) (1987) 345-354. [13] N. Pippenger, On simultaneous resource bounds, In: Proc. 20th IEEE Conf on Fundamentals of Computer Science,

pp. 307-311. [14] S.W. Reyner, An analysis of a good algorithm for the subtree problem, SIAM J. Comput. 6 (1977) 730-732. [lS] W.L. Ruzzo, Qn uniform circuit complexity, J. Comput. System Sci. 22 (1981) 365-383. [16] J.R. Smith, Parallel algorithms for depth first searches: 1. Planar graphs, SIAM J. Compact., to appear. [17] L. Stockmeyer and U. Vi&kin, Simulation of parallel random access machines by circuits, SIAM J. Comput. 13 (1984) 409-422. [18] R.E. Tarjan and U. Vishkin, Finding bi-connected components and computing tree functions in logairhmic parallel time, In: Proc. 25th IEEE Conf on Fundamentals of Computer Science (1984) 12-20.