14
Theoretical Computer Science 465 (2012) 35–48 Contents lists available at SciVerse ScienceDirect Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs Linear time algorithms for two disjoint paths problems on directed acyclic graphs Torsten Tholey Institut für Informatik, Universität Augsburg, 86135 Augsburg, Germany article info Article history: Received 15 June 2011 Received in revised form 3 July 2012 Accepted 25 September 2012 Communicated by G. Italiano Keywords: Graph algorithms Directed acyclic graphs Disjoint paths 2-disjoint paths problem abstract We present an algorithm that, given two vertices s 1 and s 2 of a directed acyclic graph, constructs in linear time a data structure using linear space that, for each pair (u,v) of two vertices u and v, in constant time can output a tuple (s 1 , t 1 , s 2 , t 2 ) with {t 1 , t 2 }={u,v} such that there are two disjoint paths p 1 , from s 1 to t 1 , and p 2 , from s 2 to t 2 , if such a tuple exists. The data structure is simpler than such a data structure for general directed graphs that can be obtained from results of Georgiadis and Tarjan. Disjoint can mean vertex- as well as edge-disjoint. As an application and main result we show that the data structure can be used to solve the 2-disjoint paths problem on directed acyclic graphs optimally, i.e., in linear time. © 2012 Elsevier B.V. All rights reserved. 1. Introduction This paper can be considered as the full version of [32]. However, we present improved results by now solving all problems on directed acyclic graphs in [32] optimally, i.e., in linear time. In general, the problem of finding disjoint paths is one of the fundamental problems in graph theory with many applications concerning network reliability, routing problems, VLSI-design, etc. Such problems have been studied extensively and a variety of efficient algorithms is known for undirected graphs (cf. [7,8]), whereas much less is known about finding disjoint paths on directed graphs. We focus on the problem of finding two edge- or vertex-disjoint paths starting from two fixed vertices s 1 , s 2 and leading to two vertices u and v. Using so-called dominator trees one can easily answer the following queries for each pair u,v of vertices in constant time. VertexDisjoint(s 1 , s 2 , u,v): Decide whether there are two vertex-disjoint paths p 1 and p 2 with {s 1 , s 2 } being the start points and {u,v} being the endpoints of the paths. EdgeDisjoint(s 1 , s 2 , u,v): Decide whether there are two edge-disjoint paths p 1 and p 2 with {s 1 , s 2 } being the start points and {u,v} being the endpoints of the paths. However, in practical applications, one often wants to know which of the two vertices s 1 and s 2 is connected to which of u and v. For example, it is obvious that in the VLSI-design it is of great importance to connect all pins with their correct counterparts. Therefore, in the k-disjoint paths problem we are given k pairs (s 1 , t 1 ), (s 2 , t 2 ), and (s k , t k ) of vertices in a graph G, often denoted as a tuple (G, s 1 ,..., s k , t 1 ,..., t k ), and want to output disjoint paths p i from s i to t i in G (i ∈{1,... k}) if such paths exist. We distinguish between the k-vertex-disjoint paths problem (k-VDPP) and the k-edge-disjoint paths problem (k-EDPP) in the obvious way. Unfortunately, even the decision version of the 2-VDPP and the 2-EDPP – in which we only test the existence of a solution – is NP -hard on general directed graphs. This is the reason why we also want to consider the following weaker queries: Tel.: +49 821 598 2384. E-mail address: [email protected]. 0304-3975/$ – see front matter © 2012 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2012.09.025

Linear time algorithms for two disjoint paths problems on directed acyclic graphs

  • Upload
    torsten

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

Theoretical Computer Science 465 (2012) 35–48

Contents lists available at SciVerse ScienceDirect

Theoretical Computer Science

journal homepage: www.elsevier.com/locate/tcs

Linear time algorithms for two disjoint paths problems on directedacyclic graphsTorsten Tholey ∗

Institut für Informatik, Universität Augsburg, 86135 Augsburg, Germany

a r t i c l e i n f o

Article history:Received 15 June 2011Received in revised form 3 July 2012Accepted 25 September 2012Communicated by G. Italiano

Keywords:Graph algorithmsDirected acyclic graphsDisjoint paths2-disjoint paths problem

a b s t r a c t

We present an algorithm that, given two vertices s1 and s2 of a directed acyclic graph,constructs in linear time a data structure using linear space that, for each pair (u, v) of twovertices u and v, in constant time can output a tuple (s1, t1, s2, t2) with {t1, t2} = {u, v}

such that there are two disjoint paths p1, from s1 to t1, and p2, from s2 to t2, if such a tupleexists. The data structure is simpler than such a data structure for general directed graphsthat can be obtained from results of Georgiadis and Tarjan. Disjoint can mean vertex- aswell as edge-disjoint. As an application and main result we show that the data structurecan be used to solve the 2-disjoint paths problem on directed acyclic graphs optimally, i.e.,in linear time.

© 2012 Elsevier B.V. All rights reserved.

1. Introduction

This paper can be considered as the full version of [32]. However, we present improved results by now solving allproblems on directed acyclic graphs in [32] optimally, i.e., in linear time. In general, the problem of finding disjoint paths isone of the fundamental problems in graph theory with many applications concerning network reliability, routing problems,VLSI-design, etc. Such problems have been studied extensively and a variety of efficient algorithms is known for undirectedgraphs (cf. [7,8]), whereas much less is known about finding disjoint paths on directed graphs. We focus on the problem offinding two edge- or vertex-disjoint paths starting from two fixed vertices s1, s2 and leading to two vertices u and v. Usingso-called dominator trees one can easily answer the following queries for each pair u, v of vertices in constant time.

• VertexDisjoint(s1, s2, u, v): Decide whether there are two vertex-disjoint paths p1 and p2 with {s1, s2} being the startpoints and {u, v} being the endpoints of the paths.

• EdgeDisjoint(s1, s2, u, v): Decidewhether there are two edge-disjoint paths p1 and p2 with {s1, s2} being the start pointsand {u, v} being the endpoints of the paths.

However, in practical applications, one often wants to know which of the two vertices s1 and s2 is connected to whichof u and v. For example, it is obvious that in the VLSI-design it is of great importance to connect all pins with their correctcounterparts. Therefore, in the k-disjoint paths problemwe are given k pairs (s1, t1), (s2, t2), and (sk, tk) of vertices in a graphG, often denoted as a tuple (G, s1, . . . , sk, t1, . . . , tk), and want to output disjoint paths pi from si to ti in G (i ∈ {1, . . . k})if such paths exist. We distinguish between the k-vertex-disjoint paths problem (k-VDPP) and the k-edge-disjoint pathsproblem (k-EDPP) in the obvious way. Unfortunately, even the decision version of the 2-VDPP and the 2-EDPP – in whichwe only test the existence of a solution – is N P -hard on general directed graphs. This is the reason why we also want toconsider the following weaker queries:

∗ Tel.: +49 821 598 2384.E-mail address: [email protected].

0304-3975/$ – see front matter© 2012 Elsevier B.V. All rights reserved.doi:10.1016/j.tcs.2012.09.025

Page 2: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

36 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

• VertexDisjointTuple(s1, s2, u, v): Return a tuple (s1, s2, t1, t2) of vertices with {t1, t2} = {u, v} such that there are twovertex-disjoint paths p1, from s1 to t1, and p2, from s2 to t2, if such a tuple exists.

• EdgeDisjointTuple(s1, s2, u, v): Return a tuple (s1, s2, t1, t2) of vertices with {t1, t2} = {u, v} such that there are twoedge-disjoint paths p1, from s1 to t1, and p2, from s2 to t2, if such a tuple exists.

• VertexDisjointPaths(s1, s2, u, v): For the tuple (s1, s2, t1, t2) output by the query VertexDisjointTuple(s1, s2, u, v),return vertex-disjoint paths p1 : s1 → t1 and p2 : s2 → t2.

• EdgeDisjointPaths(s1, s2, u, v): For the tuple (s1, s2, t1, t2) output by the query EdgeDisjointTuple(s1, s2, u, v), returntwo edge-disjoint paths p1 : s1 → t1 and p2 : s2 → t2.

Of course such queries can be answered by explicitly constructing disjoint paths connecting the vertices in {s1, s2} tothe vertices in {t1, t2}. However, this may take too much time if we have to answer a large number of such queries. In suchcases, after a linear preprocessing time, we would like to support such queries output-sensitive, i.e., linear in the size of theoutput. In our case this means that we have to support VertexDisjointTuple and EdgeDisjointTuple in constant time andVertexDisjointPaths and EdgeDisjointPaths in O(|p1| + |p2| + 1) time. Such a data structure can be easily obtained byusing independent spanning trees as it will be discussed in the proof of Lemma 6 in Section 3. However, a new simpler datastructure for directed acyclic graphs is presented that makes this paper more self-contained. As usual, we use dag as anabbreviation for directed acyclic graph.

As application of a data structure supporting the above queries and main result of this paper we present a linear timealgorithm for solving the 2-VDPP on dags. The importance of constructing disjoint paths on dags is based on the fact thatdisjoint paths in directed acyclic graphs can be used to solve several scheduling problems on general graphs:

Assume that we are given a traffic network modeled by a graph G = (V , E) whose edges (u, v) represent the possibilityto travel from u to v within one time unit (or also in the reverse direction from v to u if G and its edges are undirected).For simplicity, in the case of an undirected graph, let us assume that each edge (u, v) in our graph represents exactly tworailways between u and v, where the first one may only be used to travel from u to v and the second one is only used forthe reverse direction. If our traffic network represents a railway system in which we want to run trains between severallocations, then in a realistic scenario two trains may be allowed to use the same railway (in the same direction) to travelfrom u to v but not between the same time units. This means that during the same time unit we are allowed to send onetrain from u to v and another from v to u but not two trains from u to v. For finding a scheduling of trains, we could replaceG by a graph G∗ whose node set is V × {0, . . . , j} for a j ∈ N, where a node (v, t) represents the node v of G after t timeunits. Each edge of G∗ should be of the form ((u, t), (w, t + 1)) and represents the possibility to choose the railway fromu to w between the beginning of the t-th and the (t + 1)-th time unit. If we want to find out, for some k ∈ N and someintegers t1, . . . , tk, t∗1 , . . . , t

k , whether it is possible, for each i ∈ {1, . . . , k}, to send a train ri after ti-time units from ui tovi such that it arrives at vi exactly after t∗i -time units, we can solve this problem by finding k pairwise disjoint paths in thedirected acyclic graph G∗ with the i-th paths (i ∈ {1, . . . , n}) leading from (ui, ti) to (vi, t∗i ). Simple variants of the problemin which, for example, we want to arrive at vi at a time t∗i or earlier instead of reaching exactly at the t∗i -th time unit can bealso modeled by finding disjoint paths in directed acyclic graphs. Based on similar ideas, Schrijver described in [27] a morecomplex airplane routing problem that can be solved by finding a solution of the k-EDPP on dags.

Previous results: As alreadymentioned, by the classical network flow techniques VertexDisjointPaths and EdgeDisjoint-Paths can be supported in O(m + n) time, where here and in the following, n should denote the number of vertices andm the number of edges of the graph under consideration. This implies that one can also support VertexDisjointTuple andEdgeDisjointTuple as well as the simpler queries VertexDisjoint and EdgeDisjoint at the beginning of this section in lineartime.We nextwant to give an overview over data structures answering the above queries for a larger number of input tuplesmore efficiently.

For undirected graphs, Di Battista et al. [7] have shown that in a preprocessing time of size O(m + n) (if k = 2) or O(n2)(if k = 3) one can construct a data structure that can test the existence of k internally vertex-disjoint paths between eachpair of two vertices in constant time and output k such paths, if they exist, in a time linear in the number of the verticesvisited by these paths. Di Battista et al. also gave an overview over other data structures supporting the above queries fork ≥ 4. A list of results concerning edge-disjoint paths between pairs of vertices can be found in the paper of Dinitz andWestbrook [8].

For directed graphs and two fixed vertices s1 and s2, as already mentioned and as we will see in Section 3, dominatortrees can be used to support the queries VertexDisjoint(s1, s2, u, v) and Edge-Disjoint(s1, s2, u, v) for each pair (u, v) inconstant time. Alstrup et al. [2] could show by correcting some details of an algorithm of Harel [15] that a dominator tree canbe constructed in O(m+ n) time. However their algorithm is based on complicated data structures using bit manipulations.A simpler algorithm still running in linear time is from Buchsbaum et al. [5,6].

For a weighted directed graph with a fixed vertex s, Suurballe and Tarjan [30] presented a data structure with apreprocessing time of O(n + m log2+m/n n) which, for each t ∈ V , can test in constant time whether there are two disjointpaths from s to t , and, if so, can output two such paths of minimal total weighted length in a time linear in the number ofvertices visited by the paths. The result holds for both, vertex- and edge-disjoint paths. The preprocessing time of such a datastructure can be improved toO(n log n+m) as shown by Fredman and Tarjan [11]. Georgiadis presented in [12] a linear timealgorithm that, for a vertex r in a directed graph G = (V , E), constructs two spanning trees T1 and T2, and an integer array πwith index set V having the following property: If π [v] < π[u] holds for two vertices u, v ∈ V , then the tree paths from r to

Page 3: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 37

v in T1 and from r to u in T2 define two paths that among all pairs of paths p1 : r → u and p2 : r → v in G share a minimalnumber of common vertices. If π [v] < π [u] does not hold, the paths from r to v in T2 and from r to u in T1 define pathsp1 : r → u and p2 : r → v with a minimal number of common vertices. For the case u = v this property was also shownin [13]. Further improvements for the construction of such trees especially for the case of dags can be found in a recent paperof Georgiadis and Tarjan [14]. Since this paper appeared during the publication process of this paper not all details can beincluded. It is easy to see that the trees described above can be used directly to support the queryVertexDisjointPaths (apartfrom the relation to VertexDisjointTuple). With some further slightmodifications, discussed in Section 3, the data structurecan be also used to support the additional queries VertexDisjointTuple, EdgeDisjointTuple, and EdgeDisjointPaths.

Concerning the k-VDPP, the first polynomial time algorithms for the k-vertex-disjoint paths problem on undirectedgraphs were given by Ohtsuki [21], Seymour [28], Shiloach [29], and Thomassen [35], for k = 2, and by Robertson andSeymour [26] for general but fixed k.

More precisely, Seymour in [28] considered the decision version of the problem. However, there is a polynomial timereduction from this version of the k-VDPP to the original one. Even though there are several algorithms improving therunning time of Robertson and Seymours algorithm, all algorithms known for the k-EDPP and the k-VDPP for k ≥ 3 are faraway from being practical because of very huge constants hidden in the big-O-notation. If we let α be the inverse Ackermanfunction as defined in [31], the currently best known published asymptotic time bounds for the 2-disjoint paths problemon undirected graphs are O(m + nα(n, n)) for the 2-VDPP and O(m + n log n) for the 2-EDPP [33,34], but they seem to beimproved to the best possible running time O(m + n) by an unpublished paper of Kapadia et al. [17] mentioned in [18]. Forthe k-VDPP on general graphs Perković and Reed claimed in [22] a running time of O(n2) but the full details are omitted.Probably this running time should also hold for the k-EDPP. A quadratic time algorithm for the k-VDPP and the k-EDPP withfull details is recently given by Kawarabayashi et al. [18].

For directed graphs, the decision versions of the k-EDPP and the k-VDPP are N P -complete, even for k = 2, as shown byFortune et al. [10]. In [23] Perl and Shiloach presented an O(mn)-time algorithm for solving the 2-VDPP and the 2-EDPP ondags. Fortune et al. [10] generalized this result of Perl and Shiloach to an O(mnk−1)-time algorithm for the k-VDPP on dagsfor all k ≥ 2. By a line graph reduction this also implies a running time of O((m + n)k−1n2) for the k-EDPP. Later Lucchesiand Giglio in [20] described a linear time reduction from the decision version of the 2-VDPP on dags to the decision versionof the 2-VDPP on undirected graphs. They also presented a corollary from which it follows that, if during the reduction theinstance was not explicitly excluded as non-solvable, there is always a solution of the 2-VDPP on the undirected graph afterthe reduction if this graph is non-planar. The k-VDPP on undirected planar graphs is solvable in linear time as shown byPerl and Shiloach [23] for k = 2 and Reed et al. [24,25] for every fixed k ∈ N. Therefore, the decision version of the 2-VDPPon dags is also solvable in linear time which was not explicitly mentioned in the paper of Lucchesi and Giglio. However, nolinear time algorithm was known to construct paths solving the 2-VDPP on dags. In [32] which can be considered as theconference version of this paper, the running time of the 2-VDPP was improved from O(mn) to O(m(log2+m/n n) + n log3 n).This time bound holds also for the 2-EDPP on dags by a reduction to the 2-VDPP [32].

New results. After some preliminary definitions in Section 2, we present data structures with a construction time ofO(m+n) in Section 3 that, for fixed vertices s1 and s2 in a dag, supports the queriesVertexDisjointTuple, EdgeDisjointTuple,VertexDisjointPaths, and EdgeDisjointPaths for all instances (s1, s2, u, v) output-sensitive. The first one for generaldirected graphs is obtained after some slightmodifications from a result of Georgiadis [12] and in this sense is not really new.The second new one is a data structure for dags that should be simpler than the first one.We then show in Section 4 how thisdata structures can be used to solve the 2-VDPP on dags in O(m+ n) time. Finally, in Section 5 by a simple reduction we canconclude that the 2-EDPP on dags can be also solved in linear time. In contrast to the conference version of this paper, ourresults are now based on dominator trees. This helps to remove the logarithmic factors from the results in the conferenceversion and to greatly simplify the algorithms for the k-VDPP and the k-EDPP.

2. Preliminaries

Paths referred to in this paper are always simple paths, i.e., paths on which no vertex appears more often than once. Ifa vertex v or an edge e is included in a path p, we write v ∈ p or e ∈ p, respectively. For a path p and vertices a, b ∈ p,we let p[a, b] be the sub-path of p or of the reverse of p from a to b. p(a, b], p[a, b), and p(a, b) will denote the sub-pathsof p[a, b] starting in the vertex immediately after a, or ending in the vertex immediately before b, or both, respectively. Wewrite p : a → b to say that p is a path that starts in a and ends in b. For a path p : a → b the vertices on p(a, b) are called theinner vertices of p. A set P of paths is called internally vertex-disjoint if no inner vertex of a path p ∈ P is a vertex of anotherpath in P . This means that two internally vertex-disjoint paths may have up to two vertices in common, but then they mustbe endpoints on both paths. The length of a path p is the number of edges visited by p and denoted by |p|. A vertex w isreachable from a vertex v if there is a path from v to w. Finally, for two paths p1 and p2 with the last vertex of p1 being thefirst vertex of p2, p1 ◦ p2 is the concatenation of the two paths.

As for paths, given a tree T = (V , E) and a vertex v or an edge e, we write v ∈ T if v ∈ V and e ∈ T if e ∈ E. Let r bethe root of a tree T . Then we denote the father of a vertex v = r by fT (v) and, for simplicity, we let fT (r) = r . A descendantof a vertex v in T is a vertex w for which there is a path from v to w in T being of length zero or not visiting fT (v). Vertexw is a proper descendant if additionally v = w holds. A vertex v is a (proper) ancestor of a vertex w in T , if and only if w is a

Page 4: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

38 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

(proper) descendant of v. The lowest common ancestor of two vertices v, w ∈ T is the vertex of farthest distance from r inT that is an ancestor of both, v and w. It is denoted by lcaT (v, w).

Harel and Tarjan [16] have shown that, for each tree T = (V , E), it is possible to construct a lowest common ancestor datastructure in linear time, i.e., a data structure which, for each pair of vertices v, w ∈ T , can output lcaT (v, w) in constant time.

A topological numbering τ of the vertices of a dag G = (V , E) is an injective mapping from V to {1, . . . , n} such thatτ(v) < τ(w) holds for each pair (v, w) of vertices for which there is a path from v to w. It is well known that, for each dagG, a topological numbering can be computed in linear time.

3. Dominators

For testing the existence of disjoint paths it is useful to know which vertices cannot be avoided. More precisely, for avertex v reachable from a vertex s, we say that a vertex u dominates v with respect to s if every path from s to v includesu. Vertex u is also called the immediate dominator of v with respect to s if additionally every vertex w = v dominating vwith respect to s also dominates u with respect to s. We then also write u = idoms(v) since the immediate dominator iswell-defined:

Lemma 1. If there is a path from a vertex s to a vertex v in a directed graph G, then v has a unique immediate dominator withrespect to s in G.

For a proof, see [1,19]. Lemma 1 shows that, for a fixed vertex r in a directed graph G, the vertices v reachable from rinduce a tree T if we take r as the root of T and define fT (v) = idomr(v) for all v = r . We call this tree the dominator tree ofr (for G). The tree in the middle of Fig. 2 shows the dominator tree of the vertex r = 2 of the graph shown on the left side ofFig. 2.

We summarize some useful properties concerning dominator trees and vertices dominating other vertices:

Lemma 2. Let p be a path in a directed graph with its first vertex being reachable from a vertex r and its last vertex w beingdominated by a vertex u /∈ p with respect to r. Then all vertices of p are dominated by u with respect to r.

Proof. If the lemma does not hold, there is a vertex x = w on p for which there is a path q : r → x not including u. Thenu /∈ q ◦ p[x, w] contradicts the fact that w is dominated by uwith respect to r . �

Corollary 3. Let u be a vertex of a dominator tree T for a directed graph G. Then, for each path p in G leading from a descendantof a child v of u in T to a proper descendant w of u in T and not containing any child of u different from v, all vertices of p aredescendants of v in T .

Proof. Let r be the root of T and choose v′ as the child of u that is an ancestor of w. If v = v′, Lemma 2 implies that allvertices of p are dominated by v′ with respect to r and hence are descendants of v′. Since this cannot be true for the firstvertex v of p, we must have v = v′. Then by Lemma 2 all vertices of p(v, w] are dominated by v and hence are descendantsof v. �

Corollary 4. Let u be a vertex in a dominator tree T for a directed graph G and let p1 and p2 be paths in G leading from childrenof u in T to descendants of u in T . Then the paths are vertex-disjoint if and only if no child of u in T is a vertex of both, p1 and p2.

Proof. By Lemma 2 all vertices of p(u, w] are dominated by u and hence are descendants of u. By this fact and by applyingCorollary 3 to the sub-paths of p between two children of u, for i ∈ {1, 2}, path pi consists only of descendants of the childrenv of u with v ∈ pi. Hence p1 and p2 are disjoint if and only if no child of u is part of both, p1 and p2. �

Corollary 4 shows that we can read of the disjointness of two paths starting in children of a vertex u from the childrenof u visited by the paths. This important observation helps to show in the proof of Lemma 6 that, for two descendants w1and w2 of different children of a vertex u in a dominator tree, there are internally vertex-disjoint paths p1 : u → w1 andp2 : u → w2. For determining such paths efficiently – as also promised in Lemma 6 – we have to efficiently determine thechildren of u being ancestors of w1 and w2, respectively:

Lemma 5. Let T be a tree with n ≥ 1 vertices. Then one construct in O(n) time a data structure using O(n) space that supportsthe following query in constant time for each pair of vertices u and w with w being a descendant of u.

• ChildT (u, w): Return the child v of u that is an ancestor of w if w = u or u if w = u.

Proof. This proof follows the classical Euler-tour technique usually used to reduce lowest common ancestor queries to socalled range minima queries (compare, e.g., [3,4]). Let T be the directed graph obtained from T by replacing each edge withendpoints v and w by directed edges (v, w) and (w, v). Let p be an Euler tour of T starting in the root r of T that we obtainfrom a depth-first search on T starting in r and visiting each edge twice, the first time in a forward direction from a vertexto one of its children and later, in a backtracking step, in reverse direction (see Fig. 1). Let v1, . . . , v2n−2 be the vertices of pin the order in which they appear on p, where some vertices of T may appear several times on p. Assume that we store in anarray of length 2n−2 at position a[i] the depth of vi in T . Assign to each vertexw a number loc(w) such that vloc(w) is the lastoccurrence of w in v1, . . . , v2n−2. Let us now consider a vertex w that is a proper descendant of a vertex u. If j is the smallest

Page 5: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 39

Fig. 1. A tree T with root a consisting of the gray edges and the Euler tour on T , where the edges are visited in the order of increasing edge numbers.

index in {loc(w), . . . , loc(u)} with a[j] = min{a[i] | loc(w) ≤ i ≤ loc(u)}, then vj−1 is the child of u being a descendant ofw. So all we need is to construct a data structure using O(n) space in O(n) time that, for an array a of length O(n), allows,for each pair (i, k), to determine the smallest index j ∈ {i, . . . , k} with a[j] = min{a[i], . . . , a[k]} in constant time. Such adata structure is called a range minima data structure and a practically efficient O(n)-time construction of a range minimadata structure using O(n) space can be found for example in [3]. More precisely, the classical range minima data structurereturns an index j ∈ {i, . . . , k} with a[j] = min{a[i], . . . , a[k]} which is possibly not the smallest index with this property.For obtaining the smallest index one simply have to replace the entries a[j] by (a[j], j) and use the lexicographical order. �

As mentioned, we want to use dominator trees to construct disjoint paths. Let us call two paths p1 : s1 → t1 andp2 : s2 → t2 maximal disjoint if, among all pairs of paths p1 : s1 → t1 and p2 : s2 → t2, they have a lowest number ofcommon vertices, and, among all such pairs, a lowest number of common edges.We show that a dominator tree T of a vertexr can be used to support the following operations for all vertices w1 and w2 reachable from r but being different from r .

• Edges(r, w1, w2): Output a tuple (f1, f2, l1, l2) of vertices such that there are maximal disjoint paths p1 : r → w1 andp2 : r → w2 with (r, fi) being the first and (li, wi) being the last edge of pi (i ∈ {1, 2}).

• Paths(r, w1, w2): Output twomaximal disjoint paths p1 : r → w1 and p2 : r → w2 with (r, fi) being the first and (li, wi)being the last edge of pi (i ∈ {1, 2}), where (f1, f2, l1, l2) := Edges(r, w1, w2).

Intuitively, Edges is used to predict the first edge of the path output by Paths and ending with the edge (l1, w1). This is auseful operation if in some applications the paths output by Paths should only be constructed if the path ending in (l1, w1)starts with the correct edge, say (r, f1). If this is not the case, we do not want to loose too much time for constructing pathsthat will not be needed. In particular, this is the key idea that in Section 4 helps to reduce the running time for the 2-disjointpaths problem. Note that without the prediction of the first and the last edges there is a much simpler data structure thatcan test whether there are two internally vertex-disjoint paths from a vertex r to two different verticesw1 andw2. As part ofthe next lemma we also show the already well-known fact that the common vertices of two maximal disjoint paths exactlyexists of the vertices on the tree path from r to lcaT (w1, w2) in the dominator tree T of r . Hence there are two internallyvertex disjoint paths p1 : r → w1 and p2 : r → w2 if and only if r = lcaT (w1, w2). This can be easily tested with a lowestcommon ancestor data structure in O(1) time. It is also easy to decide whether there are edge-disjoint paths p1 : r → w1and p2 : r → w2 as shown in the proof of Theorem 7. However, even the more complicated operations Edges and Paths canbe supported output-sensitive as shown by the next lemma.

Lemma 6. Let r be a vertex of a directed graph G = (V , E), n = |V |, andm = |E|. Then one can construct in O(m+n) time a datastructure using O(n) space supporting Edges(r, w1, w2) and Paths(r, w1, w2) output-sensitive. Moreover, one can construct thedata structure such that edges of the paths returned by Paths all belong to a subset E ′

⊆ E which is pre-computable in O(m + n)time and for which indegG′(v) ≤ 2 holds for all v ∈ V in the subgraph G′

= (V , E ′) of G. Finally, if w1 = r and w2 = rare vertices of the dominator tree T of r, the common vertices of the paths returned by Paths(r, w1, w2) consist exactly of theancestors of lcaT (w1, w2) in T .

Proof. We assume w.l.o.g. that all vertices in G are reachable from r since the remaining vertices can be excluded as notbeing part of a solvable instance after a simple depth-first search.

As mentioned in the introduction, it was shown by Georgiadis in [12] that one can construct in linear time two spanningtrees T1 and T2, called independent spanning trees, and an integer array π with index set V having the following property:Two paths p1 : r → w1 and p2 : r → w2 that share a minimal number of common vertices among all such pairs of pathscan be obtained by tree paths from r to w1 in T1 and from r to w2 in T2 if π [w1] < π[w2] and otherwise by the tree pathsfrom r tow1 in T2 and from r tow2 in T1. Moreover, as stated by the lemma, the common vertices of these paths exist exactlyof the vertices that are ancestors of lcaT (w1, w2) in T . If we root the trees in r , for i ∈ {1, 2}, the first and last edges of piconsist of (r, ChildT1(r, w1)) and (fT1(w1), w1) or of (r, ChildT2(r, w1)) and (fT2(w1), w1) depending on the values of π [w1]

and π [w2]. Recall that only a linear running time is needed to construct data structures using O(n) space that support thequeries ChildT1 and ChildT2 in constant time (Lemma 5). With these data structures and the array π we then can easilypredict the first and last edges of p1 and p2 in constant time and also output p1 and p2 in O(|p1| + |p2|) time. This shouldprove our statement since it seems that the construction of the trees T1 and T2 in [12] guarantees that the paths p1 and p2 in

Page 6: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

40 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

Fig. 2. A directed acyclic graph G (left), the dominator tree of r = 2 (middle), and the shortest path tree with root r (right) consisting of the solid blackedges. The gray nodes of the shortest path tree together with the gray edges define the tree T (r).

the trees T1 and T2 also share a minimal number of common edges. If this is not the case, the trick is to replace each singleedge (u, w) of G by a path consisting of two edges (u, vu,w) and (vu,w, w) for a new vertex vu,w . Then in the new graph twopathswith aminimal number of common vertices share also aminimal number of common edges and can be translated intomaximally disjoint paths of the original graph by replacing each subpath (u, vu,w) ◦ (vu,w, w) by the original edge (u, w).

Nevertheless, in the following we want to represent a simpler data structure for dags that helps to make the paper moreself contained.

In a preprocessing phase we compute

• a topological numbering τ of the vertices of G,• a shortest path tree S for G with source node r (see Fig. 2),• a dominator tree T of r for G (see Fig. 2),• for each vertex v = r in T , two vertices lpref(v) and lalt(v) such that

– lpref(v) is the father of v in S,– (lalt(v), v) is an edge of G with τ(lcaT (lpref(v), lalt(v))) being minimal, i.e., τ(lcaT (lpref(v), lalt(v))) = minu:(u,v)∈E

τ(lca(lpref(v), u)).• For each vertex u ∈ T , a tree T (u)with its vertex set consisting of u as root and of the children of u in T , where fT (u)(v) = u,

if lpref(v) = u, and fT (u)(v) = ChildT (u, lpref(v)), otherwise (see Fig. 2).• for S, T , and each of the trees T (u) with u ∈ V , data structures supporting lowest common ancestor queries as well as

the queries ChildS , ChildT , and ChildT (u), respectively, in constant time.

Note explicitly that we have lalt(v) = lpref(v) if and only if indeg(v) = 1, where we also use the fact that we assumed allvertices to be reachable from r and that G is acyclic. The time needed for the preprocessing phase is linear and the space usedby the constructed data structure is O(n): Since G is an unweighted graph, S can be constructed as a breadth-first search treein linear time and uses O(n) space. We already mentioned in the Sections 1 and 2 that a dominator tree and a data structuresupporting lowest common ancestor queries can both be constructed in linear time and that the data structures need O(n)spacewhich is also clear for the dominator tree. By Lemma 5 a data structure supporting the query ChildT or ChildT (u) can bealso constructed in linear time and uses linear space. In particular, for a tree T (u), data structures supporting lowest commonancestor queries and the query ChildT (u) can be constructed in O(outdeg(u) + 1) time and use O(outdeg(u) + 1) space sothat the construction of these data structures for all trees takes O(m + n) time and the space used by the data structures isalso bounded by O(m + n). With the lowest common ancestor data structure for T it is easy to compute lalt(v) for a singlevertex v in O(indeg(v)) time, i.e., the values lpref(v) and lalt(v) for all v ∈ V in altogether O(m+ n) time. Note also that withthe data structure supporting the query ChildT all trees T (u) can be constructed in altogether O(m + n) time. At the end ofthe preprocessing phase, we set E ′

= {(lpref(v), v) | v ∈ V } ∪ {(lalt(v), v) | v ∈ V }.Let us assume that, for some integer k, we have already shown that we can support Paths(r, v, v) and Edges(r, v, v) for

all vertices v ∈ T − {r} with τ(v) ≤ k such that the properties of lemma hold. This should mean that, for all these vertices,in O(1) time, we can compute a tuple (f ′

1, f′

2, l′

1, l′

2) answering Edges(r, v, v), and, in O(|p1| + |p2|) time, we can computepaths p1 : r → v and p2 : r → v answering Paths(r, v, v) such that(P1) p1 and p2 consist exclusively of edges in E ′.(P2) the common vertices of p1 and p2 consist exactly of the vertices on the tree path from r to v in T .(P3) for each i ∈ {1, 2}, (r, f ′

i ) is the first and (l′i, v) the last edge of pi.

Page 7: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 41

Fig. 3. The algorithm for constructing p1 and p2 .

We further assume that l′1 = lpref(v). For technical reasons, we assume that, for all vertices v with τ(v) ≤ k, we canalso support queries Paths∗(r, v, v) and Edges∗(r, v, v) that in the case lpref(v) = fT (v) differ from Paths(r, v, v) andEdges(r, v, v) only in that way that Paths∗(r, v, v) instead of the whole path p1 only outputs p∗

1 = p1[r, ChildT (fT (v),lpref(v))] and runs in O(|p∗

1| + |p2|) time, and that Edges∗(r, v, v) returns the first and last edges of p∗

1 and p2 instead of p1and p2. It is easy to prove our assumptions for a small value of k, say, for the third smallest topological number.

We next show that the algorithm Construct(r, w1, w2) in Fig. 3, for each pair (w1, w2) of different vertices w1, w2 ∈

T − {r} with a topological number of at most k, outputs paths p1 : r → w1 and p2 : r → w2 and vertices f1, f2, l1, and l2such that

(C1) p1 and p2 consist exclusively of edges in E ′.(C2) The common vertices of p1 and p2 are exactly the vertices of the tree path from r to lcaT (w1, w2) in T ,(C3) for each i ∈ {1, 2}, (r, fi) is the first and (li, wi) the last edge of pi.

Property (C1) holds obviously. For showing (C2) and themaximal disjointness of the paths output by Construct, wemakeuse of the following relation between the trees S, T , and T (x) for some x ∈ V : For a tree path p from a vertex x to a descendantw in S, the vertices of p apart from x itself exclusively consist of descendants of that children of x in T that are part of the treepath from x to ChildT (x, w) in T (x) (see Fig. 2). Therefore, if u = v the paths q1 and q2 do not have any common children of uin T and hence, by Corollary 4, they are internally vertex-disjoint. Since u as a vertex dominating w1 and w2 must be visitedby all paths p1 : r → w1 and p2 : r → w2, the paths output by Construct in the case u = v are indeed maximal disjointand (C2) holds in this case. More precisely, in the case u = r we additionally use our knowledge about the paths returnedby Path(v, v). For example (C2) follows from (P2).

Let us next consider the case u = v. Note that in this case we must have v = ChildT (u, wj) for the index j chosen inline (16) since otherwise ChildT (u, wi) = v = ChildT (u, wj) would imply that w1 and w2 are both descendants of v andhence lcaT (w1, w2) = u. In the case u = v the only common vertices of q1 and q2 are vertices that are descendants ofv in T (compare Corollaries 3 and 4). On qj these common vertices appear before the vertex vj, where vj exists because ofv = ChildT (u, wj). Note that p′

1 is a proper sub-path of a path p1 that would have been returned by Paths(r, vj, vj) instead ofPaths∗(r, vj, vj). Since fT (vj) = u and by our assumptions about the queryPaths∗(r, vj, vj) the sub-path p1[u, vj] is internally

Page 8: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

42 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

vertex-disjoint to p′

2[u, vj]. Hence p′

1 and p′

2 have no common vertices with a topological number greater than u. Moreover,the only possibility that p1[u, vj] and p′

2[u, vj] are not edge-disjoint is that they are equal to the edge (u, vj) and that (u, vj)is the only edge ending in vj. This would be a contradiction to vj being reachable from v since τ(v) > τ(u). Since the lastedge of p1 is (lpref(vj), vj), i.e., equal to the last edge of qj, p1[u, vj] visits vertices that in T are descendants of v. Because ofthe edge- and internally vertex-disjointness of p1[u, vj] and p′

2[u, vj] and by Corollary 4, p′

2 then does not visit any verticesthat are descendants of v in T . In particular, p′

2 is vertex-disjoint to the part of qi that consists of descendants of v in T . Ifthis part of qi does not contain wi, then p′

2 as a path visiting only vertices with a topological number of at most τ(vj) is alsodisjoint from the remaining part of qi, i.e., from qi[vi, wi]. Clearly, p′

1 as a path ending in v consists exclusively of verticeswith a topological number of at most τ(v) and is therefore vertex-disjoint from qj[vj, wj]. Altogether, the constructed pathsp1 and p2 have no common vertices with a topological number larger than that of u. Since by our assumptions p1 and p′

2 aremaximal disjoint paths having only the vertex vj and the ancestors of u in T in common and since p′

1[r, u] = p1[r, u] andp′

2[r, u] = p2[r, u], we can conclude that (C2) holds and that p1 and p2 are also maximal disjoint paths.Concerning property (C3), if u = v = r , we output q1 and q2, which in this case have only vertex u in common. Therefore,

(u, ChildS(u, w1)) and (u, ChildS(u, w2)) are a correct choice for the first edges of these paths. In all other cases, q1 and q2have a common vertex v = r . Then the first edges of p1 and p2 are the first edges of p′

1 and p′

2 and we correctly choosef1 and f2 as the vertices in {f ′

1, f′

2}. Since p1 and p2 end with the last parts of the paths q1 and q2, in general we can choosel1 = lpref(w1) and l2 = lpref(w2). However, these last parts or even the whole paths q1 or q2 may be of zero length. In thiscase we have to choose l1 and l2, respectively, as the last edges of p′

1 or p′

2 as it is done by the algorithm.What we have shown so far is that the output of Construct(r, w1, w2) defines the correct answers to the queries

Paths(r, w1, w2) and Edges(r, w1, w2) as long as the topological numbers ofw1 andw2 are atmost k. Let us also analyze therunning time of Construct. Because of the preprocessing phase all lowest common ancestor queries and the queries ChildTand ChildT (u) can be supported in constant time. If we store with each vertex in S a pointer to its parent, we can constructthe parts of q1 and q2 used for the output in a time linear in the length of these sub-paths. In particular, in constant time,we can decide whether u = v and, if so, compute the vertex vj for the index j chosen in line 16. Then instead of the wholepath qj we only construct qj[vj, wj]. By our assumptions concerning the queries Paths and Paths∗ we can construct p′

1 andp′

2 in O(|p′

1| + |p′

2|) time and hence the paths p1 and p2 in altogether O(|p1| + |p2|) time. If we abstain from outputting p1and p2 and remove the lines (3), (8), and (17) computing sub-paths of p1, p2, it is easy to see that we can support the queryEdges(r, w1, w2) and Edges∗(r, w1, w2) in constant time if we have already pre-computed the output of Edges(r, v, v) andEdges∗(r, v, v) for all vertices v of topological number at most k. Note that the storage of all these values takes only O(n)space.

To finish our proof by an induction note that, for the vertex v with τ(v) = k + 1, we can support Paths(r, v, v) suchthat the properties (P1)–(P3) hold by calling Construct(r, lpref(v), lalt(v)) and adding the edges (lpref(v), v) and (lalt(v), v)to the paths returned in additional constant time. (C1)–(C3) guarantee that (P1)–(P3) hold. For supporting Paths∗(r, v, v) inthe case lpref(v) = fT (v), we call Construct(r, x, lalt(v)) for x = ChildT (fT (v), lpref(v)) instead of x = lpref(v). Edges(r, v, v)can be supported in constant time by calling Edges(r, lpref(v), lalt(v)) if we implement this query as defined for the verticesof topological number at most k and replace the last edges in the tuple returned by (lpref(v), v) and (lalt(v), v). Similarly,for Edges∗(r, v, v) we call Edges(r, x, lalt(v)), where in the case lpref(v) = fT (v) we choose x = ChildT (fT (v), lpref(v)) andotherwise x = lpref(v). �

To illustrate how the query Construct works let us consider a call of Construct(2, 36, 39) on the graph shown on theleft side of Fig. 2. Note that the numbering of the vertices already defines a topological numbering so that we can chooseτ(v) = v. The subroutine Construct first computes the lowest common ancestor u of 36 and 39 in the dominator tree Tshown in the middle of the Fig. 2. In our case we have u = lcaT (36, 39) = 2. Then v is chosen as lowest common ancestor of31 = ChildT (2, 36) and 37 = ChildT (2, 39) in the gray tree T (u) on the right side of Fig. 2, i.e., as the vertex 7. The verticesv1 and v2 correspond to the children of v in the gray tree being ancestors of 31 and 37. Hence v1 = 31 and v2 = 24. Since31 > 24, the indices i and j are chosen such that vj = 24 and vi = 31. By definition lpref(24) is the father of 24 in the shortestpath tree S on the right side of Fig. 2. The vertex lalt(24) must be chosen as a vertex u for which (u, 24) is an edge in G, andlcaT (u, lpref(24)) has aminimal topological number among all possible choices. Therefore, lpref(24) = 23 andwe can assumethat lalt(24)was chosen for example as 20. Since 7 = ChildT (2, 23) and 4 = ChildT (2, 20) and the lowest common ancestorof 7 and 4 in T and T (u) is equal to the root r = 2 of T , the paths p1 and p′

2 that would be recursively constructed by Paths(2,24, 24) consist beside the edges (23, 24) and (20, 24) of the tree paths from 2 to 23 and from 2 to 20 in S. Hence we obtainp′

1 as the sub-paths of p1 from 2 to 7, namely as the path consisting only of the edge (2, 7). Since the paths q1 and q2 alsofollows the edges in S, we obtain p1 as the path visiting the vertices 2, 7, 12, 17, 22, 30, 31, 35, and 36 and p2 as the pathsvisiting the vertices 2, 4, 5, 9, 10, 15, 20, 24, 28, 32, 37, and 39 in this order.

In this paper we make no explicit use of the existence of a sparse certificate for the above queries, i.e., a subgraph G′ ofG of at most O(|V |) edges on which all of the above queries yields to the same result as on the original graph G. However,we mention this result since sparse certificates in general are useful for improving the running time of several algorithms(see [9]). We now come to the main result of this section:

Theorem 7. Let s1 and s2 be two vertices in a directed graph G = (V , E). Then one can construct in O(m + n) time adata structure using O(n) space that supports the queries VertexDisjointTuple, EdgeDisjointTuple, VertexDisjointPaths,EdgeDisjointPaths on all instances (s1, s2, t1, t2) with t1, t2 ∈ V output-sensitive. The data structure can be constructed such

Page 9: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 43

that the edges of the paths returned by VertexDisjointPaths and EdgeDisjointPaths all belong to a subset E ′⊆ E which is

pre-computable in O(m + n) time and for which indegG′(v) ≤ 2 holds for all v ∈ V in the subgraph G′= (E ′, V ) of G.

Proof. We first exclude some simple special cases. In a preprocessing phase we mark all vertices reachable from s1 or s2by depth-first searches from these vertices and we delete all other vertices from G. Instances containing unmarked verticescan be excluded in constant time as non-solvable. For simplicity we also want to assume that s1 = s2. Note that in the cases1 = s2 there cannot exist vertex disjoint paths p1 : s1 → t1 and p2 : s2 → t2 solving the queries VertexDisjointTuple orVertexDisjointPaths. For the queries EdgeDisjointTuple or EdgeDisjointPaths the idea is to insert a new vertex s′2 and anew edge (s′2, s2) into G and to replace the instance (s1, s2, t1, t2) with (s1, s′2, t1, t2).

In all remaining cases, we insert a new vertex r and two new edges (r, s1) and (r, s2) into G. We construct a dominatortree T and the data structure described in Lemma 6 for the resulting graph in O(m + n) time. Note that T and the datastructure use only O(n) space.

To answer the different queries, let us consider the two maximal disjoint paths p1 : r → t1 and p2 : r → t2 that wouldby output by Paths(r, t1, t2). Obviously, there is a tuple answering the query VertexDisjointTuple if and only if p1 and p2are internally vertex-disjoint and t1 = t2. A tuple answering the query EdgeDisjointTuple exists if and only if p1 and p2 areedge-disjoint.

If t1 = t2, by Lemma 6 the paths p1 and p2 are internally vertex-disjoint if and only if r = lcaT (t1, t2). With a lowestcommon ancestor data structure for T using only O(n) space this can be tested in O(1) time.

To decide whether p1 and p2 are edge-disjoint is a little bit more complicated. We know by Lemma 6 that the commonvertices of p1 and p2 are exactly the vertices on the path p : r → lcaT (t1, t2) in T . Hence the endpoints of a common edge(u, v) of p1 and p2 must consist of two consecutive vertices u and v on p. Let us define indeg∗(v) as the number of vertices u′

with (u′, v) ∈ E that are not dominated by v. If indeg∗(v) = 1, then clearly all paths from r to v must use the only ingoingedge (u, v) for which u is not dominated by v and (u, v) is therefore a common edge of p1 and p2. Let us now assume for amoment that p1 and p2 have a common edge (u, v) but indeg∗(v) ≥ 2. Then there is a vertex u′

= u dominated by u butnot by v with (u′, v) ∈ E. The existence of such a vertex implies that there is also a path p′

: u → u′ whose vertices aredominated by u but not by v. Hence there are two edge-disjoint paths between u and u′, namely the paths p′

◦ (u′, u) andthe path consisting of the single edge (u, v). The simplicity of p1 and p2 imply that the vertices appearing strictly before u onp1 and p2 are not dominated by u and since by Lemma 2 all vertices of p1 and p2 appearing after v are dominated by v, thepaths obtained from p1 and p2 by replacing the edge (u, v) of p1 by p′

◦ (u′, v) define a set of paths also sharing a minimalnumber of vertices but a lower number of common edges than p1 and p2. Contradiction. Hence p1 and p2 are edge-disjoint ifand only if there is no ancestor v = r of lcaT (t1, t2) in T with indeg∗(v) = 1. With a lowest common ancestor data structurefor the dominator tree T of G it is easy to find out in constant time whether, for an edge (u, v), the vertex u is dominatedby v in constant time. Therefore we can compute the values indeg∗(v) for all vertices v in altogether O(m + n) time. Notethat such a computation is not necessary on dags since on dags we simply have indeg∗(v) = indeg(v). It is easy to see thatby a bottom-up traversal of T we can mark all nodes that have an ancestor v = r with indeg∗(v) = 1 again in O(m + n)time. Afterwards for deciding whether there is a tuple answering EdgeDisjointTuple(s1, s2, t1, t2) we just have to computelcaT (t1, t2) and to test whether this vertex is unmarked or not.

If p1 and p2 are vertex-disjoint or edge-disjoint, the tuple to be output by VertexDisjointTuple and EdgeDisjointTuple,respectively, is (s1, s2, t1, t2), if p1 starts with the edge (r, s1), and (s1, s2, t2, t1), otherwise. This first edge can be output bythe query Edges(r, t1, t2) in constant time.

Thus, we have shown that with a data structure for answering lowest common ancestor queries on T and the datastructure of Lemma 6, we can support VertexDisjointTuple(s1, s2, t1, t2) and EdgeDisjointTuple(s1, s2, t1, t2) in constanttime. If tuples answering the above queries exist, we can support VertexDisjointPath and EdgeDisjointPath within thedesired time and space bounds by just calling Paths(r, t1, t2) and deleting the edges (r, s1) and (r, s2) from the resultingpaths. �

4. Solving the 2-VDPP on dags

In this section we present a linear time algorithm for solving the 2-VDPP on dags. In the following disjoint means alwaysvertex-disjoint.

Let us call an instance I = (G, s1, s2, t1, t2) of the 2-VDPP on a dag G = (V , E) irreducible if the in-degree of each vertexv ∈ V − {s1, s2} and the out-degree of each vertex v ∈ V − {t1, t2} is at least two, and if t1, t2 have no outgoing and s1, s2no incoming edges. As observed by Thomassen [36], each non-irreducible instance on a dag can be reduced in linear time toan irreducible instance of at most the same size. More precisely, given an algorithm for solving the 2-VDPP on irreducibleinstances of a dag in T (m, n) time, the 2-VDPP on dags can be solved even on non-irreducible instances inO(T (m, n)+m+n)time. For more details see [20,36]. Hence in the following we always assume that we are given an irreducible instance andcan make use of the following important property of such instances.

Lemma 8. Let (G, s1, s2, t1, t2) be an irreducible instance of the 2-VDPP on a dag G = (V , E). Then, for each pair v, w ∈ V withv = w, there are two disjoint paths p1 and p2 such that pi (1 ≤ i ≤ 2) leads from a vertex in {v, w} to a vertex in {t1, t2} as wellas two disjoint paths leading from {s1, s2} to {v, w}. Moreover such paths can be constructed in a time linear in the sum of theirlengths (or in O(1) time if the paths both have zero length).

Page 10: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

44 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

Fig. 4. A path with gray colored switches.

Table 1The different path replacements.

Case Description: {i, j} = {1, 2} and Replacements

1 v ∈ pi , v′∈ rj p∗

i := pi[si, v] ◦ ri[v, ti]p∗

j := pj[sj, v′] ◦ rj[v′, tj]

2 u ∈ pi , u′∈ qj and p∗

i := qi[si, u] ◦ pi[u, ti]Case 1 is not given p∗

j := qj[sj, u′] ◦ pj[u′, tj]

3 The remaining cases with p∗

i := qi[si, u′] ◦ pj[u′, v′

] ◦ ri[v′, ti]u ∈ pi and v ∈ pi p∗

j := qj[sj, u] ◦ pi[u, v] ◦ rj[v, tj]

4 The remaining cases with p∗

i := qi[si, u′] ◦ pj[u′, v] ◦ ri[v, ti]

u ∈ pi and v ∈ pj p∗

j := qj[sj, u] ◦ pi[u, v′] ◦ rj[v′, tj]

Proof. We show how to construct two disjoint paths p1 and p2 leading from vertices in {v, w} to vertices in {t1, t2}. Pathsfrom vertices in {s1, s2} to the vertices in {v, w} can be constructed analogously. We initialize p1 and p2 as paths of zerolength from v to v and from w to w, respectively, and extend them step by step until we get the desired paths. We alwaysassume that the current paths p1 and p2 are vertex-disjoint which, of course, is true immediately after the initialization of p1and p2. We consider a fixed topological numbering of the vertices of G which must assign the two largest numbers |V | − 1and |V | to t1 and t2. In each step we take the endpoint u of p1 and p2 with the smaller topological number and search foran outgoing edge (u, y) for u. Say w.l.o.g. that u is the endpoint of p1. Our construction rule implies that if y is part of p2,then it must be the endpoint of p2. Otherwise we have already added an edge (y, z) to p2 although τ(y) > τ(u) and obtaina contradiction to our construction rule. If u ∈ {t1, t2}, the fact that outdeg(u) ≥ 2 guarantees that we can find anotheroutgoing edge (u, x) and that we can add it to p1 without violating the disjointness of p1 and p2. Finally, if u ∈ {t1, t2},then the endpoints of p1 and p2 must be t1 and t2 so that we have already constructed the desired paths. Since for eachcurrent endpoint u of the already constructed paths we have to consider at most two edges, the running time is bounded byO(|p1| + |p2| + 1). �

The lemma above is a slight modification of the following lemma used by Lucchesi and Giglio for their algorithm.

Corollary 9 (Thomassen [36]). If (G, s1, s2, t1, t2) is an irreducible instance of the 2-VDPP on a dag G = (V , E), then, for eachvertex v ∈ V − {s1, s2, t1, t2}, there exist four internally vertex-disjoint paths p1 from s1 to v, p2 from s2 to v, p3 from v to t1, andp4 from v to t2.

We next describe a slightly modified version of Lucchesi and Giglio’s algorithm for solving the 2-VDPP on an irreducibleinstance (G, s1, s2, t1, t2) in a dag G. Let U(G) be the undirected graph obtained from G by replacing each directed edge (u, v)of Gwith an undirected edge {u, v}. Then the algorithm of Lucchesi and Giglio first determines two disjoint paths p1, from s1to t1, and p2, from s2 to t2, in U(G). As Lucchesi and Giglio, for two consecutive edges (u, v) and (v, w) on p1 or p2, we referto v as a switch if either both, (u, v) and (w, v), are contained in E (i.e. (v, u), (v,w) ∈ E since G is a dag), or both, (v, u) and(v, w), are part of E (see also Fig. 4).

Let τ be a topological numbering of the vertices of G. We define u to be the switch of smallest topological number and vto be the switch of largest topological number among all switches on p1 and p2. In slight difference to Lucchesi and Gigliowe let u′ be the last vertex x with τ(x) < τ(u) on the path p1 or p2 not visiting u. Analogously, v′ should be the first vertexy with τ(y) > τ(v) on the path p1 or p2 not visiting v. The vertices u, u′, v, and v′ in the following are called the boundaryvertices (of p1 and p2). We then construct two disjoint paths q1 and q2 such that, for i ∈ {1, 2}, qi starts in si and ends in oneof the vertices in {u, u′

} and, analogously, two disjoint paths r1 and r2 with ri, for i ∈ {1, 2}, leading from one of the verticesin {v, v′

} to ti. By Lemma 8 such paths must exist and can be constructed in linear time. After determining u, u′, v, and v′,the paths p1 and p2 are replaced by new paths p∗

1 and p∗

2 as shown in Table 1. For an illustration see also Fig. 5. Recall that,for two vertices a and b on a path p, p[a, b] is possibly not a subpath of p but of the reverse of p if a appears after b on p. Thefollowing lemma shows that the replacements maintain the disjointness of the paths.

Lemma 10. p∗

1 and p∗

2 are disjoint.

Proof. Keep inmind that by definition q1 is disjoint to q2 and r1 is disjoint to r2. Then in the Cases 1 and 2 the lemma followsfrom the fact that by the definition of the boundary vertices the remaining sub-paths of p1 and p2 used for the construction

Page 11: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 45

Fig. 5. The replacements of Table 1, where in Case 3 we assume that u appears before v on pi . Similar assumptions for the other boundary vertices and Case4 are not necessary since we show that v′ can only appear after a vertex in {u, u′

} and that u′ can only appear before a vertex in {v, v′} on p1 or p2 .

of p∗

1 and p∗

2 apart from u′ and v′ visit only vertices xwith τ(x) ≤ τ(v) (Case 1) or only vertices xwith τ(x) ≥ τ(u) (Case 2).Let p′

1 and p′

2 be the sub-paths of p1 and p2, respectively, that were used for the construction of p∗

1 and p∗

2 in Case 3 or 4. Thensimilar to the previously considered cases the disjointness of p∗

1 and p∗

2 follows if we can show that τ(u) ≤ τ(x) ≤ τ(v)holds for all x ∈ p′

1 and all x ∈ p′

2 with x ∈ {u′, v′}. It is easy to see that this holds if, for each ordered pair of vertices

(y, z) ∈ {(u, v′), (u′, v), (u′, v′)} with y, z ∈ p′

i for an i ∈ {1, 2}, y appears before z on p′

i—the case y = u and z = v is notexplicitly considered since in this case we always have τ(u) ≤ τ(x) ≤ τ(v) for all vertices x ∈ pi[u, v] even in the possiblecase that u appears after the vertex v. For all considered choices, y appears before z since the properties of v′ guarantee thatv′ must appear after the last switch on p1 or p2, whereas u′ must appear before the first switch on p1 or p2, if there are anyswitches. In the special case of u′ or v′ appearing on a path without any switches, the relation τ(u) < τ(v) guarantees thatu′ by definition must appear before v′. �

Recall that by our choice of τ the vertices s1 and s2 have the smallest topological numbers whereas the vertices t1 andt2 have the largest topological numbers. If a path p ∈ {p1, p2} contains at least one switch than the topological numbersof the vertices on the subpath of p from its first vertex to the first switch increase whereas immediately after the switchthe topological number decrease. Therefore, pmust visit a further switch before reaching its last vertex in {t1, t2}. With p inthis case having at least two switches it is easy to see that the edges on p incident to the switch with a smallest topologicalnumber on p are outgoing edges in G, whereas the edges incident to the switch with the largest topological number on pare ingoing edges in G. This means that after a replacement corresponding to one of the Cases 2–4, the boundary vertex u isincident to one ingoing edge on q1 or q2 and one outgoing edge on p1 or p2 and therefore not a switch anymore. Similarly,after a replacement corresponding to the Cases 1, 3, and 4, v is not a switch of p∗

1 and p∗

2 anymore. Moreover, u′ and v′ arechosen in such a way that neither before nor after the replacement they are switches of p1 or p2. The paths q1, q2, r1, andr2 as paths in the dag G cannot contain any switch. Consequently, the set of switches of p∗

1 and p∗

2 is a proper subset of theswitches of p1 and p2 before the replacement. Therefore, after O(n) replacements, the resulting paths can no longer containany switches and they solve the 2-VDPP. Since Lucchesi and Giglio in their paper focus only on the existence of a solution,they did not present explicit time bounds for the construction of the vertices u, u′, v, and v′ and the paths q1, q2, r1, and r2.However, with the standard network flow techniques these vertices and paths can be easily computed in O(m) time. UsingLemma 8 this running time can be improved to O(n). With this simple modification the algorithm of Lucchesi and Gigliobecause of the at most O(n) repetitions can be implemented in O(n2) time. We next show that the running time can beimproved to linear time.

Theorem 11. The 2-VDPP on a dag G with n ≥ 1 vertices and m edges can be solved in O(m + n) time.

Page 12: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

46 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

Proof. Take G = (V , E). We follow the basic concept of the algorithm of Lucchesi and Giglio described above. In particular,we assume that we are given an irreducible instance and start with constructing two disjoint paths p1 : s1 → t1 andp2 : s2 → t2 on U(G) instead of our original graph G. Unfortunately, as mentioned in the introduction, the currently bestpublished running time for the 2-VDPP on undirected graphs is an O(m + nα(n, n))-time algorithm given in [34]. The mostexpensive part of this algorithm consists of repeatedly removing vertices z for which there is a set S ⊆ V \ {z} of at mostthree vertices such the subgraph U(G)− S is not connected and the connected component of U(G)− S containing z does notcontain any of the vertices s1, s2, t1, and t2. The good news is that on an irreducible instance such a vertex cannot exist sinceby Corollary 9 there are four internally vertex-disjoint paths from v to the vertices in {s1, s2, t1, t2} in U(G). The classicalnetwork flow theory then implies that a set S as described above cannot exist. Therefore, we can skip the most expensivepart of the O(m + nα(n, n))-time algorithm. Since the remaining parts of the algorithm run in linear time, we obtain twopaths p1 : s1 → t1 and p2 : s2 → t2 solving the 2-VDPP on U(G) in linear time.

After having constructed p1 and p2 we determine all switches on these paths and sort them by their topological numbers.Using bucket sort this takes again linear time. We next determine the boundary vertices u, v, u′, and v′ as defined in oursketch of the algorithm of Lucchesi and Giglio. The vertices u and v can be taken as the first and last vertex of our sortedlist of switches in constant time. For computing u′ we determine the index i with u ∈ pi and, for j = 3 − i, we consider thevertices of pj in direction from sj to tj until reaching the first vertex xwith τ(x) > τ(u). We then let u′ be the predecessor ofx on pj. The vertex v′ can be computed in a similar way by considering one of the paths in reverse direction.

Now, as a first change, we delay the explicit replacements shown in Table 1 since later replacements could make themsuperfluous and an explicit replacement may be expensive. However, we still want to determine in which case we wouldcome after running a replacement like in Table 1. In more detail, we construct in linear time the data structure of Theorem 7for s1 and s2 as fixed vertices. Then, in constant time, we can decide with the query VertexDisjointTuple(s1, s2, u, u′) forthe two disjoint paths that would be output by VertexDisjointPaths(s1, s2, u, u′), whether the path starting in s1 ends in uor in u′. Analogously, for each of two disjoint paths from {v, v′

} to a vertex in {t1, t2), we can predict its first vertex withoutconstructing the paths explicitly. Afterwards we can decide in which case of Table 1 we are and which parts of the pathshave to be replaced. To store this information we number the vertices of the original paths p1 and p2 in direction from thevertices s1 and s2 to the vertices t1 and t2. For a vertexw on pi (i ∈ {1, 2}), we define ni(w) as the number ofw on pi. For eachpath pi (i ∈ {1, 2}), we additionally store two values lowi and upi that should denote the fact that the part of pi consistingof all vertices w with ni(w) ≤ lowi or n(w) ≥ upi is already replaced. We initialize lowi with the number of si and upiwith the number of ti. If after computing the boundary vertices u, v, u′, v′ and applying the query VertexDisjointTuple weare in Case 1, according to the definition of the boundary vertices, the idea is to replace up1 and up2 with the numbers ofthe vertices v and v′. In Case 2, low1 and low2 should be replaced with the numbers of the vertices u and u′. Finally in theCases 3 and 4, we want to run both replacements. There is only one problem. In Case 3, umay appear after v on pi for somei ∈ {1, 2}.

In this special case we have to update lowi with the number of v and upi with the number of u. Moreover, from now on,the remaining part of pi used for the construction of p∗

j (j = 3 − i) appears on p∗

j in reverse direction. Therefore, in sucha case we also switch the value of a boolean variable reversej initialized with zero to the value 1 − reversej until the nextchange of the direction on this path. As long as reversej = 1 we have to take into account that the remaining part of theoriginal path on the current path with index j have to be considered in reverse direction.

If, after the computation of the values low1, low2, up1, and up2, we want to determine new boundary vertices u, u′, v, andv′ for the new paths p∗

1 and p∗

2 , these vertices have to appear on p∗

1 and p∗

2 between the vertices low1 and up1 and betweenlow2 and up2, respectively: For u and v this follows from the fact that q1, q2, r1, and r2 have been chosen as paths in G andtherefore do not contain any switches. For u′ and v′ this follows from the fact that the paths q1, q2, r1, and r2 beside thevertices u and v consist exclusively of vertices with a topological number smaller than that of u or larger than that of v,respectively. This knowledge helps to recursively compute boundary vertices u, u′, v, and v′ for the paths p∗

1 and p∗

2:For computing v, we first delete the switch that has been computed as the switch of largest topological number of the old

paths p1 and p2 if it is not a switch for the new paths anymore. Afterwards, from our sorted list of switches we recursivelydelete all switches of largest number until we obtain a switch on the remaining parts of p1 and p2, i.e., a switch v with anumber ni(v) of at least lowi and at most upi, where i is the index in {1, 2} with v ∈ pi. The boundary vertex u can bedetermined analogously.

If v ∈ p∗

i and j = 3− i, we can start the search for v′ on p∗

j in the vertex upj in the direction to lowj, if reversej = 0, and indirection from lowj to upj if reversej = 1. A further improvement is possible. Let us for simplicity assume that reversej = 0.If during the computation of previous boundary vertices we already searched for a boundary vertex v′ on p∗

j in the samedirection – i.e. with the same value of reversej – and this search ended in a vertex y appearing before the current value of upj,we can start the search in y instead of upj. This is true since τ(y)was larger than the topological number of the former switchof largest topological number and hence is also larger than the topological number of the current boundary vertex v of largesttopological number. Analogous improvements are possible for the case reversej = 1, and also for the vertex u′. Therefore,if we recursively repeat the above steps for each new pair of disjoint paths p∗

1 and p∗

2 , then the time needed to determinethe boundary vertices v′ on p∗

j for the same value j and the same value reversej is bounded by O(|p1| + |p2|) = O(n) timetaken over all recursion steps and the same holds analogously for u′. This efficient computation of the boundary vertices u′

and v′ is the reason why in this paper we replaced the original definition of u′ and v′ given by Lucchesi and Giglio. The costsfor repeatedly determining the switches of smallest and largest topological number can also be bounded by O(n) since no

Page 13: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

T. Tholey / Theoretical Computer Science 465 (2012) 35–48 47

vertex that have been deleted from our sorted list of switches is reinserted and in each round at least one switch becomesa non-switch.

After at most O(n) replacements the part of p1 between low1 and up1 and the part of p2 between low2 and up2 containsno switch anymore. Then the part of p1 leading from s1 to the vertex in {low1, up1} with the lower topological number andthe part of p2 leading from s2 to the vertex in {low2, up2} with the lower topological number define two paths q1 and q2corresponding to a previous replacement of Table 1—except in the very special case, where the considered parts of p1 and p2have zero lengths. Recall that we have not explicitly constructed q1 and q2 but only called the query VertexDisjointTuple.We can now call VertexDisjointPaths to explicitly construct q1 and q2 in O(n) time. In the same way, in O(n) time, we canconstruct vertex-disjoint paths r1 leading from the vertex in {low1, up1} with the larger topological number to t1 and r2leading from the vertex in {low2, up2} with the larger topological number to t2. Concatenating the constructed paths withthe remaining parts of the original paths p1 and p2 between low1 and up1 and between low2 and up2 we then obtain twodisjoint paths solving our instance of the 2-VDPP. �

5. Solving the 2-EDPP on dags

In this section we show how to solve the 2-EDPP on dags efficiently.

Theorem 12. The 2-EDPP on a dag G with n ≥ 1 vertices and m edges can be solved in O(m + n) time.

Proof. For testing whether there are two edge-disjoint paths p1 : s1 → t1 and p2 : s2 → t2, we first test whether there aresuch paths being vertex-disjoint by using Theorem 11. If not, two edge-disjoint paths p1 : s1 → t1 and p2 : s2 → t2 can onlyexist if there is a vertex v for which there are two edge-disjoint paths q1 : s1 → v and q2 : s2 → v and two edge-disjointpaths r1 : v → t1 and r2 : v → t2. For testing the existence of q1 and q2, we apply Theorem 7 with s1 and s2 as fixedvertices. Then, for each vertex v ∈ V , the existence of edge-disjoint paths from the vertices s1 and s2 to v can be tested inconstant time by the query EdgeDisjointTuple(s1, s2, v, v). Applying a similar data structure on the graph obtained from Gby replacing each edge (u, w) by its reverse edge (w, u), we can also decide whether there are two edge-disjoint paths in Gleading from v to the vertices in {t1, t2} for each vertex v in constant time. After testing all vertices v, each vertex in constanttime, we knowwhether there are two edge-disjoint paths p1 : s1 → t1 and p2 : s2 → t2 using v as a common vertex. If suchpaths exist, they can be output with the query EdgeDisjointPaths. �

6. Conclusion

We presented linear time algorithms for the 2-VDPP and the 2-EDPP on dags. The most important question concerningthe DPP on dags is whether the running times for the k-VDPP and k-EDPP can also be improved for k > 2. It would be alsointeresting to extend the data structure of Theorem 7 for predicting the first and last vertices of disjoint paths to the casek > 3 or to general directed graphs.

References

[1] A.V. Aho, J.D. Ullman, The Theory of Parsing, Translation, and Compiling. Vol. 2, Compiling, Prentice-Hall, Englewood Cliffs, N.J, 1972.[2] S. Alstrup, D. Harel, P.W. Lauridsen, M. Thorup, Dominators in linear time, SIAM J. Comput. 28 (1999) 2117–2132.[3] M.A. Bender, M. Farach-Colton, The LCA problem revisited, in: Proc. 4th Latin American Theoretical Informatics Symposium, LATIN 2000, in: Lecture

Notes in Computer Science, vol. 1776, Springer, Berlin, 2000, pp. 88–94.[4] O. Berkman, D. Breslauer, Z. Galil, B. Schieber, U. Vishkin, Highly parallelizable problems, in: Proc. 21st Annual ACM Symposium on Theory of

Computing, STOC 1989, pp. 309–319.[5] A.L. Buchsbaum, H. Kaplan, A. Rogers, J. Westbrook, A new, simpler linear-time dominators algorithm, ACM Trans. Program. Lang. Syst. 20 (1998)

1265–1296.[6] A.L. Buchsbaum, H. Kaplan, A. Rogers, J. Westbrook, Corrigendum: a new, simpler linear-time dominators algorithm, ACM Trans. Program. Lang. Syst.

27 (2005) 383–387.[7] G. Di Battista, R. Tamassia, L. Vismara, Output-sensitive reporting of disjoint paths, Algorithmica 23 (1999) 302–340.[8] Y. Dinitz, J. Westbrook, Maintaining the classes of 4-edge-connectivity in a graph on-line, Algorithmica 20 (1998) 242–276.[9] D. Eppstein, Z. Galil, G.F. Italiano, A. Nissenzweig, Sparsification-a technique for speeding up dynamic graph algorithms, J. ACM 44 (1997) 669–696.

[10] S. Fortune, J. Hopcroft, J. Wyllie, The directed subgraph homeomorphism problem, Theoret. Comput. Sci. 10 (1980) 111–121.[11] M.L. Fredman, R.E. Tarjan, Fibonnaci heaps and their uses in improved network optimization algorithms, J. ACM 34 (1987) 596–615.[12] L. Georgiadis, Linear-Time Algorithms for Dominators and Related Problems (thesis), Technical Report TR-737-05, Department of Computer Science,

Princeton University, 2005.[13] L. Georgiadis, R.E. Tarjan, Dominator tree verification and vertex-disjoint paths, in: Proc. 16th Annual ACM-SIAM Symposium on Discrete Algorithms,

SODA 2005, pp. 433–442.[14] L. Georgiadis, R.E. Tarjan, Dominators, directed bipolar orders, and independent spanning trees, in: Proc. 39th International Colloquium on Automata,

Languages and Programming, ICALP 2012, in: Lecture Notes in Computer Science, vol. 7391, Springer, Berlin, 2012, pp. 375–386.[15] D. Harel, A linear time algorithm for finding dominators in flow graphs and related problems, in: Proc. 17th Annual ACM Symposium on Theory of

Computing, STOC 1985, pp. 185–194.[16] D. Harel, R.E. Tarjan, Fast algorithms for finding nearest common ancestors, SIAM J. Comput. 13 (1984) 338–355.[17] R. Kapadia, Z. Li, B. Reed, A linear time algorithm to test the 2-paths problem, Manuscript.[18] K. Kawarabayashi, Y. Kobayashi, B. Reed, The disjoint paths problem in quadratic time, J. Combin. Theory, Ser. B 102 (2012) 424–435.[19] E.S. Lorry, V.W. Medlock, Object code optimization, Commun. ACM 12 (1969) 1322.[20] C.L. Lucchesi, M.C.M.T. Giglio, On the irrelevance of edge orientations on the acyclic directed two disjoint paths problem, IC Technical Report DCC-92-

03, Universidade Estadual de Campinas, Instituto de Computação, 1992.

Page 14: Linear time algorithms for two disjoint paths problems on directed acyclic graphs

48 T. Tholey / Theoretical Computer Science 465 (2012) 35–48

[21] T. Ohtsuki, The two disjoint path problem and wire routing design, in: Proc. Symposium on Graph Theory and Algorithms, in: Lecture Notes inComputer Science, vol. 108, Springer, Berlin, 1981, pp. 207–216.

[22] L. Perković, B. Reed, An improved algorithm for finding tree decompositions of small width, Internat. J. Found. Comput. Sci. (IJFCS) 11 (2000) 365–371.[23] Y. Perl, Y. Shiloach, Finding two disjoint paths between two pairs of vertices in a graph, J. ACM 25 (1978) 1–9.[24] B. Reed, N. Robertson, A. Schrijver, P.D. Seymour, Finding disjoint trees in planar graphs in linear time, Contemp. Math. 147 (1993) 295–301.[25] B. Reed, Rooted routing in the plane, Discrete Appl. Math. 57 (1995) 213–227.[26] N. Robertson, P.D. Seymour, Graph minors. XIII. The disjoint paths problem, J. Combin. Theory Ser. B 63 (1995) 65–110.[27] A. Schrijver, A group-theoretical approach to disjoint paths in directed graphs, CWI Quarterly 6 (1993) 257–266.[28] P.D. Seymour, Disjoint paths in graphs, Discrete Math. 29 (1980) 293–309.[29] Y. Shiloach, A polynomial solution to the undirected two paths problem, J. ACM 27 (1980) 445–456.[30] J.W. Suurballe, R.E. Tarjan, A quick method for finding shortest pairs of disjoint paths, Networks 14 (1984) 325–336.[31] R.E. Tarjan, J. van Leeuwen, Worst-case analysis of set union algorithms, J. ACM 31 (1984) 245–281.[32] T. Tholey, Finding disjoint paths on directed acyclic graphs, in: Proc. 31st International Workshop on Graph-Theoretic Concepts in Computer Science,

WG 2005, in: Lecture Notes in Computer Science, vol. 3787, Springer, Berlin, 2005, pp. 319–330.[33] T. Tholey, Solving the 2-disjoint paths problem in nearly linear time, Theory Comput. Syst. 39 (2006) 51–78.[34] T. Tholey, Improved algorithms for the 2-vertex disjoint paths problem, in: Proc. 35th Conference onCurrent Trends in Theory andPractice of Computer

Science, SOFSEM 2009, in: Lecture Notes in Computer Science, vol. 5404, Springer, Berlin, 2009, pp. 546–557.[35] C. Thomassen, 2-linked graphs, European J. Combin. 1 (1980) 371–378.[36] C. Thomassen, The 2-linkage problem for acyclic digraphs, Discrete Math. 55 (1985) 73–87.