Efficient Parallel Shortest-Paths in Digraphs with a Separator Decomposition

Efficient Parallel Shortest-Paths in Digraphs with a Separator Decomposition

JOURNAL OF ALGORITHMS ARTICLE NO. 21, 331]357 Ž1996. 0048 Efficient Parallel Shortest-Paths in Digraphs with a Separator Decomposition Edith CohenU...

NAN Sizes 0 Downloads 201 Views

JOURNAL OF ALGORITHMS ARTICLE NO.

21, 331]357 Ž1996.

0048

Efficient Parallel Shortest-Paths in Digraphs with a Separator Decomposition Edith CohenU AT & T Bell Laboratories, Murray Hill, New Jersey 07974 Received July 21, 1993

We consider 1 shortest-paths and reachability problems on directed graphs with real-valued edge weights. For sparser graphs, the known N C algorithms for these problems perform much more work than their sequential counterparts. In this paper we present efficient parallel algorithms for families of graphs, where a separator decomposition either is provided with the input or is easily obtainable. ŽA separator is a subset of the vertices that its removal splits the graph into connected components, such that the number of vertices in each component is at most a fixed fraction of the number of vertices in the graph. A separator decomposition is a recursive decomposition of the graph using separators.. Let G s Ž V, E ., where n s < V <, be a weighted directed graph with a k m-separator decomposition Žwhere subgraphs with k vertices have separators of size O Ž k m ... We present an N C algorithm that computes shortest-paths from s sources to all ˜Ž n3 m q sŽ n q n2 m .. work. A sequential version of our other vertices using O algorithm improves over previously known time bounds as well. Reachability from ˜Ž M Ž n m . q sŽ n q n2 m .. work, where M Ž r . s s sources can be computed using O 2.37 . is the best known work bound for r = r matrix multiplication. The oŽ r ˜Ž n2 m . edges such that in the algorithm is based on augmenting G with a set of O augmented graph, all distances can be obtained by paths of size O Žlog n.. The above bounds, with m s 0.5, are applicable to planar graphs, since a k 0.5 -separator decomposition can be computed within these bounds. We obtain further improvements for graphs with planar embeddings where all vertices lie on a small number Q 1996 Academic Press, Inc. of faces.

1. INTRODUCTION The reachability problem on a directed graph G s Ž V, E . is to determine, for a specified source vertex ¨ g V, all vertices reachable from ¨ in * E-mail: [email protected]. 1 An extended abstract appeared in ‘‘Proceedings 5th Annual ACM Symposium on Parallel Algorithms and Architectures, 1993. 331 0196-6774r96 $18.00 Copyright Q 1996 by Academic Press, Inc. All rights of reproduction in any form reserved.

332

EDITH COHEN

G. When real-valued edge weights w: E ª R are associated with the edges, the single-source shortest-paths problem is to determine directed paths of minimum weight from ¨ to all other vertices, where the weight of a path is defined to be the sum of the weights of the edges on the path. Let ˜Ž f . ' OŽ f polylog f .. Alm s < E < and n s < V <. We use the notation O though the reachability and shortest-path problems from s sources can be ˜Ž ms . time Ž O˜Ž mn. time if negative weights are solved sequentially in O ˜Ž n3 . work and allowed., the best N C algorithms for shortest-paths use O 2.37 . Ž ˜ Ž Ž .. Ž . Ž for reachability O M n work, where M r s o r see Coppersmith and Winograd w2x. is the best known work bound for r = r matrix multiplication. Hence, when m g n2 or s g n, the parallel algorithms perform considerably more work. This reality is referred to in the literature as the ‘‘transitive closure bottleneck.’’ In this paper we present efficient N C algorithms that overcome this bottleneck for families of graphs that have a recursive decomposition using small separators. Our Results. A separator of a graph G s Ž V, E . is a subset of vertices S ; V such that the subgraph induced by V R S is not connected. It is typically required that the number of vertices in each connected component is at most a fixed fraction of the number of vertices in the graph. For a function f : N ª R, an f Ž k .-separator decomposition of G is, roughly, a recursive decomposition of G using separators, where subgraphs of size k have separators of size O Ž f Ž k ... Consider a directed graph G s Ž V, E . with weights w: E ª R and a k m-separator decomposition of G. We present an algorithm that finds minimum weight paths from s sources by first performing a preprocessing step in O Žlog 2 n. time and O ŽŽ n q n3 m .log n. work, if m / 1r3, or O Ž n log 2 n. work, if m s 1r3. After the preprocessing, the algorithm takes O Žlog 2 n. time and uses O Ž sŽ n q n2 m .. work, if m / 1r2, or O Ž sn log n. work, if m s 1r2. An alternative algorithm performs the preprocessing stages in O Žlog 3 n. time using O Ž n q n3 m . work if m / 1r3 and O Ž n log n. work otherwise. See Table 1 for a summary. For graph reachability, the preprocessing can be done using

TABLE 1 Shortest Paths in Graphs with k m-Separators Time

Preprocessing work 3m .

log n

m / 1r3 Ž n q n m s 1r3 n log 2 n

log 3 n

m / 1r3 m s 1r3

2

n q n3 m n log n

log n

Work per source

m s 1r2 m / 1r2

n log n n q n2 m

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

333

O ŽŽ n q M Ž n m ..log 2 n. work if vm / 1 and O Ž n log 3 n. otherwise, where v is the matrix multiplication exponent M Ž r . s O Ž r v .. The parallel bounds discussed in this paper are on the EREW PRAM model unless explicitly stated otherwise. An example of a family of graphs with a readily available separator decomposition is dX-dimensional grid graphs, where d F dX dimensions have more than a constant width. For these graphs there is a trivial k Ž dy1.r d-separator decomposition. Other examples are bounded tree-width graphs with a tree decomposition Žsee, e.g., Robertson and Seymour w19x. and r-overlap graphs, proposed by Miller et al. w15x. Miller et al. had shown that r-overlap graphs embedded in d dimensions have a separator bound of O Ž r 1r d nŽ dy1.r d . and these separators can be computed by a randomized algorithm in polylogarithmic time using linear work. r-Overlap graphs constitute an important family of graphs that in two dimensions includes the class of planar graphs, and in d dimensions includes all subgraphs of the d-dimensional grid. We comment that sequential versions of our algorithms are an improvement over previous sequential algorithms. For general directed graphs with real edge-weights, the best known sequential time bound for computing shortest-paths from s sources is O Ž mn q n2 log n., using a Fibonacci heap implementation of Johnson’s algorithm Žsee w3x.. For planar graphs Frederickson w5x gave a O Ž n2 . time algorithm. As far as we know, these are also the previously best known bounds for graphs with a separator decomposition Žin particular, for the examples above.. An interesting application of our algorithm outside the shortest-paths realm is obtaining faster sequential algorithms for solving linear systems of inequalities where each inequality involves at most two variables, when the underlying graph has a separator decomposition. The underlying graph of such a system has a vertex corresponding to each variable and an edge to each inequality between the vertices corresponding to the variables participating in the inequality. The fastest known algorithm for solving such ˜Ž n3 q mn. expected systems, due to Cohen and Megiddo w1x, runs in O time, where n is the number of variables and m is the number of ˜Ž n3 . factor in the running time arises from the work inequalities. The O bound of a Floyd-Warshall parallel shortest-paths computation. The algorithm can use instead, however, the work bound of any polylog-time directed all-pairs shortest-paths algorithm that is applicable to the underlying graph and to path algebra problems over semirings. Hence, our results imply that when the underlying graph of the system of inequalities has a ˜Ž n1q 2 m q mn. k m-separator decomposition, the system can be solved in O time. For planar graphs, a separator decomposition such that m s 0.5 can be found in O Ž n1q e . work and O Žlog 3 n. time on a CRCW PRAM for any e ) 0 Žsee Gazit and Miller w7x.. Hence, shortest-paths from s sources can

334

EDITH COHEN

be found in O Žlog 3 n. time and O Ž n1.5 q sn log n. work on a CRCW PRAM. We further improve over the above bounds for families of graphs that have planar embeddings such that all vertices lie on q g n faces. The improvement is achieved by combining our algorithm with an algorithm by Pantziou et al. w18x that is based on a sequential algorithm by Frederickson w6x. Their algorithm reduces the problem to computing shortest-paths in a graph of size O Ž q .. It suffices to compute a k 0.5-separator decomposition of a planar graph with O Ž q . vertices. We use the algorithm of Gazit and Miller w7x to compute this decomposition in O Žlog 4 q . time and O Ž q 1q e . work on a CREW PRAM. We show that a representation of all-pairs shortest-paths Žby a compact routing table. can be produced in O Žlog 4 q q log 2 n. time using O Ž nq log 2 n. work on a CREW PRAM, shortest-path trees from s sources can be produced in O Žlog 4 q q log 2 n. time using O Ž n log 2 n q q 1.5 q sŽ n q q log q .. work, and distances between k pairs of vertices can be produced in O Žlog 4 q q log 2 n. time using O Ž n log 2 n q q 2 log q q k log n. work. We give some comments. Ži. Note that if negative weight cycles are present, some of the distances are not defined. It is simple, however, to adopt the algorithm to detect negative weight cycles within the same resource bounds. Žii. The algorithm as stated computed only distances, but it can be easily adapted to explicitly find minimum weight paths. Žiii. Our algorithm is applicable to general path algebra problems over semirings Žsee Pan and Reif w16x and w3x for applications.. Živ. The separator decomposition for a graph G depends only on the undirected unweighted skeleton of G, and hence needs to be computed only once for a group of instances which differ in the weights and direction on edges. Žv. In addition to providing significant asymptotic improvements over previous algorithms, our algorithm are intuitive and simple, and hence, may be of value in practice Žparticularly in situations where a separator-decomposition is readily available, for example, multi-dimensional grid-like graphs or planar graphs.. Pre¨ ious Work. Pan and Reif w16, 17x extended their parallel nested dissection algorithm and presented a class of parallel algorithm for path algebra problems on undirected graphs. Their algorithms rely on the availability of a separator decomposition of the undirected graph G and exhibit comparable bounds to ours. Lingas w13x considered planar directed graphs where the edge weights are restricted to be nonnegati¨ e and ha¨ e polynomial size. His algorithm assumes that a separator decomposition of the graph is available, where the separators must be simple cycle separators. The work bounds given are worse by a factor of O Žlog 2 n. than our algorithm with m s 0.5. For planar digraphs for which we are provided with embeddings such that all vertices are on q g n faces, Pantziou et al.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

335

w18x presented a CREW parallel algorithm for all-pairs shortest-paths information with real-valued edge weights. Their algorithm is based on parallelizing the hammock decomposition technique introduced by Frederickson w6x. Their algorithm runs in O Žlog 2 n. time and employs O Ž nq q q 3 . processors. The transitive closure can be found using O Ž nq q M Ž q .. processors. Another outcome of the parallel hammock decomposition technique is an algorithm by Djidjev et al. w4x that computes distances between k specified pairs of vertices in a planar graph in O Žlog 2 n. time ˜Ž n. work N C using O ŽŽ n q q 3 .log 2 n. work. Kao and Klein w10x gave a O algorithm for single source reachability in planar digraphs. Their algorithm ˜Ž n. work strongly connected components algorithm by Kao is based on a O and Shannon w11x. Klein and Sairam w12x gave a parallel approximation algorithm for single source shortest-paths on undirected planar graph with nonnegative weights. Their algorithm finds approximate paths to within a factor of Ž1 q e . Žfor a fixed e . and runs in O Ž n1r10 . time performing ˜Ž n. work. O O¨ er¨ iew. We give an overview of our algorithm. The algorithm is given as input a directed graph G s Ž V, E . with real weights w: E ª R, along with a separator decomposition tree TG of the undirected skeleton of G. The tree TG is a rooted binary tree with subgraphs of G associated with its nodes. The root of TG contains the original graph. With each node t g TG we associate a separator for the subgraph at the node t. The subgraphs at the children of t correspond to the partition induced by the separator at t. The algorithm uses TG to recursively construct a set of edges Eq; V = V with weights w: Eqª R. The set Eq is such that distances in G s Ž V, E . are the same as in Gqs Ž V, E j Eq. . In addition, every distance in Gq can be achieved by a path with at most O Ž dG . edges, where dG is the height of the tree TG Žthe size of the longest path from the root to a leaf.. Given the graph Gq, single source shortest-path information can be obtained in O Ž dG log n. time with O Ž< E j Eq< dG . work per source, using a straightforward parallel version of the Bellman-Ford algorithm Žsee w3x.. We show how to reduce the work to O Ž< E j Eq<. . In Section 2 we give some definitions. In Section 3 we define the set Eq with respect to G and the tree TG and prove that Eq has the desired properties. We also discuss an efficient way of computing shortest-paths using the set Eq. In Section 4 we present algorithms for computing the set Eq. In Section 5 we analyze the resource bounds of these algorithms when the decomposition tree is such that for some fixed m - 1, at each node, if the subgraph has k vertices, the separator is of size O Ž k m .. In Section 6 we discuss algorithms for planar graphs.

336

EDITH COHEN

2. PRELIMINARIES In this section we give some definitions and notation. 2.1. Notation For a graph G s Ž V, E . and V X ; V, we denote by E Ž V X . ; E the set of edges with two end points in V X , and we denote by N Ž V X . ; V the neighborhood of V X , that is, all vertices in or adjacent to V X . For a directed path p s Ž ¨ 1 , . . . , ¨ r . and 1 F i - j F r we denote by pi j the subpath Ž ¨ i , . . . , ¨ j .. A subset of vertices V X ; V separates V1 ; V R V X and V2 ; V R V X , if every Žundirected. path between a vertex in V1 and a vertex in V2 contains a vertex in V X . Let w: E ª R be weights on the edges of G. For EX ; E, we denote w Ž EX . s Ý e g EX w Ž e .. We refer to paths as sequences of vertices or edges. The size of a path is the number of edges in the path. The weight of a path p ; E is w Ž p .. The distance from ¨ 1 g V to ¨ 2 g V, denoted dist G Ž ¨ 1 , ¨ 2 ., is the weight of the minimum-weight path Žshortest path. from ¨ 1 to ¨ 2 . We use the notation R for the set of real numbers and Zq for the set of nonnegative integers. 2.2. The Minimum-Weight Diameter of a Graph The minimum-weight diameter diamŽ G . g Zq of a graph G s Ž V, E . with weights w: E ª R is the maximum, over all pairs Ž ¨ 1 , ¨ 2 . g V = V of the minimum size of a path from ¨ 1 to ¨ 2 of weight distŽ ¨ 1 , ¨ 2 .: diam Ž G . s

max

Ž ¨ 1 , ¨ 2 .gV=V

min  < p < < p is a path from ¨ 1 to ¨ 2 s.t. w Ž p . s dist G Ž ¨ 1 , ¨ 2 . 4 .

Single source shortest-paths computation can be performed more efficiently in parallel on graphs with a small minimum-weight diameter, namely, in O ŽdiamŽ G .log n. time using O Ž< E < diamŽ G .. work. These bounds are achieved by running a parallel version of the Bellman-Ford shortestpaths algorithm Žsee w3, 9x.. Note that we need to run the algorithm for only diamŽ G . phases and each phase can be performed in O Žlog n. time and O Ž< E <. work. 2.3. Separator Decomposition Tree of a Graph Consider an undirected graph G s Ž V, E .. A separator decomposition tree of G Žsee Fig. 1, for an example. is a rooted binary tree TG such that each note t g TG is labeled by two subsets of vertices V Ž t . ; V and S Ž t . ; V Ž t .. For t g TG , denote by GŽ t . s Ž V Ž t ., E Ž V Ž t ... the subgraph of G induced by V Ž t .. The subset S Ž t . is a separator of GŽ t .. The root

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

337

FIG. 1. A separator decomposition tree of a 9 = 9 grid graph.

node r g TG is labeled with V Ž r . s V and S Ž r . is a separator for the graph G. The labels for the children of a node t g TG are determined as follows. Let V1 ; V Ž t . and V2 ; V Ž t . be such that S Ž t . separates V1 from V2 in GŽ t .. ŽNote that V1 and V2 are not necessarily connected.. Denote by t 1 , t 2 the children of t in TG . The labels of t i Ž i s 1, 2. are V Ž t i . s Vi j Ž S Ž t . l N Ž Vi .. and S Ž t i . is a separator of GŽ t i .. The leaves of TG have only V Ž . labels. To avoid ambiguity, throughout the paper we refer to the vertices of G as ‘‘vertices’’ and to the vertices of the separator tree TG as ‘‘nodes.’’ We denote by dG the height of the tree TG Žsize of a maximum size path from the root to a leaf.. We associate sets of boundary vertices BŽ t . with each node t g TG . The boundaries are defined as follows: The boundary of the root r g TG is BŽ r . s B. The boundary of a node t g TG with parent tX is BŽ t . s Ž S Ž tX . j BŽ tX .. l V Ž t ..

338

EDITH COHEN

It is easy to see that the boundary sets have the following properties: PROPOSITION 2.1. i. For all t g TG , BŽ t . s V Ž t . l D tX g W S Ž tX ., where W ; TG is the set of ancestors of t. ii. For all t g TG , BŽ t . separates V Ž t . R BŽ t . from V R V Ž t . in G.

3. AUGMENTING G USING THE DECOMPOSITION TREE Consider a directed graph G s Ž V, E . with weights w: E ª R and a separator decomposition tree TG of the undirected skeleton of G. We define an augmentation of G, with respect to TG , by a set Eq; V = V of edges with weights w: Eqª R. The augmented graph Gqs Ž V, E j Eq. is such that distances in Gq are equal to the respective distances in G, and Gq has a small minimum-weight diameter. In Section 3.1 we define the set Eq and prove it has some desired properties. In Section 3.2 we discuss the resource bounds of computing shortest-paths from a set of sources when the set Eq is given. 3.1. The Set Eq For t g TG , denote by Et a set of weighted edges as follows: Et s BŽ t . = BŽ t . j S Ž t . = S Ž t ., where e s Ž ¨ 1 , ¨ 2 . g Et has weight w Ž e . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. Define Eqs D t g T G Et . We may assume that Eq does not contain parallel edges by including in Eq only the parallel edge of minimum weight. In Section 4 we present an algorithm to compute the set Eq. The following theorem establishes that the set Eq has the desired properties. THEOREM 3.1. The graph Gqs Ž V, E j Eq. has the following properties. Ži. For e¨ ery Ž ¨ 1 , ¨ 2 . ; V = V, dist G Ž ¨ 1 , ¨ 2 . s dist G q Ž ¨ 1 , ¨ 2 ., and Žii. diamŽ Gq. , the minimum-weight diameter of Gq, is such that diamŽ Gq. F 4 dG q 2 l q 1, where l is the maximum, o¨ er all lea¨ es t g TG of the minimum-weight diameter of GŽ t .. Part i of Theorem 3.1 immediately follows from the fact that all the edges in Eq have weight which is not smaller than the respective distances in G. In the remaining part of the section we prove part ii of Theorem 3.1. We define two functions level: V j TG ª  0, . . . , dG 4 and node: V ª TG . For a node t g TG , denote by levelŽ t . the size of the path in TG from t to the root. For ¨ g V, define level Ž ¨ . s min  i < ' t g TG s.t. ¨ g S Ž t . n level Ž t . s i 4 ,

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

339

the minimum level of all nodes t g TG such that ¨ g S Ž t .. If ¨ f D t g T G S Ž t . Ž ¨ does not belong to any separator., then levelŽ ¨ . is undefined. It is easy to see that for all t g TG , if ¨ g BŽ t . then levelŽ ¨ . levelŽ t . and if ¨ g S Ž t . then levelŽ ¨ . F levelŽ t .. For ¨ g V, we define nodeŽ ¨ . g TG as follows: nodeŽ ¨ . s t if and only if ¨ g S Ž t . n levelŽ ¨ . s levelŽ t .. If ¨ f D t g T G S Ž t ., we define nodeŽ ¨ . to be the leaf t g TG such that ¨ g V Ž t .. It follows from the construction of TG and properties of the level function that nodeŽ ¨ . is uniquely defined. Consider a directed path p s Ž ¨ 1 , ¨ 2 , . . . , ¨ r . in G. We say that the path p has a shortcut if e s Ž ¨ 1 , ¨ r . g Eqj E and w Ž e . F w Ž p .. The following proposition states some sufficient conditions for shortcuts. PROPOSITION 3.2. A path p s Ž ¨ 1 , ¨ 2 , . . . , ¨ r . in G has a shortcut if any one of the following conditions holds: Ži. levelŽ ¨ 1 . s levelŽ ¨ r . and for all 1 F k F r, levelŽ ¨ k . G levelŽ ¨ 1 . Žii. levelŽ ¨ 1 . ) levelŽ ¨ r . and for all 1 - k - r, levelŽ ¨ k . ) levelŽ ¨ 1 . Žiii. levelŽ ¨ 1 . - levelŽ ¨ r . and for all 1 - k - r, levelŽ ¨ k . ) levelŽ ¨ r .. Proof. In order to prove that a path p has a shortcut, it suffices to show that there exists some t g TG , such that p ; V Ž t . and either  ¨ 1 , ¨ r 4 ; S Ž t . or  ¨ 1 , ¨ r 4 : BŽ t .. We first prove part i. Note that p l BŽnodeŽ ¨ 1 .. s B Žsince the level of boundary vertices of a node is lower than the level of the node.. Hence, p ; V ŽnodeŽ ¨ 1 .. and nodeŽ ¨ 1 . s nodeŽ ¨ r .. The definition of the level function implies that  ¨ 1 , ¨ r 4 ; S ŽnodeŽ ¨ 1 ... It follows that p has a shortcut. We prove part ii of the claim. The correctness of part iii can be shown by a symmetric argument. The properties of the level function assert that  ¨ 1 , . . . , ¨ ry14 l BŽnodeŽ ¨ 1 .. s B,  ¨ 2 , . . . , ¨ ry1 4 l S ŽnodeŽ ¨ 1 .. s B, ¨ r g BŽnodeŽ ¨ 1 .., and ¨ 1 g S ŽnodeŽ ¨ 1 ... Hence, one of the children, t, of nodeŽ ¨ 1 . is such that p ; V Ž t . and  ¨ 1 , ¨ r 4 ; BŽ t .. Thus, p has a shortcut. We are ready to conclude the proof of Theorem 3.1 and show that diamŽ Gq. F 4 dG q 2 l q 1. We first establish the following claim. Consider a path ˆ p s Ž ¨ s ¨ 1 , . . . , ¨ r s u. such that the levels of at least one vertex in ˆ p and all of  ¨ 2 , . . . , ¨ ry14 are undefined. It follows that for some leaf t g TG , p ; V Ž t ., and hence, there is a path pX s Ž ¨ s ¨ X1 , . . . , ¨ Xk s u. such that w Ž pX . F w Ž ˆ p . and k F l. Consider a path p s Ž ¨ 1 , . . . , ¨ r . in G. We say that p can be replaced by a path pX in Gq, if pX is from ¨ 1 to ¨ r and w Ž pX . F w Ž p .. It suffices to show that p can be replaced by a path of size at most 4 dG q 2 l q 1. If levelŽ ¨ i . is undefined for all 1 F i F r, then the claim implies that p can be replaced by a path of size at most l. Otherwise, let i1 s min 1 F i < levelŽ ¨ i . is defined4 and let i 2 s max i < levelŽ ¨ i . is defined4 . The claim asserts that the subpaths p1 i1 and pi 2 r can each be replaced by paths of size at most l. If i1 s i 2 then p can

340

EDITH COHEN

be replaced by a path of size at most 2 l and we are done. Otherwise, to establish that p can be replaced by a path of size at most 4 dG q 2 l q 1, it suffices to show that the subpath pi1 i 2 can be replaced by a path of size 4 dG q 1. We explicitly point on h F 4 dG q 2 indices i1 s j1 - j2 - ??? jh s i 2 such that for all 1 F i F h y 1, pj i j iq 1 has a shortcut. For each i1 F j - i 2 such that levelŽ ¨ j . is defined, we assign to ¨ j a right shortcut as follows. The right shortcut of ¨ j is a vertex ¨ k such that j - k F i 2 , levelŽ ¨ k . is defined, and the subpath pjk has a shortcut. Below we define the right shortcut of a vertex ¨ j . In the following, when levelŽ ¨ . is undefined we treat it as levelŽ ¨ . s `. i. Let k s max  i < i ) j n level Ž ¨ i . s level Ž ¨ j . n ; iX s.t. i F iX F j, level Ž ¨ iX . G level Ž ¨ j . 4 . If k is defined, the right shortcut from ¨ j is ¨ k . It follows from Part i of Proposition 3.2 that pjk has a shortcut. ii. Otherwise, if k is not defined, then if there exists i ) j such that levelŽ ¨ i . - levelŽ ¨ j ., let k s min  i ) j < level Ž ¨ i . - level Ž ¨ j . 4 , and define ¨ k to be the right shortcut of ¨ j . It follows from Part ii of Proposition 3.2 that pjk has a shortcut. iii. Otherwise, for all i ) j, levelŽ ¨ i . ) levelŽ ¨ j .. Let k s max  i ) j < ; iX s.t. j F iX F i , level Ž ¨ iX . ) level Ž ¨ i . 4 , and define ¨ k to be the right shortcut of ¨ j . Since levelŽ ¨ i 2 . is defined, levelŽ ¨ k . must be defined. It follows from Part iii of Proposition 3.2 that pjk has a shortcut. Consider the path pX in Eq formed by starting from ¨ i1 and following right shortcuts Žnote that levelŽ ¨ i1 . is defined.. The path pX must end in ¨ i 2 , and the level function of all vertices in pX is defined. Consider the sequence of level labels of vertices on the path. It is easy to see that any subsequence of consecutive vertices with the same level is of size at most 2. The sequence is bitonic: first nonincreasing up to a point and then nondecreasing. We conclude that the size of pX is at most 4 dG q 1. See Fig. 2 for an example of right shortcuts.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

341

FIG. 2. A path with level labels and corresponding right shortcuts.

3.2. Computing Shortest-Paths Using Eq We discuss how we employ the set Eq of weighted edges to compute shortest-paths from s sources. We consider a single source vertex u g V. In Section 2.2 we argued that distances from a single source in a graph G can be computed in O ŽdiamŽ G .log n. time using O Ž m diamŽ G .. work. These bounds are achieved by running for each source, a parallel version of the Bellman-Ford shortest-paths algorithm Žsee w3, 9x.. We sketch the algorithm. The algorithm runs in O ŽdiamŽ G .. phases. In each phase, for each node ¨ g V, we consider all edges e g E entering ¨ . For each such edge, e s Ž ¨ X , ¨ . we update the distance of ¨ from u to be the minimum of the current distance and the sum of w Ž e . and the current distance of ¨ X from u. We refer to the above operation as scanning the edge e. Each phase takes O Ž m. time sequentially and it can be parallelized such that it takes O Žlog n. time and O Ž m. work. The Bellman-Ford algorithm sketched above scans all edges in every phase. We show that for the augmented graph Gqs Ž V, E j Eq. , however, it suffices to scan the edges only in a small number of phases. In the proof of Theorem 3.1 we pointed on minimum-weight paths of a specific structure. We defined the function level: V ª  0, . . . , dG 4 , where dG is the height of the separator tree TG . We showed that for every pair of vertices in Gq, there exist a minimum-weight path between them with the following structure. The path may start and end with a sequence of at most l edges from E Žwhere l is as in Theorem 3.1.. All other edges are Eq edges. The levels of the vertices on the path form a bitonic sequence: first nonincreasing then nondecreasing, where vertices of the same level may appear at most two consecutive times. It is easy to see that it suffices to run a version of the Bellman-Ford algorithm that scans edges as follows. We run the algorithm for 2 l q 4 dG q 1 phases. In each of the first l phases and the last l phases we scan the edges E. For 1 F i F 2 dG q 1, in the Ž i q l .th phase we scan all edges e s Ž ¨ 1 , ¨ 2 . as follows: If i is odd, we scan e if levelŽ ¨ 1 . s levelŽ ¨ 2 . s dG y Ž i y 1.r2. If i is even, e is scanned if levelŽ ¨ 1 . s dG y ir2 y 1 and levelŽ ¨ 2 . - levelŽ ¨ 1 .. For 1 F i F 2 dG , in the Ž i q l q 2 dG .th phase we scan all edges e s Ž ¨ 1 , ¨ 2 . as follows: If i is odd, e is scanned if levelŽ ¨ 1 . s Ž i y 1.r2 and levelŽ ¨ 2 . ) levelŽ ¨ 1 .. If i is even, e is scanned if levelŽ ¨ 1 . s levelŽ ¨ 2 . s ir2.

342

EDITH COHEN

The work performed by the modified Bellman-Ford algorithm is O Ž l < E < q < Eq<. per source, and the time is O Žlog n. per phase and hence is O ŽŽ l q dG .log n.. 4. COMPUTING THE SET E q In this section we present two algorithms that input a directed graph G s Ž V, E . with edge-weights w: E ª R and a separator tree TG for G, and compute the weighted set of edges Eqs D t g T G Et as defined in Section 3. The first algorithm computes the set Eq recursively, going from the leaves to the root. The running time is O Ž dG log 2 n.. The second algorithm runs in time O Ž dG log n. but performs a factor of O Žlog n. more work. 4.1. Computing Eq from the Lea¨ es Up The computation of Eq is done by first computing the sets Et for the leaves of TG Žthis can be done independently and in parallel for all leaves., and then dG parallel phases are performed, where at phase iŽ1 F i F dG ., Et is computed for all nodes t g TG at level dG y i, using the procedure below and the previously computed Et sets for all nodes at level dG y i q 1. Below, we state a procedure that inputs a node t g TG with children  t 1 , t 2 4 ; TG and the sets Et and Et , and constructs the set Et . 1 2 We discuss the procedure for processing a single node t. Let t 1 g TG and t 2 g TG be the children of T. We assume that for i s 1, 2, we are provided with the set Et i , and in particular, with the distances in GŽ t i . between the pairs BŽ t i . = BŽ t i .. The goal is to obtain the distances in GŽ t . between the pairs BŽ t . = BŽ t . j S Ž t . = S Ž t .. The following procedure performs this computation. ALGORITHM 4.1 wProcess the node t g TG x. i. Construct the graph HS s Ž S Ž t ., S Ž t . = S Ž t .. with weights wH S : S Ž t . = S Ž t . ª R as follows. For every e s Ž ¨ 1 , ¨ 2 . g S Ž t . = S Ž t .. define: wH SŽ e . ¤ min  dist GŽ t 1 . Ž ¨ 1 , ¨ 2 . , dist GŽ t 2 . Ž ¨ 1 , ¨ 2 . 4 . ŽThese distances are available since for i s 1, 2,  ¨ 1 , ¨ 2 4 ; BŽ t i ... ii. Perform an all-pairs shortest-paths computation on HS . For every e s Ž ¨ 1 , ¨ 2 . g S Ž t . = S Ž t ., output w Ž e . ¤ dist H SŽ ¨ 1 , ¨ 2 .. iii. Construct the graph H s Ž VH , EH . where VH s BŽ t . j S Ž t . and EH s BŽ t . = S Ž t . j S Ž t . = BŽ t . j S Ž t . = S Ž t . with weights wH : EH ª R as follows.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

343

For e s Ž ¨ 1 , ¨ 2 . g EH : if e g S Ž t . = S Ž t .., then wH Ž e . ¤ dist H SŽ ¨ 1 , ¨ 2 .. Otherwise, let i g  1, 24 be such that  ¨ 1 , ¨ 2 4 ; V Ž t i . Žthis must be the case for exactly one of i s 1 or i s 2.. Let wH Ž e . ¤ dist GŽ t i .Ž ¨ 1 , ¨ 2 .. ŽThese distances are available since  ¨ 1 , ¨ 2 4 ; BŽ t i ... iv. For every vertex ¨ g BŽ t . perform a single-source 3-limited shortestpaths computations in H of distances from ¨ and distances to ¨ . v. For every e s Ž ¨ 1 , ¨ 2 . g BŽ t . = BŽ t ., output

¡min dist

Ž ¨ 1 , ¨ 2 . , dist 3H Ž ¨ 1 , ¨ 2 . 4

if  ¨ 1 , ¨ 2 4 ; B Ž t 1 .

w Ž e . s min  dist GŽ t 2 . Ž ¨ 1 , ¨ 2 . , dist 3H Ž ¨ 1 , ¨ 2 . 4

if  ¨ 1 , ¨ 2 4 ; B Ž t 2 .

~

¢dist

3 H

GŽ t 1 .

Ž ¨1, ¨2 .

otherwise.

Complexity. Using the Floyd-Warshall algorithm Žsee w3, 9x., step ii can be implemented such that it uses O Ž< S Ž t .< 3 logŽ< S Ž t .<.. work and runs in O Žlog 2 n. time. The work can be further reduced to O Ž< S Ž t .< 3 ., if a recent algorithm of Han et al. w8x is used. Step iv can be implemented Že.g., by using, for each source, three iterations of a parallel Bellman-Ford algorithm, see w3, 9x. such that it uses < BŽ t .< 2 < S Ž t .<. work and runs in O ŽlogŽ< BŽ t .< q < S Ž t .<.. time. Hence, Algorithm 4.1 can be implemented such that it uses O Ž< S Ž t .< 3 q < BŽ t .< 2 < S Ž t .<. work and runs in O Žlog 2 n. time. If the algorithm is used for reachability or transitive closure computations, we can perform step ii in O Žlog 2 < S Ž t .<. time using M Ž< S Ž t .<.log < S Ž t .< work, and step iv in O Žlog < S Ž t .< q < BŽ t .<. time using M Ž< S Ž t .< q < BŽ t .<. work. Hence, in O Žlog 2 n. time using M Ž< S Ž t .<.log n q M Ž< BŽ t .<. work. Correctness. The following proposition establishes the correctness of the algorithm. PROPOSITION 4.2. For e¨ ery e s Ž ¨ 1 , ¨ 2 . g Et , w Ž e . we computed by the algorithm is such that w Ž e . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. Proof. First we show that for  ¨ 1 , ¨ 2 4 ; S Ž t ., dist H sŽ ¨ 1 , ¨ 2 . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. Consider a path p s Ž u1 , . . . , u r . ; V Ž t . such that p l S Ž t . s  u1 , u r 4 . It follows from definitions that  u1 , u r 4 ; BŽ t 1 . l BŽ t 2 . and either p ; V Ž t 1 . or p ; V Ž t 2 .. Hence, w Ž p . G min  dist GŽ t 1 . Ž u1 , u r . , dist GŽ t 2 . Ž u1 , u r . 4 s wH SŽ u1 , u r . G dist H SŽ u1 , u r . .

344

EDITH COHEN

Consider a path p s Ž ¨ 1 s u1 , . . . , u r s ¨ 2 . : V Ž t . such that p l S Ž t . s  u i , . . . , u i 4 , where 1 s i1 - ??? - i k s r. It suffices to show that w Ž p . G 1 k dist H SŽ u1 , u r .. The argument above implies that for 1 F j F k y 1, w Ž pi j i jq 1 . G dist H SŽ u i j , u i jq 1 .. Therefore, ky1

w Ž p. s

ky1

Ý w Ž pi i . G Ý dist H Ž u i , u i . G dist H Ž u1 , u r . . j jq 1

js1

S

j

jq 1

S

js1

It remains to show that for e s Ž ¨ 1 , ¨ 2 . ; BŽ t . = BŽ t ., w Ž e . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. Let p s Ž ¨ 1 s u1 , . . . , u r s ¨ 2 . be a path from ¨ 1 to ¨ 2 in GŽ t . we show that w Ž e . F w Ž p .. If p l S Ž t . s B then for either i s 1 or i s 2, p ; V Ž t i . and  ¨ 1 , ¨ 2 4 ; BŽ t i .; hence, w Ž p . G dist GŽ t i .Ž ¨ 1 , ¨ 2 . G w Ž e .. Otherwise, let i1 s min 1 F i F r < u i g S Ž t .4 and let i 2 s max 1 F i F r < u i g S Ž t .4 . By definition,  e1 s Ž u1 , u i1 ., e2 s Ž u i1, u i 2 ., e3 s Ž u i 2 , u r .4 ; EH . ŽIf i1 s i 2 , do not consider the edge e2 .. It follows that p1 i1 and pi 2 r must be each contained either in V Ž t 1 . or in V Ž t 2 .. Hence, w Ž p1 i1 . G wH Ž e1 ., w Ž pi 2 r . G wH Ž e3 ., and Žusing the first part of the proof. wH Ž e2 . s dist H SŽ u i1, u i 2 . F w Ž pi1 i 2 .. It follows that w Ž p . G wH Ž e1 . q wH Ž e2 . q wH Ž e3 .. Hence, there is a path of size at most 3 in H with weight at most the weight of p. 4.2. A Faster Algorithm for Computing Eq The algorithm in Section 4.1 computes the set Eq by performing dG parallel phases, where in phase i we compute Et for all the nodes t g TG of level dG y i. Therefore, in each phase, the algorithm performs complete all-pair shortest-path computations that take O Žlog 2 n. time. The following algorithm computes Eq by performing simultaneously, for all nodes t g TG , an all-pairs shortest-paths computation on the boundary and separator vertices of GŽ t .: Roughly, computing Et for each node t g TG before it is done with computing Et 1, Et 2 for the children t 1 , t 2 of t. This enables us to save a factor of O Ž dG . in the running time. We assume that the all-pairs shortest-paths computation utilized consists of O Žlog n. path doubling steps. After each doubling step, we update the weights in each GŽ t . using the weights given to the edge by the children of t. ALGORITHM 4.3 wCompute the weighted set Eqx . i. For all t g TG pardo: Construct the graph H Ž t . s Ž VH Ž t ., EH Ž t .., where VH Ž t . ¤ S Ž t . j BŽ t . and EH Ž t . ¤ VH Ž t . = VH Ž t ..

345

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

Assign weights to every e s Ž ¨ 1 , ¨ 2 . g EH Ž t . as follows: wt Ž e . ¤

½

dist GŽ t . Ž ¨ 1 , ¨ 2 .

if t is a leaf

min  w Ž e . , ` 4

otherwise

ii. Repeat 2ulog n v q 2 dG times: Ž1. For all t g TG apply a path doubling step to H Ž t .: Pardo for all e s Ž u1 , u 2 . g EH Ž t .: w Ž e . ¤ min wt Ž e ., min ug V H Ž t . wt Ž u1 , u. q wt Ž u, u 2 .4 . Ž2. For all t g TG pardo: For every e g EH Ž t . pardo: wt Ž e . ¤ min wt 1Ž e ., wt 2Ž e ., wt Ž e .4 . Žwhere t 1 , t 2 g TG are the children of t and for i g  1, 24 , wt Ž e . i ' ` if e f EH Ž t i ... q iii. For all e g E , w Ž e . ¤ min t g T < e g E Ž t .4 wt Ž e . G

H

Complexity. Let LG ; TG be the set of leaves of TG , and let l be the maximum minimum-weight diameter of  GŽ t . < t g LG 4 . Step i can be implemented in O Žmax t g L G log < V Ž t .<. time and O Ž lÝ t g L GŽ< S Ž t .< q < BŽ t .<.< V Ž t .<. work, using l iterations of the Bellman-Ford algorithm Žsee w3, 9x. or in Ý t g L Ž< V Ž t .< 3 .max t g L log < V Ž t .<. work and O Žlog l max t g L G G G log < V Ž t .<. time using the Floyd-Warshall algorithm. Step iiŽ1. can be implemented such that it uses Ý t g T GŽ< S Ž t .< q < BŽ t .<. 3 work and runs in max O Ž log Ž < S Ž t . < q < B Ž t . < . . s O Ž log n .

tgTG

time, by using a single iteration of the Floyd-Warshall algorithm Žsee w3, 9x.. The complexity bounds of the other steps are dominated by step iiŽ1.. Note that step iiŽ1. is performed O Ž dG q log n. times. It follows that Algorithm 4.3 can be implemented such that it uses O

žÝŽ

< S Ž t . < q < B Ž t . < . 3 log n q

tgTG

Ý Ž < V Ž t . < 3 . log n tgL G

/

work and runs in O Žlog 2 n q dG log n. time. If the algorithm is used for reachability or transitive closure computations, we can perform step iiŽ1. in O ŽlogŽ< S Ž t .< q < BŽ t .<. time using O Ž M Ž< S Ž t .< q < BŽ t .<.. work, and step i in O ŽÝ t g L GŽ M Ž< V Ž t .<.max t g L G log < V Ž t .<.. work. Hence, the algorithm runs in O Žlog 2 n q dG log n. time using O

žÝ

tgTG

M Ž < S Ž t . < q < B Ž t . < . log n q

Ý tgL G

M Ž < V Ž t . < . log n work.

/

346

EDITH COHEN

Remark 4.4. In some cases, the time can be improved using the following consideration. Observe that Algorithm 4.3 as stated performs some redundant work. We say that two edges Ž u1 , u 2 . and Ž u 2 , u 3 . are paired at some iteration, if during this iteration the algorithm updates the weights assigned to Ž u1 , u 3 . to be at most the sum of the weights currently assigned to Ž u1 , u 2 . and Ž u 2 , u 3 .. For a triple of vertices u1 , u 2 , u 3 define Cu1 u 2 u 3 s  t g TG <  u1 , u 2 , u 3 4 ; VH Ž t . 4 . The algorithm pairs the edges Ž u1 , u 2 . and Ž u 2 , u 3 . < Cu1 u 2 u 3 < times in each computation of step iiŽ1.. These pairing are done with respect to the weights wt Ž t g Cu1 u 2 u 3 .. It suffices to do the pairing once with respect to the weights min t g C u u u wt . We modify the algorithm such that it maintains 1 2 3 a single copy of each edge in D t g T G EH Ž t . and a compactly represented table indicating which edges are to be paired, where two edges Ž u1 , u 2 . and Ž u 2 , u 3 . are paired if and only if < Cu u u < ) 0. ŽNote that this table depends 1 2 3 only on the sets VH Ž t . for t g TG and needs to be computed once.. It follows from standard PRAM techniques that the computation of the table and each iteration of step iiŽ1. Žthat is, pairing all qualified pairs. can be performed in O Žlog n. time and O Ž   u1 , u 2 , u 3 4 ; V < ' t g TG ,  u1 , u 2 , u 3 4 ; VH Ž t . 4

. work.

Correctness. The following proposition establishes the correctness of Algorithm 4.3. PROPOSITION 4.5. At step iii of the algorithm, for e¨ ery t g TG and e s Ž ¨ 1 , ¨ 2 . g EH Ž t ., wt Ž e . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. In the remaining part of this section we prove Proposition 4.5. For a node t g TG , denote by heightŽ t . the maximum size of a path from t to a leaf in the subtree of TG rooted at t. The following claim implies the proposition. Consider a node t g TG and an edge e s Ž ¨ 1 , ¨ 2 . g EH Ž t .. Let p s Ž ¨ 1 s u1 , . . . , u r s ¨ 2 . be a path in GŽ t . from ¨ 1 to ¨ 2 such that w Ž p . s dist GŽ t .Ž ¨ 1 , ¨ 2 .. We claim that after at most 2ulogŽ r y 1.v q 2 heightŽ t . iterations of step ii, wt Ž e . s w Ž p .. We prove the claim by induction on heightŽ t .. The base case is when t is a leaf ŽheightŽ t . s 0., and the claim is immediate from the initialization Žstep i.. If heightŽ t . ) 0, we assume Žby the induction hypothesis. that the claim holds for the children t 1 , t 2 of t. If p l S Ž t . ;  u1 , u r 4 , it follows from definitions that  u1 , u 2 4 ; BŽ t 1 . l BŽ t 2 . and either p ; V Ž t 1 . or p ; V Ž t 2 .. Hence, the claim follows from the induction hypothesis. Otherwise, let 1 s i1 - ??? i k s r be such that Ž p R  u1 , u r 4. l S Ž t . s  u i 2 , . . . , u i ky 14 . It follows from the definitions that for 1 F j F k y 1, the subpath pi j i jq 1 is contained in

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

347

V Ž t i . Žfor either i s 1 or i s 2. and that e j ' Ž u i j , u i jq 1 . g EH Ž t i . and e j g EH Ž t .. The induction hypothesis asserts that for 1 F j F k y 1, after 2ulogŽ i jq1 y i j .v q 2 max heightŽ t 1 ., heightŽ t 2 .4 iterations, min wt 1Ž e j ., wt 2Ž e j .4 s w Ž pi j i jq 1 . and hence, wt Ž e j . s w Ž pi j i jq 1 .. View the path in H Ž t . consisting of the edges e1 , . . . , e ky1 as a list. We define the size of the edge e j to be < e j < s i jq1 y i j Žthe size of the subpath pi j i jq 1 .. We say that an edge e j becomes acti¨ e when it is assigned the weight w Ž pi j i jq 1 .. The edge e j becomes active after at most 2ulogŽ i jq1 y i j .v q2 max heightŽ t 1 ., heightŽ t 2 .4 iterations. Consider performing the following ‘‘pairing phase’’ on the list of edges in each iteration. i. Choose a collection of disjoint pairs of active edges in the list such that the two edges in each pair are consecutive. ii. Replace each such pair of edges eX1 s Ž ¨ 1 , ¨ 2 . and eX2 s Ž ¨ 2 , ¨ 3 . with a new edge eX s Ž ¨ 1 , ¨ 3 . g EH , where the weight of eX is defined to be the sum of the weights currently assigned to eX1 and eX2 , and the size of eX is the sum of the sizes of eX1 and eX2 . Newly formed edges are active. Consider performing pairing phases with a sequence of iterations. The sum of the sizes of the edges on the list is always r y 1. It is easy to see that during the execution of the sequence, the weight currently assigned to each edge e in the list is not smaller than the current value of wt Ž e .. Consider a sequence that reduces the list to a single edge eX s Ž u1 , u r .. The weight of the edge eX equals w Ž p .. Hence, it suffices to show that there exists a sequence of at most 2ulogŽ r y 1.v q 2 heightŽ t . pairing phases that reduces the list e1 , . . . , e ky1 to a single edge. We use the following proposition: PROPOSITION 4.6. There exists a sequence of pairing phases such that for i G 1, after 2 i q 2 max  height Ž t 1 . , height Ž t 2 . 4 phases, all edges of size at most 2 i are acti¨ e and the list does not contain two consecuti¨ e edges of size 2 iy1 or less. Proof. The part of the claim regarding the active edges is immediate from the definition. We prove the proposition by induction on i. The base case where i s 1 is immediate, since all edges of size 1 are initially active and an obvious pairing achieves the goal Že.g., any maximal pairing of active edges.. Assume that the proposition holds for i s k. Consider all edges of size at most 2 k after phase 2 k q 2 max heightŽ t 1 ., heightŽ t 2 .4 . We need to show that after two appropriately chosen pairing phases there are no two consecutive edges of size 2 k or less. Consider a maximal sublist of

348

EDITH COHEN

edges of size 2 k or less. ŽIt suffices to consider these sublists independently.. It follows from the induction hypothesis that each edge of size at most 2 ky 1 either is the rightmost edge of the sublist or has an edge of size larger than 2 ky 1 to its right. In the first pairing phase, pair all edges of weight no larger than 2 ky 1 with the edge to their right Žif the edge to the right is active. and if the two rightmost edges are not paired, pair them together. As a result, all the edges in the new sublist have size larger than 2 ky 1, except, perhaps, the rightmost edge. In the second phase, pair up edges at even positions with the edge to their right Žexcept for the rightmost edge.. The resulting sublist is such that all edges are of size larger than 2 k with the possible exception of the rightmost edge. We conclude the proof of Proposition 4.5. We substitute i s uŽ r y 1.v in Proposition 4.6. We obtain that after 2 Ž r y 1 . q 2 max  height Ž t 1 . , height Ž t 2 . 4 phases the list consists of at most three edges, all active. ŽSince the sum of sizes of edges is r y 1.. Hence, after two additional pairing phases the list would consist of a single edge. Proposition 4.5 follows using the fact that heightŽ t . s max heightŽ t 1 ., heightŽ t 2 .4 q 1. 5. GRAPHS WITH n m SEPARATORS We analyze the performance of the algorithms of Section 4 Žcomputing the set Eq. and Section 3 Žcomputing shortest-paths using Eq. when for two constants 0 - m - 1 and 1r2 - a - 1, the separator decomposition tree TG has the following properties: i. For all t g TG , < S Ž t .< s O Ž< V Ž t .< m .. ii. For all  t, tX 4 ; TG such that tX is a child of t, < V Ž tX .< F a < V Ž t .<. iii. If t g TG is a leaf then < V Ž t .< s O Ž1.. We prove the following: THEOREM 5.1. Under the assumptions abo¨ e, the set Eq can be computed within the following bounds: i. Algorithm 4.3 runs in O Žlog 2 n. time and performs O ŽŽ n q n log n. work if m / 1r3 and O Ž n log 2 n. work if m s 1r3. For the reachability problem, the algorithm performs O ŽŽ M Ž n m . q n.log 2 n. work if vm / 1 and O Ž n log 3 n. work if vm s 1. 3m .

349

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

ii. The algorithm of Section 4.1 runs OŽ n work if 3 m ) 1, O Ž n log n. work 3 m - 1. iii. The sets E and Eq are such that Ž O n q n2 m .. We ha¨ e dG s O Žlog n.. 3m .

in O Žlog 3 n. time and performs if 3 m s 1, and O Ž n. work if < E < s O Ž n q n2 m . and < Eq< s

COROLLARY 5.2. Distances from a set of s sources to all other ¨ ertices in Gq can be computed in O Žlog 2 n. time using O Ž sŽ n q n2 m .. work if m / 1r2 and O Ž sn log n. work if m s 1r2. Proof. The corollary follows from the analysis done in Section 3.2, and substituting dG s O Žlog n., l s O Ž1., and the above bounds for < E < and < Eq <. The remaining part of the section contains a proof of Theorem 5.1. The above properties guarantee that the height of the separator tree is dG F log ay1 n. It follows that Algorithm 4.3 runs in time O Žlog 2 n. and the algorithm of Section 4.1 runs in O Žlog 3 n. time, for 0 F i F dG . For 0 F i F ?log Ž1y a .y1 n @, denote by Ti ; TG , the set of all nodes t g TG such that Ž1 y a . iy1 n - < V Ž t .< F Ž1 y a . i n. Observe that Ži. Ti is a forest consisting of subtrees of height ulog Ž1y a . a v, and Žii. if t g Tk for some k, then the children of t are in Tk j Tkq1. Denote by Pk ; Tk , all nodes t g Tk such that the parent of t in TG is not in Tk . Denote n k s Ý t g P k < V Ž t .<. Observe that Ý t g T k < V Ž t .< s O Ž n k .: sk s

Ý

< S Ž t. < s O

tgT k

ž

nk k

Ž1 y a . n

Ž1 y a .

km

nm .

/

It is immediate from the definitions that n 0 s n and n kq1 F n k q sk . We show that for all k, n k s O Ž n.. Note that n kq 1 F n k q sk F n k 1 q O

ž

ž ŽŽ1 y a .

k

n.

my1

//.

Hence, k

n kq 1 F n Ł 1 q O n m y1 Ž Ž 1 y a . is0

ž

ž

y1 i Ž1y m .

.

//.

Using the fact that k F log Ž1y a .y1 n we derive ?log Ž1y a .y1 n @

nk F n

Ł

is0

ž1 q O ž n

F n Ł 1 q OŽŽ1 y a . iG0

ž

m y1

Ž Ž 1 y a . y1 .

i Ž1y m .

Therefore, sk s O Ž n m Ž1 y a . kŽ m y1. ..

. / F n2 OŽÝ

Ž? log Ž1y a .y1 n @yi .Ž 1y m .

i G 0 Ž1y a .

iŽ1y m .

.

//

s O Ž n. .

350

EDITH COHEN

We bound the work of performing Algorithm 4.3. The work bound is obtained using the analysis done in Section 4.2. First note that Ý t g L GŽ< V Ž t .< 3 . s O Ž n., where LG ; TG are the leaves of TG . We use the implementation discussed in Remark 4.4. It follows that the work is bounded by O Ž< P
ž ž

?log Ž1y a .y1 n @

?log Ž1y a .y 1 n @

sk 2

Ý

jsk

Ž1 y a .

Ý

m

?log Ž1y a .y 1 n @

2

Ý

k Ž3 m y1 .

¡O Ž n . ¢O Ž n.

ks0

s ~O Ž n log n .

/

Ž Ž 1 y a . i n.

m

isj

3m

?log Ž1y a .y1 n @

sO n

Ž Ž 1 y a . n.

Ý

ks0

3m

j

/

if 3 m ) 1 if 3 m s 1 if 3 m - 1.

Remark 4.4 assumes a specific path doubling algorithm which considers all edges that are to be paired. In some cases, a faster doubling algorithm is available Že.g., for reachability problems we can use fast matrix multiplication algorithms.. We analyze the work bound of Algorithm 4.3 when the weights are such that a doubling step on a graph with k nodes can be performed in O Žlog k . time and O Ž k v . work Ž2 F v - 3.. It follows from the analysis in Section 4.2 that the work is bounded by ?log Ž1y a .y1 n @

Ý O Ž < S Ž t . < v log n q < B Ž t . < v log n . .

Ý ks0

tgT k

Consider 0 F k F ?log Ž1y a .y1 n @. We have m

Ý O Ž < S Ž t . < v . s O ž skr Ž Ž 1 y a . k n . Ž Ž 1 y a . k n .

tgT k

s OŽŽ1 y a .

k Ž vm y1 .

vm

/

n vm . .

ŽSince for all t g Tk , < S Ž t .< s O ŽŽŽ1 y a . k n. m . and the sum is maximized when the elements are as large as possible.. Hence,

Ý tgTG

v

< S Ž t. < s

¡O Ž n . ~ s O Ž n log n . ¢O Ž n. vm

?log Ž1y a .y1 n @

Ý

Ý

ks0

tgT k

< S Ž t. <

v

if vm ) 1 if vm s 1 if vm - 1.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

351

We bound Ý t g T kO Ž< BŽ t .< v .. Recall that for a node t g TG , Ži. BŽ t . consists of separator vertices of ancestors of t, and Žii. each occurrence of ¨ in S Ž t . contributes to the boundaries of at most two of t’s descendants at each level. Hence, Ý t g T k < BŽ t .< s O ŽÝ i F k si .. The sum Ý t g T kO Ž< BŽ t .< v . is maximized when the boundaries are as large as possible. It is easy to see that the choice Žin accordance with the restrictions above. of boundary sizes at Tk that maximizes the sum is such that for i F k, there are O Ž sirŽŽ1 y a . i n. m . s O ŽŽ1 y a .yi . nodes t g Tk , for which < BŽ t .< s O ŽŽŽ1 y a . i n. m .. It follows that

Ý O Ž < BŽ t . < v . s O Ý Ž 1 y a . yi Ž Ž 1 y a . i n .

ž

tgT k

vm

iFk

s O n vm

ž

Ý Ž 1 y a . i vmy1 Ž

.

iFk

¡O Ž n Ž 1 y a . s ~O Ž kn . ¢O Ž n . vm

k Ž vm y1 .

/

/ if vm - 1

.

if vm s 1 if vm ) 1.

vm

Therefore,

Ý

v

< BŽ t . < s O

tgTG

ž

?log Ž1y a .y1 n @

Ý

Ý

ks0

tgT k

¡O Ž n log n. n. ¢O Ž n log n.

s~O Ž n log vm

2

< BŽ t . < v

/

if vm - 1 if vm s 1 if vm ) 1.

It follows that the work performed by Algorithm 4.3 is bounded by O Ž n log 2 n., if vm - 1, by O Ž n log 3 n., if vm s 1, and by O Ž n vm log 2 n., otherwise. Recall that Algorithm 4.3 runs in O Žlog 2 n. time. Hence, the computation of the set Eq for the reachability problem can be performed in O Žlog 2 n. time and O Ž n log 3 n. work if vm s 1, and O Ž M Ž n m .log 2 n q n log 2 n. work otherwise. We bound the work performed by the algorithm of Section 4.1 Že.g., applying, sequentially for each layer, Algorithm 4.1 to the nodes of that layer.. The algorithm performs

Ý tgTG

< BŽ t . < 2 < S Ž t . < q < S Ž t . < 3

352

EDITH COHEN

work. We have that

Ý

< BŽ t . < 2 < S Ž t . < s

?log Ž1y a .y1 n @

O

Ý

tgTG

ks0

ž

m

Ž Ž 1 y a . k n. Ý

< BŽ t . < 2 .

/

tgT k

Using the derivation above we obtain that for 0 F k F ?log Ž1y a .y1 n @, O

ž

m

Ž Ž 1 y a . k n. Ý

¡O Ž n

< BŽ t . < 2

3m

s~O Ž n

k

Ž 1 y a . Ž 3m y 1.

1.5

kŽ1 y a .

3m

Ž1 y a .

¢O Ž n

/

tgT k

0.5k

mk

if 2 m - 1 if 2 m s 1

.

otherwise.

.

Hence, the work performed by the algorithm is

¡O Ž n . ~O Ž n log n . ¢O Ž n. 3m

if 3 m ) 1 if 3 m s 1 if 3 m - 1.

We bound the size of the set Eqs D t g T G ET . For each node t g TG , Et s S Ž t . = S Ž t . j BŽ t . = BŽ t .. Therefore, ?log Ž1y a .y1 n @

D

Eqs

ks0

D Ž S Ž t . = S Ž t . j BŽ t . = BŽ t . . .

tgT k

Consider a node t. If a vertex ¨ is in S Ž t ., then ¨ is a boundary vertex of both children of t. If ¨ g BŽ t . R S Ž t . then ¨ is a boundary vertex in exactly one of the children of t. If two vertices ¨ 1 , ¨ 2 are such that  ¨ 1 , ¨ 2 4 ; S Ž t . j BŽ t . for some node t g TG , then for some tX Žeither t or an ancestor of t . we have  ¨ 1 , ¨ 2 4 ; S Ž tX . j BŽ tX . and  ¨ 1 , ¨ 2 4 l S Ž tX . / B Žassume ¨ 1 g S Ž tX ... In addition, for some tY Žeither tX or an ancestor of tX . we have that ¨ 2 g S Ž tY .. Therefore, to bound the size of Eq, it suffices to bound for each node t, and each occurrence of a vertex ¨ in S Ž t ., the number of vertices that are in S Ž tX . in every descendant tX of t such that X ¨ g BŽ t .. Hence, q<


?log Ž1y a .y1 n @

F

sk

Ý ks0

ž

?log Ž1y a .y 1 n @

Ý jsk

sn

Ý ks0

ž

m

/

/

¡O Ž n . ~ . s O Ž n log n . ¢O Ž n. 2m

?log Ž1y a .y1 n @ 2m

j

O Ž Ž 1 y a . n.

OŽŽ1 y a .

k Ž2 m y1 .

if 2 m ) 1 if 2 m s 1 if 2 m - 1.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

353

We bound the number of edges < E <. Consider a node t g TG with children t 1 , t 2 . It is immediate that if an edge e is such that e g E Ž V Ž t .. R Ž E Ž V Ž t 1 .. j E Ž V Ž t 2 ..., then e g S Ž t . = S Ž t .. Denote by LG ; TG the leaves of TG . It follows that the number of edges is bounded by the log Ž1y a .y 1 n@ sum of Ý t g L G < V Ž t .< 2 s O Ž n. and Ý?ks0 Ý t g T k < S Ž t .< 2 . Using the considerations above we obtain that Ý t g L G < S Ž t .< 2 is O Ž n2 m . if 2 m ) 1, is O Ž n log n. if m s 1r2, and is O Ž n. if 2 m - 1. Hence, < E < s O Ž n q n2 m . if 2 m / 1 and O Ž n log n. if 2 m s 1.

6. PLANAR GRAPHS Planar graphs are known to have separators of size O Ž n0.5 . Žsee Lipton and Tarjan w14x. and hence, they fall into the class of graphs for which our analysis is applicable. Gazit and Miller w7x gave a deterministic O Žlog 3 n. time O Ž n1q e . work CRCW PRAM algorithms that computes an O Ž n0.5 . separator tree for a planar graph. It follows that shortest paths from s sources in a planar digraph can be found using O Žlog 3 n. time O Ž n1.5 . work preprocessing, and then O Žlog 2 n. time using O Ž sn log n. work. Hence, in O Žlog 3 n. time and O Ž n1.5 q sn log n. work. The preprocessing work bound for reachability is O Ž M Ž n0.5 .log 2 n.. Further improvements can be obtained for graphs where we are given a planar embedding such that all vertices lie on q faces. An efficient sequential algorithm for such graph was given by Frederickson w6x. A parallel version by Pantziou et al. w18x followed. We achieve further improvements for the parallel version by plugging our shortest-paths algorithm in one of the steps of the Pantziou et al. algorithm. We sketch the general ideas behind these algorithms. Frederickson w6x presented a sequential algorithm that computes a compact representation of shortest-paths and is based on a novel hammock decomposition technique. The graph is decomposed into O Ž q . subgraphs Ž‘‘hammocks’’. such that each hammock forms an outerplanar graph in the given embedding. The total size of the hammocks is O Ž n. and every hammock is attached to the rest of the graph through at most four vertices. Frederickson showed how to compute the hammock decomposition and a representation Žvia compact routing tables. of all-pairs shortest-paths within a hammock in linear time. The hammock decomposition and the paths information between the attachment vertices of each hammock are used to construct a graph GX with O Ž q . edges and vertices. The graph GX is produced by replacing every hammock in the hammock decomposition of G by a complete directed graph on four vertices Žthe attachment vertices of the hammock. with weights corresponding to dis-

354

EDITH COHEN

tances within the hammock. ŽIn fact, Frederickson considered a planar version of GX also with O Ž q . vertices.. All pairs shortest-paths information in GX can be computed in O Ž q 2 . time and be used to construct a representation of shortest-paths in the original graph, via compact routing tables, in O Ž qn. time. Frederickson also showed that shortest-paths information within hammocks and in the graph GX constitutes an alternate encoding of all-pairs shortest-paths in G. This encoding can be produced in only O Ž n q q 2 . time. Pantziou et al. w18x showed how to compute the hammock decomposition on a CREW PRAM in O Žlog n logU n. time using O Ž n. processors. They also showed that a representation Žcompact routing table. of all-pairs shortest-paths in an outerplanar graph can be performed on a CREW Pram in O Žlog 2 n. time using O Ž n log 2 n. work. Their algorithm performs the basic steps of Frederickson’s algorithm using their parallel procedures. The algorithm computes the hammock decomposition and all-pairs distances within each hammock. Following that, it produces the graph GX . The computation of all-pairs shortest-paths distances in GX can be performed in O Žlog 2 q . time using O Ž q 3 . work Žusing the algorithm of w8x.. The all-pairs shortest-path information on GX and individually in each hammock is used by Pantziou et al. to produce a compact routing table of all-pairs shortest-paths in G in O Žlog 2 n. time using O Ž nq log 2 n. work. The resulting bounds Žon a CREW PRAM. are O Žlog 2 n. time and O Ž nq log 2 n q q 3 . work for all-pairs shortest-paths computation and O Ž nq log 2 n q M Ž q .log n. work for transitive closure information. Djidjev et al. w4x gave an O Žlog 2 n. time O ŽŽ n q q 3 .log 2 n q k log n. work algorithm to compute distances between k specified pairs of vertices. Their algorithm consists of O ŽŽ n q q 3 .log 2 n. preprocessing and then can answer a query about a specific pair in O Žlog n. work. The preprocessing work bound for reachability is O ŽŽ n q M Ž q ..log 2 n.. Their algorithm is based on the parallel hammock decomposition and on a separator decomposition of outerplanar graphs that makes it possible to compute distances efficiently after O Ž n log 2 n. preprocessing work. We can improve over the above bounds as follows. Observe that the graph GX is ‘‘almost’’ planar. It is easy to produce a planar graph GY such that a k 0.5-separator decomposition of GY corresponds to a k 0.5-separator decomposition of GX . The graph GY can be obtained from GX by replacing every hammock by a circle of size 4 Žwhich corresponds to the four attachment vertices in the order they appear in the corresponding outerplanar graph. and a middle vertex connected to the attachment vertices. A separator of GY can be transformed to a separator of G by replacing each middle vertex by the four attachment vertices of the corresponding ham-

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

355

mock. It is easy to verify that a k 0.5-separator decomposition of GY corresponds to a k 0.5-separator decomposition of GX . We use the planar separator algorithm of Gazit and Miller w7x to compute a separator decomposition tree of GY . It follows that our algorithm can be used to compute shortest-paths in GX . We first compute a k 0.5-separator decomposition tree of GX Žwhich can be obtained in O Žlog 3q . time and O Ž q 1q e . work on a CRCW PRAM w7x and hence in O Žlog 4 q . time on a CREW PRAM.. Combining this with our algorithm we obtain that shortest-paths from s sources to all other vertices in GX can be computed in O Žlog 4 q . time using O Ž q 1.5 q sq log q . work. Reachability from s sources can be computed using O Ž M Ž q .log 2 q q sq log q . work. Hence, all-pairs shortestpaths in GX can be obtained using O Ž q 2 log q . work. It follows that the alternate encoding of shortest-paths suggested by Frederickson w6x Žusing all-pairs shortest-paths information in each hammock and in GX . can be computed in O Ž q 2 log q q n log 2 n. work and O Žlog 4 q q log 2 n. time on a CREW PRAM. Given the above information and an appropriate representation of distances in each hammock Žsee Djidjev et al. w4x., we can produce the distance between two given vertices as follows: In constant work if the vertices belong to different hammocks and in O Žlog n. work and time if the vertices are in the same hammock. Hence, distances between k specified pairs of vertices can be computed in O Žlog 4 q q log 2 n. time using O Ž q 2 log q q n log 2 n. preprocessing work and O Ž k log n. additional work. The resulting bounds for a representation Žvia a compact routing table. of all-pairs shortest-paths in G are O Žlog 4 q q log 2 n. time and O Ž nq log 2 n. work on a CREW PRAM. Shortest-paths trees from s sources can be computed on a CREW PRAM in O Žlog 4 q q log 2 n. time using O Ž n log 2 n q sŽ n q q log q . q q 1.5 . work. We sketch how the latter bounds are achieved. We compute, for each source u, single-source shortest-paths in GX from the 4 attachment vertices of the hammock containing u. We also compute, for each hammock, distances and shortest-paths information in the subgraph induced by each hammock, from the attachment vertices to all other vertices in the hammock Žthis information can be produced in O Žlog 2 n. time and O Ž n log 2 n. work.. Given the above, a shortest-path tree from u can be computed using O Ž n. work. As for finding an embedding of a planar graph with a small number q g n of faces, Frederickson w6x showed that the problem of finding the minimum q is NP-complete. He provided, however, a sequential algorithm that finds an embedding where the number of faces is a constant factor away from the minimum possible. Pantziou et al. w18x provided a parallel version of the approximation algorithm that uses O Ž n. processors and runs

356

EDITH COHEN

in O Žlog 6 n. time on a CREW PRAM. The latter can be combined with the above algorithm when a planar embedding is not provided with the input. ACKNOWLEDGMENTS The author thanks Noga Alon, Andrew Goldberg, Seffi Naor, and Mario Szegedy for helpful discussions, Christos Zaroliagis for many comments and references, and John Reif for comments, references, and suggesting to reduce the time bound by a factor of O Žlog n..

REFERENCES 1. E. Cohen and N. Megiddo, Improved algorithms for linear inequalities with two variables per inequality, in ‘‘Proceedings 23rd Annual ACM Symposium on Theory of Computing,’’ pp. 145]155, Assoc. Comput. Mach., New York, 1991. SIAM J. Comput. 23 Ž1994., 1313]1347. 2. D. Coppersmith and S. Winograd, Matrix multiplication via arithmetic progressions, J. Symbolic Comput. 9 Ž1990., 215]280. 3. T. Cormen, C. Leiserson, and R. Rivest, ‘‘Introduction to Algorithms,’’ McGraw]Hill, New York, 1990. 4. H. N. Djidjev, G. E. Pantziou, and C. D. Zaroliagis, Computing shortest-paths and distances in planar graphs, in ‘‘Proceedings 18th ICALP,’’ Lecture Notes on Computer Science, C510, pp. 327]339, Springer-Verlag, Berlin, 1991. 5. G. N. Frederickson, Fast algorithms for shortest paths in planar graphs with applications, SIAM J. Comput. 16 Ž1987., 1004]1022. 6. G. N. Frederickson, Planar graph decomposition and all pairs shortest paths, J. Assoc. Comput. Mach. 38 Ž1991., 162]204. 7. H. Gazit and G. L. Miller, A deterministic parallel algorithm for finding a separator in planar graphs, Technical Report CMU-CS-91-103, Carnegie-Mellon University, 1991. 8. Y. Han, V. Pan, and J. Reif, Efficient parallel algorithms for computing all pair shortest paths in directed graphs, in ‘‘Proceedings 4th annual ACM Symposium on Parallel Algorithms and Architectures,’’ pp. 353]362, Assoc. Comput. Mach., New York, 1992. 9. J. JaJa, ´ ´ ‘‘Parallel Algorithms,’’ Addison-Wesley, Reading, MA, 1992. 10. M-Y Kao and P. N. Klein, Towards overcoming the transitive-closure bottleneck: Efficient parallel algorithms for planar digraphs, in ‘‘Proceedings 22nd Annual ACM Symposium on Theory of Computing,’’ pp. 181]192, Assoc. Comput. Mach., New York, 1990. 11. M-Y Kao and G. E. Shannon, Local reorientation, global order, and planar topology, in ‘‘Proceedings 21st Annual ACM Symposium on Theory of Computing,’’ pp. 286]296, Assoc. Comput. Mach., New York, 1989. 12. P. N. Klein and S. Sairam, A linear-processor polylog-time algorithm for shortest paths in planar graphs, in ‘‘Proceedings 34th IEEE Annual Symposium on Foundations of Computer Science,’’ pp. 259]270, IEEE Press, New York, 1993. 13. A. Lingas, Efficient parallel algorithms for path problems in planar directed graphs, in ‘‘SIGAL,’’ Lecture Notes in Computer Science 450, pp. 447]457, 1990. 14. R. J. Lipton and R. E. Tarjan, A separator theorem for planar graphs, SIAM J. Appl. Math. 36 Ž1979., 177]189. 15. G. L. Miller, S-H Teng, and S. A. Vavasis, A unified geometric approach to graph separators, in ‘‘Proceedings 32nd IEEE Annual Symposium on Foundations of Computer Science, pp. 538]547, IEEE Press, New York, 1991.

SHORTEST PATHS IN GRAPHS WITH SEPARATORS

357

16. V. Pan and J. Reif, Fast and efficient solution of path algebra problems, J. Comput. System Sci. 38 Ž1989., 494]510. 17. V. Pan and J. Reif, The parallel computation of minimum cost paths in graphs by stream contraction, Inform. Process. Lett. 40 Ž1991., 79]83. 18. G. E. Pantziou, P. G. Spirakis, and C. D. Zaroliagis, Efficient parallel algorithms for shortest paths in planar digraphs, BIT 32 Ž1992., 215]236. 19. N. Robertson and P. D. Seymour, Graph minors. II. Algorithmic aspects of tree-width, J. Algorithms 7 Ž1986., 309]322.