Computing Vertex-Disjoint Paths in Large Graphs Using MAOs

We consider the problem of computing k∈N\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k \in {\mathbb {N}}$$\end{document} internally vertex-disjoint paths between special vertex pairs of simple connected graphs. For general vertex pairs, the best deterministic time bound is, since 42 years, O(min{k,n}m)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(\min \{k,\sqrt{n}\}m)$$\end{document} for each pair by using traditional flow-based methods. The restriction of our vertex pairs comes from the machinery of maximal adjacency orderings (MAOs). Henzinger showed for every MAO and every 1≤k≤δ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$1 \le k \le \delta $$\end{document} (where δ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\delta $$\end{document} is the minimum degree of the graph) the existence of k internally vertex-disjoint paths between every pair of the last δ-k+2\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\delta -k+2$$\end{document} vertices of this MAO. Later, Nagamochi generalized this result by using the machinery of mixed connectivity. Both results are however inherently non-constructive. We present the first algorithm that computes these k internally vertex-disjoint paths in linear time O(n+m)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(n+m)$$\end{document}, which improves the previously best time O(min{k,n}m)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(\min \{k,\sqrt{n}\}m)$$\end{document}. Due to the linear running time, this algorithm is suitable for large graphs. The algorithm is simple, works directly on the MAO structure, and completes a long history of purely existential proofs with a constructive method. We extend our algorithm to compute several other path systems and discuss its impact for certifying algorithms.


Introduction
Vertex-connectivity is a fundamental parameter of graphs that, by a result due to Menger [13], can be characterized by the existence of internally vertex-disjoint paths between vertex pairs.Thus, much work has been devoted to the following question: Given a number k, a simple graph G = (V , E), and two vertices of G, compute k internally vertex-disjoint paths between these vertices if such paths exist.Despite all further efforts, the traditional flow-based approach by Even and Tarjan [3] and Karzanov [7] gives still the best deterministic bound O(min{k, √ n}m) for this task, where n := |V | and m := |E|.
Our research is driven by the question whether k internally vertex-disjoint paths can be computed faster deterministically.This question has particular impact for large graphs, as we aim for linear-time algorithms.We have no general answer, but show for specific pairs of vertices that this can actually be done using maximal adjacency orderings (MAOs, also known under the name maximum cardinality search).MAOs order the vertices of a graph and can be computed in time O(n + m) [19] (we will define MAOs in detail in Sect.2).
One of the key properties of MAOs is that their last vertices are highly vertexconnected, i.e., have pairwise many internally vertex-disjoint paths.In more detail, let G be a simple unweighted graph of minimum degree δ and let < be a MAO of G. Then < decomposes G into edge-disjoint forests F 1 , . . ., F m in a natural way (we will give the precise background on MAOs and such forest decompositions later).Let a subset of vertices be k-connected if G contains k internally vertex-disjoint paths between every two vertices of this subset.Henzinger proved for every 1 ≤ k ≤ δ that the last δ − k + 2 vertices of < are k-connected [6].
In order to appreciate Henzinger's result, it is important to mention that its special case k = δ alone was predated by many results in the (weaker) realm of edgeconnectivity: a well-known line of research [4,15,18] proved that the last two vertices of < are δ-edge-connected.In fact, we exhibit the following forgotten link to a result by Mader [9,10] in 1971, who used a preliminary variant of MAOs over one decade before MAOs were introduced and proved that their last two vertices are even δ-connected.In 2006, Nagamochi generalized all the mentioned results as follows.
Theorem 1 ([14], [16,Thm. 2.28]) Let < be a MAO of a simple graph G and let F 1 , . . ., F m be the forests into which < partitions E. For every two vertices s and t that are in the same component of some F k , G contains k internally vertex-disjoint paths between s and t.
Theorem 1 specializes to Henzinger's result by taking the component T k of F k that contains the last vertex of < (this tree contains the last δ − k + 2 vertices of <).Its proof depends heavily on the machinery of mixed connectivity, and so does its most general statement (which we will explain in Sect.4.1).Theorem 1 may be seen as the currently strongest result on MAOs regarding vertex-connectivity.However, all proofs known so far about vertex-connectivity in MAOs (including the ones by Henzinger and Nagamochi) are non-constructive and thus do not give any faster algorithm than the flow-based one for the initial question of computing internally vertex-disjoint paths.
The main result of this paper is an algorithm that computes the k paths of Theorem 1 in linear time O(n + m).
Theorem 2 Let < be a MAO of a simple graph G and let F 1 , . . ., F m be the forests into which < partitions E. For every two vertices s and t that are in the same component of some F k , k internally vertex-disjoint paths between s and t can be computed in time This improves upon the previously best time O(min{k, √ n}m).To our surprise, its key idea is simple; the details of its correctness proof however are subtle.We therefore explain the algorithm in two incremental variants: The slightly weaker variant in Sect. 3 computes internally vertex-disjoint paths between one vertex s and a fixed set of k vertices of the forest decomposition; it does so by performing a right-to-left sweep through the MAO, in which the k paths are switched cyclically whenever one of the k paths would be lost.Section 4 then invokes two of these computations (one for s and one for t) in parallel in order to obtain our main result.We show also how the computation can be extended to find the k internally vertex-disjoint paths between a vertex and a vertex set, and between two vertex sets, whose existence was shown by Menger [13].
It is not easy to quantify for how many vertex pairs our faster algorithm can be applied.If we require δ internally vertex-disjoint paths, there are δ-regular graphs for which the only component of F δ consists of one vertex pair joined by an edge and In this case, we can apply our algorithm only to a single vertex pair.However, in practice, many more of these sets occur and each of them may have a much larger size.If k < δ internally vertex-disjoint paths are sufficient, all pairs of a much larger set of size δ − k + 2 can be taken (even in the worst case), at the expense of the linearly decreased pairwise connectivity k.
Certifying Algorithms Being able to compute k internally vertex-disjoint paths has a benefit that purely existential proofs and algorithms that only argue about vertex separators do not have: It certifies the connectivity between the two vertices.For related problems on edge-connectivity, this has already been used to make algorithms certifying (in the sense of [12]).
The perhaps most prominent such result is the minimum cut algorithm of Nagamochi and Ibaraki [15], which refines the work of Mader [9,10], and was simplified by Frank [4] and by Stoer and Wagner [18].This algorithm computes iteratively a MAO and then contracts the last two δ(-edge)-connected vertices of it.For unweighted multigraphs, this is easily made certifying by storing the k edge-disjoint paths between these last two vertices in every step; the global k-edge-connectivity then follows by transitivity.In fact, the desired k edge-disjoint paths for every MAO can be obtained by just taking, for every 1 ≤ i ≤ k, the unique s-t-path in the tree T i of F i that contains t.Using more involved methods, Arikati and Mehlhorn [1] made the algorithm of Nagamochi and Ibaraki certifying even for weighted graphs, again without increasing the quadratic asymptotic running time and space.
For the problem of recognizing k-connectivity, linear-time certifying algorithms are known for every k ≤ 3 [17,20].For arbitrary k, the best known deterministic certifying algorithm is still the traditional flow-based one [3,5], which achieves a running time . By using a geometric characterization of graphs, also a nondeterministic certifying algorithm with running time O(n 5/2 + k 5/2 n) is known [8].For designing faster certifying algorithms, finding a good certificate for k-connectivity seems to be the crucial open graph-theoretic problem, even when k is fixed: Open Problem For every k ∈ N, find a small and easy-to-verify certificate that proves the k-vertex-connectivity of simple graphs.
Our main result plays the same important role for certifying the vertex-connectivity between two vertices, as s-t-flows do for certifying the edge-connectivity between s and t in the results described above.For example, the 2-approximation algorithm for vertex-connectivity [6] by Henzinger can be made certifying using our new algorithm.

Maximal Adjacency Orderings
Throughout this paper, our input graph G = (V , E) is simple, unweighted and of minimum degree δ.We assume standard graph theoretic notation as in [2].A maximal adjacency ordering < of G is a total order 1, . . ., n on V such that, for every two vertices v < w, v has at least as many neighbors in {1, . . ., v − 1} as w has.For ease of notation, we always identify the vertices of G with their position in <.
Every MAO < decomposes G into edge-disjoint forests F 1 , . . ., F m (some of which may be empty) 1 as follows: If v > 1 is a vertex of G and w 1 < • • • < w l are the neighbors of v in {1, . . ., v − 1}, the edge {w i , v} belongs to F i for all i ∈ {1, . . ., l}.For every i, the graph (V , F i ) is an edge-maximal forest of G\{E(F 1 ), . . ., E(F i−1 )} (we refer to [16, Section 2.2] for a proof).For the sake of conciseness, we identify this forest with its edge set F i .The partition of E into the non-empty forests is called the forest decomposition of <.For vertices v < w, we say v is left of w.If there is an edge between v and w, we call this a left-edge of w.
For any k, we want to compute k internally vertex-disjoint paths between any two vertices that are contained in a tree T k of the forest F k .Hence, throughout the paper, let s > 1 be an arbitrary but fixed vertex of G and let k be a positive integer that is at most the number of left-edges of s.The vertex s will be the start vertex of the k internally vertex-disjoint paths to find (the end vertex will be left of s).E.g., if we choose s as the last vertex of the MAO (or any other vertex with at least that many left-edges), k can be chosen as any value that is at most the degree of vertex n; in particular, k can be chosen arbitrary in the range 1, . . ., δ, as claimed in the introduction.
For i ∈ {1, . . ., k}, let T i be the component of F i that contains s.As i ≤ k, T i is a tree on at least two vertices.Let the smallest vertex r i of T i with respect to < be the root of T i .For the purpose of this paper, it suffices to consider the subgraph of G induced by the edges of T 1 , . . ., T k .
Hence, for every i ∈ {1, . . ., k}, every vertex v > r i of T i has exactly one left-edge that is in T i and thus at least i left-edges that are in G. Let left i (v) be the end vertex of the left-edge of v in F i .The root r i of T i has left-degree exactly i − 1, as if it had more, r i would have a left-edge in F i and thus not be the root of T i and, if it had less, the left-degree of r i + 1 cannot be at least i, as this violates the MAO (this uses that G is simple).We conclude that r 1 < r 2 • • • < r k .Thus, the definition of F i and Lemma 3 imply the following corollary.
For a vertex-subset S ⊆ V , let S := V \S.For convenience, we will denote sets {v} by v.For a vertex-subset S ⊆ V , a set of paths is S-disjoint if no two of them intersect in a vertex that is contained in S. Thus, V -disjointness is the usual vertex-disjointness and a set of paths is v-disjoint if every two of them intersect in either the vertex v or not at all.We represent paths as lists of vertices.The length of a path is the number of edges it contains.For a path A, let end(A) be the last vertex of this list and, if the path has length at least one, let sec(A) be the second to last vertex of this list.

A Side Note on the Origin of MAOs
In [9,10], Mader presents a method to find a pendant pair {v, w} in a simple graph, which is a pair of vertices that is min{d(v), d(w)}-connected, where d is the degree function.He chooses an inclusion maximal clique and deletes vertices of this clique until it is not maximal anymore.When deleting vertices, new edges are added to preserve the degree of vertices that are not in the clique.Next the clique is enlarged to a maximal one; this procedure is iterated until every edge has an incident vertex in the clique.Then a pendent pair of the original graph can be found.
It turns out that this method is a preliminary version of MAOs: The order in which the vertices are added to the clique is in fact a maximal adjacency ordering, and, for every k-connected pendent pair found by this method, there is a MAO whose forest decomposition contains this pair as the end vertices of an edge in F k .This seems to be widely unknown and we are only aware of one place in literature where this similarity is (briefly) mentioned [11, p. 443].Mader's existential proof can in fact be made algorithmic.However, MAOs provide a much nicer structure, as they work directly on the original graph.

The Loose Ends Algorithm
We first consider the slightly weaker problem of computing k internally vertex-disjoint paths between s and the root set {r 1 , . . ., r k }.We will extend this to compute k internally vertex-disjoint paths between two vertices in the next section.

Lemma 5 Algorithm 1 computes k s-disjoint paths in T
The outline of our algorithm is as follows.We initialize each A i to be the path that consists of the two vertices s and left i (s) (in that order).The vertices left i (s) are marked as active; throughout the algorithm, let a vertex be active if it is an end vertex of an unfinished path A i .
So far the A i are s-disjoint.We aim for augmenting each A i to r i .
Step by step, for every active vertex v from s −1 down to r 1 in <, we will modify the A i to longer paths, similar as in sweep line algorithms from computational geometry.The modification done at an active vertex v is called a processing step.From a high-level perspective, the end vertices of several paths A i may be replaced or augmented by new end vertices w such that r i ≤ w < v during the processing step of v.Such vertices w are again marked as active, which results in a continuous modification of each A i to a longer path.By the above restriction on w, each path A i will have strictly decreasing vertices in < throughout the algorithm.At the end of the processing step of v, we unmark v from being active.
Let v be the active vertex that is largest in <.Assume that v is the end vertex of exactly one Algorithm 1).The important aspect of this approach is that the index of the path A i predetermines the vertex that augments A i .Clearly, this way A i will reach r i at some point, according to Lemma 3.

Algorithm 1 LooseEnds(G, <, s, k)
1: for all i do initialize all A i 2: Mark left i (s) as active 4: while there is a largest active vertex v do process v 5: Let j 1 < j 2 < • • • < j l be the indices of the paths A j i that end at v 6: for i := 2 to l do replace end vertices 7: Replace end(A j i ) with left j i−1 (sec(A j i )) 8: Mark left j i−1 (sec(A j i )) as active

9:
Perform a cyclic downshift on A j 1 , . . ., A j l A j i := A j i+1 , A j l := A j 1 10: if v = r j l then 11: A j l is finished r j l is reached 12: else 13: Append left j l (v) to A j l append predetermined vertex 14: Mark left j l (v) as active 15: Unmark v from being active 16: Output A 1 , . . ., A k However, if at least two paths end at v, this approach does not ensure vertexdisjointness.Let A j 1 , . . ., A j l be these l ≥ 2 paths and assume We first replace the end vertex v of A j i with the vertex left j i−1 (sec(A j i )) for all i = 1.We will show that these modified end vertices are strictly smaller than v, which will re-establish the vertex-disjointness.The key idea of the algorithm is then to switch the indices of the l paths appropriately such that the appended vertices are again predetermined by the path index.
Let a cyclic downshift on A j 1 , . . ., A j l replace the index of each path by the next smaller index of a path in this set (where the next smaller index of j 1 is j l ), i.e. we set A j i := A j i+1 for every i = l and then replace A j l with the old path A j 1 .We perform a cyclic downshift on A j 1 , . . ., A j l .Note that we did not alter the path A j l (which was named A j 1 before) yet.If v = r j l , A j l is finished; otherwise, we append the vertex left j l (v) to A j l .See Algorithm 1 for a description of the algorithm in pseudo-code.Figure 1 shows a run of Algorithm 1.
We prove the correctness of Algorithm 1.Before the processing step of any active vertex v, the A i satisfy several invariants, the most crucial of which are that they are {v + 1, . . ., s − 1}-disjoint and that the vertices of every A i are decreasing in <.In detail, we have the following invariants.
Invariants Let v < s be the largest active vertex, or v := 0 if there is no active vertex left.Before processing v, the following invariants are satisfied for every 1 ≤ i ≤ k: (1) The vertices of A i start with s and are strictly decreasing in <.
(2) The path A i is finished if and only if end(A i ) > v.In this case, end We first clarify the consequences.Invariant (2) implies that the algorithm has finished all paths A i precisely after processing r 1 , and that every A i ends at r i .The Invariants (1) and ( 3) are necessary to prove Invariant (4), which in turn implies that the A i are {v + 1, . . ., s − 1}-disjoint before processing an active vertex v. Hence, the final paths A i are s-disjoint.With Invariant (5) this gives the claim of Lemma 5.
It remains to prove Invariants (1)-( 5).Immediately after initializing A 1 , . . ., A k , the next active vertex is end(A k ) < s.It is easy to see that all five invariants are satisfied for v = end(A k ), i.e. before processing the first active vertex.We will prove that processing any largest active vertex v preserves all five invariants for the active vertex v that follows v (where v := 0 if v is the only remaining active vertex).For this purpose, let A i be the path with index i immediately before processing v and let A i be the path with index i before processing v; by induction hypothesis, the paths A i satisfy all invariants for v.
For Lines 7 and 13 in the processing step of v, we have to prove the existence of left j i−1 (sec(A j i )) and left j l (v) respectively.In Line 7, we have i ≥ 2 and end(A j i ) = v as can be seen in the pseudo-code.Then Invariant (2) implies that A j i is not finished and v = end(A j i ) = left j i (sec(A j i )).Thus, left j i−1 (sec(A j i )) exists.In Line 13, we have v = r j l and end(A j l ) = v (here, A j l refers by definition to the path with index j l before the cyclic downshift; note this is not the path dealt with in Line 13).Then Invariant (2) implies that r j l ≤ v.This proves r j l < v and the existence of left j l (v).
We prove v < v next.Consider the vertices that are newly marked as active in the processing step of v.According to Line 5 of Algorithm 1, every such vertex is the new end vertex of some path A j i with end vertex v that was modified in the processing step of v (we do not count index transformations as modifications).There are exactly two cases how A j i may have been modified, namely either by Line 7 (then 2 ≤ i ≤ l and left j i−1 (sec(A j i )) is the vertex that is newly marked as active) or by Line 13 (then left j l (v) is the vertex that is newly marked as active); in particular, A j i was not modified by both lines.In the first case, A j i satisfies Invariant (2) before the processing step of v by hypothesis.In fact, we have r j i ≤ v, as v < r j i implies that A j i is finished and since end(A j i ) > v would contradict end(A j i ) = v.Hence, the last edge of A j i is in T j i , which shows v = left j i (sec(A j i )).Since j i−1 < j i by Line 5 and due to Corollary 4, we conclude left j i−1 (sec(A j i )) < v.In the second case, Corollary 4 implies left j l (v) < v. Thus, in both cases, every new active vertex is strictly smaller than v, which proves v < v.
This gives Invariant (1), as every A j i starts with s and every new vertex is left of its predecessor in the path by Corollary 4.
For Invariant (2), consider the path A i for any i.First, assume that A i is finished.Then either A i is finished or v = r i , according to Line 11 of Algorithm 1 in the processing step of v.In the former case, A i satisfies Invariant (2) for v and so does A i for v < v.In the latter case, we have v < v = r i and end(A i ) = end(A j 1 ) = v.
Second, assume that A i was not modified in the processing step of v and is not finished.Then end(A i ) < v, as every path with end vertex at least v is modified or finished in the processing step of v or finished before.In particular, processing v did not change the index of A i = A i .As A i satisfies Invariant (2) for v by hypothesis, the only condition of Invariant (2) that may be violated for v is end(A i ) ≤ v .However, as end(A i ) < v was marked as active in some previous step of Algorithm 1 and since v is the largest active vertex, end(A i ) ≤ v .Thus, A i satisfies Invariant (2) for v .
Third, assume that A j i was modified in the processing step of v and is not finished.Then A j i was modified either by Line 7 or 13.If A j i was modified by Line 7, we have i < l and 2 ≤ l after the cyclic downshift, as the path A j 1 is not modified by Line 7. In addition, we know end(A j i ) = left j i (sec(A j i+1 )) < left j i+1 (sec(A j i+1 )) = v by Corollary 4 and that the last edge of A j i is in T j i .Thus, r j i ≤ end(A j i ).If A j i was modified by Line 13, we have i = l and r j l ≤ left j l (v) = end(A j l ) by Corollary 4. Then the last edge of A j l is in T j l .In both cases, end(A j l ) is active before processing v and it follows end(A j l ) ≤ v .
For Invariant (3), assume to the contrary that sec(A i ) ≤ v .Since v < v < sec(A j ) for all j ∈ {1, . . ., k}, a new end vertex was appended to A i in the processing step of v (the end vertex was not replaced, as this would not have changed sec(A i )).This must have been done in Line 13 of Algorithm 1 and we conclude v < v = sec(A i ), which contradicts the assumption.
For Invariant (4), consider Line 7 of the processing step of v.As showed in the proof of v < v above, we have left j i−1 (sec(A j i )) < v for all 1 < i ≤ l.Thus, Invariants (1) and (3) imply that exactly the path A j l of the paths A 1 , . . ., A k contains v.
Invariant (5) follows directly from the definition of left i .This concludes the correctness part of the proof of Lemma 5.

Remark Invariant (4) cannot be strengthened to
as the cyclic downshifting may force A i to contain edges of F k or F 1 : During the construction, many active vertices v ∈ T k may occur at which all k paths (temporarily) end (see Fig. 2, for which each of the three paths A 1 , A 2 , A 3 contains edges of every tree T 1 , T 2 , T 3 ).So far we have shown an algorithmic proof for the existence of k s-disjoint paths from s to the roots r 1 , . . ., r k .It remains to show the running time for Lemma 5.At every point in time, we maintain the order A 1 < • • • < A i on our i ≤ k internally vertex-disjoint paths, where i is the index of the root vertex r i that will be visited next.This ordered list can be updated in constant time after each cyclic downshift by modifying the position of one element.Let v be the currently active vertex and let r i ≤ v be the root vertex that will be visited next.Consider the ordered list of unfinished paths A 1 < • • • < A i just before invoking Line 5. For Line 5, we need to sort the subset A j 1 , . . ., A j l ( j l ≤ i) of such paths ending at v according to <.In order to do this, we run through the i paths A 1 < • • • < A i in that order, check for each entry whether its end vertex is v, and if so, append it to the sorted list

Computing Vertex-Disjoint Paths Between Two Vertices
We use the algorithm of the last section to prove our following main result.

Theorem 6 Let t < s be a vertex in T k . Then k internally vertex-disjoint paths between s and t can be computed in time O(|E(T
This theorem is directly implied by the following lemma.

set of k internally vertex disjoint paths from s to t. Moreover, all paths are contained in T 1 ∪ • • • ∪ T k and can be computed by Algorithm 2 in time O(|E(T 1 ∪ • • • ∪ T k )|).
A first idea would be to use the loose ends-algorithm twice, once for the start vertex s and once for the start vertex t, in order to find the paths A i and B i for all i.However, in general this is bound to fail, as Figure 3 shows.A second attempt may try to finish two paths A i and B j whenever they end at the same active vertex.However, this may fail when i = j, as then two single paths A i and B j may remain that end at the respective roots r i and r j > r i such that B j cannot be extended to r i without violating the index scheme of Invariant (2), as Fig. 4 shows.
We will nevertheless use Algorithm 1 to prove Lemma 7, but in a more subtle way, as outlined next.First, we compute the paths A 1 , . . ., A k with start vertex s using Algorithm 1, until the largest active vertex v is less or equal t (i.e. the parts of the A i between s and t are just computed by Algorithm 1).As soon as v ≤ t, we additionally construct a second set of paths B 1 , . . ., B k with start vertex t using Algorithm 1.
The main difference to Algorithm 1 from this point on is that we extend the paths A i and the paths B i in parallel (i.e.we take the largest active vertex of both running constructions) such that, after the processing step of v, the vertex v is not contained in any two paths A i and B j with i = j.This ensures the vertex-disjointness.
If no A-path or no B-path ends at v, we again just perform Algorithm 1; then at most one path contains v after the processing step.Otherwise, some A-path and some B-path ends at v.After the processing step at v, we want to have exactly two paths A j and B j (i.e.having the same index) that end at v; such a pair of paths is then finished.In order to ensure this, we choose j as the largest index such that A j or B j ends at v before processing v.If both A j and B j end at v, we perform one processing step of Algorithm 1 at v for the A-paths and the B-paths, respectively, which implies that no other path is ending at v.
Otherwise, exactly one of the paths A j and B j ends at v, say A j .Then B j is not finished, as we finish only paths having the same index, and the last edge of B j is in F j .By assumption, there is an index i < j such that B i ends at v. We then apply a processing step of Algorithm 1 (including a cyclic downshift) on B j and all B-paths that end at v, and one on all A-paths, respectively.Then the new paths A j and B j (due to cyclic downshifts, these correspond to the former A-and B-paths with lowest index ending at v) end at v afterward, but no other A-or B-path, as desired.Note that the replacement of the last edge of (the old) B j , which did not end at v but, say, at a vertex w, may cause w to be active although neither an A-path nor a B-path ends at w.
For a precise description of the approach, see Algorithm 2. We now show that Algorithm 2 outputs the desired paths and thus proves Lemma 7. The following observations follow directly from Algorithm 2.
(1) For every i ∈ {1, . . ., k}, A i and B i are both finished or both unfinished.
(2) As long as the largest active vertex is larger than t, (3) The end vertex of every unfinished path is active.
We prove Lemma 7 by showing that Algorithm 2 outputs the desired paths.Before the processing step of any active vertex v, the paths A i and B i satisfy several invariants, the most crucial of which are that they are {v + 1, . . ., s − 1}\{t}-disjoint and that the vertices of every A i and B i are decreasing in <.We will prove the following invariants.
Invariants Let v < s be the largest active vertex, or v := 0 if there is no active vertex left.Before processing v, the following invariants are satisfied for every 1 ≤ i ≤ k: (1) A i starts with s, B i starts with t, and the vertices of both paths are strictly decreasing in <. continue with further consequences of some of these invariants, which will be used later.

(2) The paths A i and B i are finished if and only if v < end(A
Observation 9 Let v < s be the largest active vertex, or v := 0 if there is no active vertex left.Before processing v, we have the following observations: (1) Assume Invariants ( 1) and (3).Then, for every 1 ≤ i ≤ k, all vertices of the paths A i and B i except end(A i ) and end(B i ) are greater than v before processing v. (2) Assume Invariant (2).Then no finished path is modified while processing v, as Algorithm 2 modifies A i or B i , 1 ≤ i ≤ k, only if at least one of them ends at v. (3) Assume Invariants (2) and (3).Then the largest active vertex after processing v > 0 is smaller than v.

Proof
The following proof of Observation (3) uses the fact that new active vertices are only created after Lines 22, 25, 33 and 36.When Line 22 replaces the end vertex of A i 2 , the new end vertex left i 1 (sec(A i 2 )) is smaller than the old one due to Corollary 4. By the previous observation, A i 2 is not finished.According to Invariant (2), the new end vertex of A i 2 is smaller than v.
When invoking Line 25, |I B ∪ { j}| ≥ 2 and, hence, there is at least one path B i that ends at v = t: According to Invariant (3), v < t and B i 2 has length at least one such that sec(B i ) > v. Thus, the new end vertex of B i 2 is smaller than the old one and, in particular, smaller than v.
The vertices marked as active in Line 33 and 36 are smaller than v by definition of left.
We now prove Invariants (1)-( 5) for all largest active vertices encountered in the algorithm.Immediately after initializing the paths A 1 , . . ., A k and B 1 , . . ., B k , the largest active vertex is end(A k ) < s or t.It is easy to see that all five invariants are satisfied for v = max{end(A k ), t}, i.e. before processing the first active vertex.We will prove that processing any largest active vertex v preserves all five invariants for the largest active vertex v after having processed v (here, we set v := 0 if v is the last active vertex).For this purpose, let A i and B i be the paths with index i immediately before processing v and let A i and B i be the paths with index i immediately before processing v .By induction hypothesis, A i and B i satisfy the desired invariants for the vertex v; hence, we can also use their implications in Observation 9.In particular, v < v due to Observation 9.(3).
We assume first v = t and that v is not the end vertex of any of the paths A 1 , . . ., A k , B 1 , . . ., B k (the following cases can thus assume that at least one such path ends at v).Then Line 19 cancels the processing step without changing any path.According to Observation 9.(1), v is not contained in any of the paths A 1 , . . ., A k , B 1 , . . ., B k .The paths 1) and ( 5) also for v .They also satisfy Invariant (3) for v , since v ≥ t if v > t, and Invariant (2) for v , since the largest end vertex of any unfinished path is at most v , according to Observation 8. (3).By Invariant (2) for v and Observation 9.(1), any vertex w = t with v < w ≤ v is contained in A i or B i only if A i or B i is unfinished and has end vertex w.Then w is active due to Observation 8.(3), which contradicts the choice of v .Any w > v would give Invariant (4) by induction hypothesis.Thus, Invariant (4) is satisfied for v .
Next, we assume v > t.Then the paths A 1 , . . ., A k are all not finished and, according to Invariant (3), B 1 = • • • = B k = (t).We thus have I B = ∅ in Line 17 and j = max I A in Line 20.In particular, the paths B 1 , . . ., B k are not modified while processing v and the changes of A 1 , . . ., A k are identical to the ones in the loose ends algorithm.Thus, A 1 , . . ., A k satisfy the invariants of the loose ends algorithm for v , which imply the invariants of Algorithm 2 for v , as t ≤ v .
We assume v = t.Then left i (t) exists in Line 12, since we have end(A i ) = t, which implies by Invariant (2) that A i is not finished and r i ≤ end(A i ) < t = v.The paths A 1 , . . ., A k , B 1 , . . ., B k satisfy Invariant (1) for v due to left i (t) < t for every i, Observation 8.(2) and Invariant (1) for v.We prove Invariant (2) for v : If A i and B i are finished, end(A i ) = t before processing v and we conclude v < end(A i ) = end(B i ) = t.Otherwise, the algorithm leaves both A i and B i unfinished by setting A i := A i and B i := (t, left i (t)).Since both end(B i ) = left i (t) and end(A i ) = end(A i ) are active after processing t, r i ≤ end(B i ) ≤ v and r i ≤ end(A i ) ≤ v .In particular, both A i and B i are of length at least one and have their last edge in T i , which gives Invariant (2) for v .
For Invariants (3) and ( 5), note that A i = A i and B i = (t) if B i is finished and otherwise A i = A i and B i = (t, left i (t)).It remains to prove Invariant (4).If A i contains a vertex w with v < w < t (again, any larger w would give Invariant (4) by induction hypothesis), w is the active end vertex of A i by Observations 9.(1) and 8.(3), which contradicts the choice of v .Since B i consists of t and at most one active vertex that is smaller or equal to v , the vertex w of Invariant (4) does not exist.This proves Invariant (4) for v .
It only remains to assume v < t.According to the statement of our first case, we can additionally assume I A ∪ I B = ∅ (as defined in Lines 16 and 17).Let j be the index chosen in Line 20 of processing step v. Then Observation 8.(1) ensures that both A j and B j are unfinished; hence, the downshifts in Lines 27 and 28 are well-defined.The paths A 1 , . . ., A k , B 1 , . . ., B k satisfy Invariant (1) for v due to Invariant (1) for v, the fact that left i (v) < v for all i, and Observation 9.(3).
We prove Invariant (2) for v : By induction, this invariant is true for the paths that were finished before processing v.For all paths A i and B i that are unfinished after processing v, Observation 8.(3) ensures that end(A i ) ≤ v and end(B i ) ≤ v .The cyclic downshifts in processing step v imply that the last edge of A i and the last edge of B i are in T i for every i = j.Since A j and B j are the only paths that may change their status from unfinished to finished during the processing step of v, this gives Invariant (2) for all paths except for A j and B j .These two paths are finished after processing step v if and only if v < v = end(A j ) = end(B j ).In this case, Invariant (2) for v is satisfied.The case end(A j ) = v = end(B j ) (and, by symmetry, the case end(A j ) = v = end(B j )) only occurs if I A = ∅ in processing step v.In this case A j = A j and end(B j ) = left j (v).By Observation 8.(3) and Invariant (2) for v, r j ≤ end(A j ) ≤ v and the last edge of A j is in T j .This gives Invariant (2) for v .
In order to prove Invariant (3) for v , observe that all modified paths are unfinished and have length at least one.Thus, we only have to prove that, when appending a vertex to a path in processing step v, the new second last vertex (i.e. the old end vertex) is greater than v .The algorithm does this only in Lines 32 and 35, in which v > v is the new second last vertex.
We prove Invariant (4) for v .If v < w < s, this follows directly from Invariant (4) for v, so let v < w ≤ v. First, suppose w < v such that w is contained in A i ∪ B i .Then w is active after processing v by Invariants (1) and (3) for v , which contradicts the choice of v .Second, suppose w = v.Let j be the index chosen in Line 20 of processing step v.If both paths A j and B j contain v, both end at v and are finished by Line 30.It remains to prove that v = w is not contained in any other path than A j and B j .If any path A i or B i contains v before processing step v, it contains v as end vertex by Observation 9(1).All paths with v as end vertex, except for the one with smallest index, get a new end vertex in processing step v.After the cyclic downshift in processing step v, only the paths with index j contain v.This proves Invariant (4) for v .
Invariant (5) follows straight from the definition of left i .This concludes the proof of Invariants (1)-( 5) for every v < s.
As in the loose ends algorithm, the running time of Algorithm 2 is upper bounded by O(|E(T 1 ∪ • • • ∪ T k )|) and thus by O(n + m), as it suffices to visit every edge in the trees T 1 , . . ., T k a constant number of times.

Variants
Several variants of Menger's theorem [13] are known.Instead of computing k paths between two vertices, we can compute paths between a vertex and a set of vertices (fan variant) and between two sets of vertices (set variant).Our algorithm extends to these variants.
Theorem 10 Let G be a simple graph and <, s and T 1 , . . ., T k be defined as in Sect. 2.
(i) (Fan variant) Let T = {t 1 , . . ., t k } be a subset of V such that r i ≤ t i < s for every i.Then k internally vertex-disjoint paths between s and T can be Proof Let G be the subgraph of G that is induced by the vertex set {1, . . ., s}.Clearly, < is also a MAO of G (restricted to the vertices 1, . . ., s) and the relevant parts of the trees T 1 , . . ., T k are preserved by Lemma 3.For (i), augment G by a new vertex s + 1 with k edges to t 1 , . . ., t k ; this preserves that < is a MAO.Applying Theorem 6 to this graph on the vertices s and s + 1 gives the claim.For (ii), we augment G by two new vertices of degree k with neighborhoods S and T , respectively, and apply Theorem 6 on the vertices s + 1 and s + 2. In both cases, the running time is not increased.

Fig. 1 A
Fig. 1 A run of Algorithm 1 on the graph depicted in a when s = 12 and k = 3 (Color figure online)

Fig. 2
Fig. 2 The output of Algorithm 1 on the graph depicted in a when s = 12 and k = 3 (Color figure online) this running time is upper-bounded by the number of such left-edges plus one.Summing the number of these left-edges for every visited v thus gives a running time bound of O(|E(T 1 ∪ • • • ∪ T k )|) for all invocations of Line 5. Since the algorithm visits every edge only a constant number of times, this implies a total running time of O(|E(T 1 ∪ • • • ∪ T k )|) ⊆ O(n + m).
and the last edge of A i as well as the last edge of B i (if B i has length at least 1) are in T i .