## Finding a Shortest M -link Path in a Monge Directed Acyclic Graph

## Joy Z. Wan

Siebel School of Computing and Data Science University of Illinois Urbana-Champaign

## Abstract

A Monge directed acyclic graph (DAG) G on the nodes 1 , 2 , · · · , N has edges ( i, j ) for 1 ≤ i &lt; j ≤ N carrying submodular edge-lengths. Finding a shortest M -link path from 1 to N in G for any given 1 &lt; M &lt; N -1 has many applications. In this paper, we give a contract-and-conquer algorithm for this problem which runs in O ( √ NM N ( -M ) log ( N -M ) ) time and O N ( ) space. It is the first o ( NM )-time algorithm with linear space complexity, and its time complexity decreases with M when M ≥ N/ 2. In contrast, all previous strongly polynomial algorithms have running time growing with M . For both O poly ( (log N )) and N -O poly ( (log N )) regimes of M , our algorithm has running time O N ( · poly (log N )), which partially answers an open question rased in [2] affirmatively.

Keywords: Monge graph; parametric search; contact and conquer

## 1 Introduction

Many algorithmic problems [2, 3] can be reduced to seeking a shortest M -link path in a Monge directed acyclic graph (DAG) G on nodes 1 2 , , · · · , N with 1 ≤ M ≤ N -1. The edge set of G is { ( i, j ) : 1 ≤ i &lt; j ≤ N } ; and the edge-length (or edge-weight) function c of G satisfies that for any 1 ≤ i &lt; j &lt; k &lt; l ≤ N ,

$$\begin{array} {$$

In addition, the length c ( i, j ) of each edge ( i, j ) can be evaluated in constant time. A path P in G specified by the sequence

$$s = v _ { 0 }, v _ { 1 }, \cdots, v _ { m$$

is said to be an m -link s t -path, and its length is the total length of edges in P . The path P is called a shortest m -link s t -path if P has the minimum length among all m -link s t -paths.

As observed by [2, 3], a shortest M -link 1N path in G can be computed in O NM ( ) time and space by the standard dynamic programming accelerated by the celebrated SMAWK algorithm [1]. A parametric search scheme was also introduced in [2, 3] for computing a shortest M -link 1N path in G . When the edge lengths are restricted to integers, the binary search method yields a weakly polynomial algorithm [2, 3]. A strongly polynomial algorithm with sub-quadratic complexity was developed in [2], which is referred to the algorithm AST. The algorithm AST follows Megiddo's parametric search paradigm [7], and runs in O N ( √ M log N + N log N ) time and O N ( √ M log N ) space. For the Ω (log N ) regime of

M , the algorithm AST [2] is superior to the O NM ( )-time accelerated dynamic programming; and the existence of an O N ( · poly (log n ))-time algorithm was raised as an open question in [2].

For the same Ω (log N ) regime of M , Schieber [8] gave a recursive parametric search algorithm with O ( N 2 4 √ (log M )(log log N ) ) running time. Schieber's algorithm is superior to the algorithm AST [2] when M = Θ( N ), but may be inferior when M = Θ( poly (log N )). Indeed when M = log 16 N , Schieber's algorithm has the same asymptotic time complexity O N ( log 16 N ) = O NM ( ) as the accelerated dynamic programming, while the algorithm AST [2] has time complexity O N ( log 8 5 . N ) and is asymptotically faster by a factor of Θ ( log 7 5 . N ) . Similarly, when M = log 4 N , Schieber's algorithm has time complexity O N ( log 8 N ) = O NM ( 2 ) , which is even asymptotically slower by a factor of Θ ( M ) than the accelerated dynamic programming.

Schieber [8] also noted, with no analysis, the linear space complexity of his recursive algorithm. A careful look into the recursion reveals that the space complexity hidden within the recursion is more than linear order. The recursion runs on an auxiliary DAG with modified lengths of all edges from the node 1. These modified lengths have to be maintained on the recursion stack, and the space needed for maintaining these modified lengths grows with the recursion depth and certainly exceeds the linear order. There is no apparent fix for such recursive algorithm to achieve the linear space complexity.

In addition to the superlinear space complexity, all of the above strongly polynomial algorithms have time complexity strictly growing with M . However, the closeness of M to N could be beneficial for the computation of a shortest M -link 1N path. If M = N -1, then there is a single ( N -1)-link 1N path. If M = N -2, then there are N -2 ( N -2)-link 1N paths, each of which can be generated from the unique ( N -1)-link 1N path by removing an internal node. Thus, a shortest ( N -2)-link 1N path can also be computed in linear time and space. In fact, there is a symmetry between these two 'largest' cases and the two 'smallest'cases. If M = 1, then there is a single 1-link 1N path. If M = 2, then there are N -2 2-link 1N paths, each of which can be generated by adding an internal node. In general, the number of m -link 1N paths and the number of ( N -m )-link 1N paths are both equal to

$$\binom { N - 2 } { m - 1 } = \binom { N - 2 }$$

This symmetry sheds light on the room of improvement when M is close to N .

In this paper, we present a contract-and-conquer algorithm for computing a shortest M -link 1N path iteratively in O ( √ NM N ( -M ) log ( N -M ) ) time and O N ( ) space. Thus, it is the first o ( NM )-time algorithm with linear space complexity. For the O poly ( (log n )) and N -O poly ( (log n )) regimes of M , the contract-and-conquer algorithm has an O N ( · poly (log n )) runtime, and hence partially answers the open question in [2] affirmatively. For all M , the contract-and-conquer algorithm is superior to the algorithm AST [2] in both time and space complexity. For M around N/ 2, the contract-and-conquer algorithm is inferior to Schieber's algorithm [8] in time complexity in return for superior space complexity. The contract-and-conquer algorithm follows the elementary decreasing-and-conquer paradigm. It is conceptually simple and easy for implementation.

The following notations and terms are used in this paper. For two integers a and b with a ≤ b , the closed integer interval [ a : b ] denotes the set of integers k with a ≤ k ≤ b ; and ( a : b ] represents [ a : b ] \{ } a . For a positive integer n , [ n ] is a shorthand for [1 : n ]. A set L ⊆ Z 2 is a lattice [9] if for any

two members ( i 1 , j 1 ) and ( i 2 , j 2 ) in L with i 1 &lt; i 2 and j 1 &gt; j 2 , both ( i 1 , j 2 ) and ( i 2 , j 1 ) are also in L . A real-valued function ρ on a lattice L is submodular [9] if for any two members ( i 1 , j 1 ) and ( i 2 , j 2 ) in L with i 1 &lt; i 2 and j 1 &gt; j 2 ,

$$\rho \left ( i _ { 1 }, j _ { 1 } \right ) + \$$

A Monge DAG on an integer interval [ s : N ] is a complete DAG on [ s : N ] with a submodular edgelength function on the edge lattice { ( i, j ) : s ≤ i &lt; j ≤ N } . Throughout this paper, 1 ≤ s &lt; N and G s is a Monge DAG on [ s : N ] with edge-length function c s .

The remainder of this paper is organized as follows. Section 2 presents a parsimonious dynamic programming for computing the lengths of a collection of shortest m -link paths. Section 3 introduces the notion of minimal and maximal shortest-path trees and characterizes their depth properties. Section 4 elaborates precisely on the parametric search scheme for computing a shortest m -link path. Section 5 develops a key probe procedure with the hit-or-contract nature. Section 6 describes the contractand-conquer algorithm and analyzes its complexity. Section 7 concludes with discussion on possible improvements.

## 2 A Parsimonious Dynamic Programming

Suppose 1 ≤ s &lt; N and G s is a Monge DAG on [ s : N ] with edge-length function c s . For each n ∈ [ s +1 : N ], there is an m -link s n -path if and only if m ∈ [ n -s ]. We use L s to denote the lattice

$$\left \{ \left ( m, n \right ) \colon n \in \left [$$

For each ( m,n ) ∈ L s , let f s ( m,n ) denote the minimum length of all m -link s n -paths in G s , and P ∗ s ( m,n ) denote the set of all shortest m -link s n -paths in G s . The following computation task is needed frequently in our later algorithm: Given ( m,n ) ∈ L s with m&gt; 1 and s + m&lt;n ≤ N , compute f s ( m,j ) for all i ∈ [ s + m n : ] and f s ( m +1 , j ) for all j ∈ [ s + m +1 : n ]. The outputs are stored in two global arrays f and f : f s ( m,j ) is stored at f ( j ), and f s ( m +1 , j ) is stored at f ( j ). In this section, we present a parsimonious dynamic programming for this task which runs in Θ ( m n ( -s +1 -m )) time and Θ( n -s +1 -m ) working space.

All f s ( k, j ) for ( k, j ) ∈ L s satisfy a variant of the Bellman-Ford recurrence:

- · f s (1 , j ) = c s ( s, j ) for each j ∈ [ s +1 : N ];
- · for each ( k, j ) ∈ L s with k &gt; 1,

$$f _ { s } \left ( k, j \right ) = \min _ { i \in [ s + m - 1 \colon j - 1 ] } \left [ f _ { s } \left ( k - 1, i \right ) + c _ { s } \left ( i, j \right ) \right ].$$

The parsimonious dynamic programming exploits the minimal recurrence dependence as illustrated in Figure 1:

- · The entries f s ( m,j ) for j ∈ [ s + m n : ] depend exactly on the entries f ( m -1 , j ) for all j ∈ [ s + m -1 : n -1].

- · In turn, the entries f s ( m -1 , j ) for j ∈ [ s + m -1 : n -1] further depend exactly on the entries f s ( m -2 , j ) for all j ∈ [ s + m -2 : n -2], and so on.

Recursively, the outputs depend exactly on the ( m -1) ( n -s +1 -m ) entries f s ( k, j ) for all k ∈ [1 : m -1] and j ∈ [ s + k : n -m + ]. k

Figure 1: Minimal recurrence dependence.

![Image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00227v1-figure-8a99694a-5c98-45dd-a400-a828cd454fb2.jpg)

Accordingly, we get the explicit 'minimal' recurrence:

- · f s (1 , j ) = c s ( s, j ) for each j ∈ [ s +1 : n -m +1].
- · For each 2 ≤ k ≤ m and each j ∈ [ s + k : n -m + ], k

$$f _ { s } \left ( k, j \right ) = \min _ { i \in [ s + k - 1 \colon j - 1 ] } \left [ f _ { s } \left ( k - 1, i \right ) + c _ { s } \left ( i, j \right ) \right ].$$

- · For each j ∈ [ s + m +1 : n ],

$$f _ { s } \left ( m + 1, j \right ) = \min _ { i \in [ s + m \colon j - 1 ] } \left [ f _ { s } \left ( m, i \right ) + c _ { s } \left ( i, j \right ) \right ].$$

For each 2 ≤ k ≤ m , the set

$$\{ ( i, j ) \colon s + k - 1 \leq i < j \leq n - m + k \}$$

is a sublattice of the edge lattice, and f s ( k -1 , i ) + c s ( i, j ) is submodular in ( i, j ) on this lattice; hence the SWAWK algorithm can be applied to compute f s ( k, j ) for all j ∈ [ s + k : n -m + ] in k Θ( n -s +1 -m ) time and space. Similarly, the SWAWK algorithm can be applied to compute f s ( m +1 , j ) for all j ∈ [ s + m +1 : n ] in Θ ( n -s -m ) time and space.

A subroutine PBF ( s, m, n ) implementing the parsimonious dynamic programming is outlined in Table 1:

- · Initialize f ( j ) = c s ( s, j ) for each j ∈ [ s +1 : n -m +1].

- · For k = 2 to m , first apply the SWAWK algorithm to compute

$$\overline { f } \left ( j \right ) = \min _ { i \in [ s + k - 1 \colon j - 1 ] } \left [ f \left ( i \right ) + c _ { s } \left ( i, j \right ) \right ]$$

for all j ∈ [ s + k : n -m + ]; and then overwrite k f ( j ) with f ( j ) for all j ∈ [ s + k : n -m + ]. k

- · Finally, apply the SWAWK algorithm to compute

$$\overline { f } \left ( j \right ) = \min _ { i \in [ s + m \colon j - 1 ] } \left [ f \left ( i \right ) + c _ { s } \left ( i, j \right ) \right ]$$

$$\text{for all } j \in [ s + m + 1 \colon n ].$$

Clearly, the subroutine PBF ( s, m, n ) runs in Θ( m n ( -s +1 -m )) time and needs additional O n ( -s +1 -m ) working space by the SWAWK algorithm.

$$\text{orking space by the $wAwK$ algorithm}. \\ \frac { \text{PBF} ( s, m, n ) \colon } { \text{ for $j=s+1$ to $n-m+1$ do $f(j) \leftarrow c _ { s } ( s, j ) ; } } \frac { } { \text{ for $k=2$ to $m$ do} } \quad \text{for $j=s+k$ to $n-m+k$ do} \, \text{//SMAWK} } \quad \frac { } { \text{$f(j) \leftarrow \min_{i\in[s+k-1:j-1] }[f(i)+c_{s}(i,j)]; } } \quad \text{for $j=s+k$ to $n-m+k$ do} \, \text{for $f(j) \leftarrow \frac{}{\text{$j}(j);}$} } \quad \text{for $j=s+m+1$ to $n$ do} \, \text{//SMAWK} } \quad \frac { } { \text{$f(j) \leftarrow \min_{i\in[s+m:j-1] }[f(i)+c_{s}(i,j)]; } } \quad \text{Table 1: Outline of PBF} ( s, m, n ).$$

Table 1: Outline of PBF ( s, m, n ).

## 3 Minimal and Maximal Shortest-Path Trees

Suppose 1 ≤ s &lt; N and G s is a Monge DAG on [ s : N ] with edge-length function c s . A shortest-path tree (SPT) in G s is a directed tree on [ s : N ] in which the tree path from s to each node n is a shortest s n -path in G s . In this section, we introduce the notion of minimal SPT and maximal SPT, and assert that they are also respectively a shallowest SPT and a deepest SPT.

For each n ∈ [ s : N ], let F s ( n ) be the minimum length of all s n -paths in G s . All F s ( n ) for n ∈ [ s : N ] satisfy the recurrence: F s ( s ) = 0; and for each n ∈ [ s +1 : N ],

$$F _ { s } \left ( n \right ) = \min _ { i \in [ s \colon n - 1 ] } \left [ F _ { s } \left ( i \right ) + c _ { s } \left ( i, n \right ) \right ].$$

Denote Π s ( s ) := { } 0 ; and for each n ∈ [ s +1 : N ] denote

$$\Pi _ { s } \left ( n \right ) \coloneqq \arg \min _ { i \in [ s \colon n - 1 ] } \left [ F _ { s } \left ( i \right ) + c _ { s } \left ( i, n \right ) \right ].$$

Each SPT in G s is uniquely defined by a parent selection π : [ s +1 : N ] → [ s : N -1] satisfying that π ( n ) ∈ Π ( s n ) for each n ∈ [ s +1 : N ], and vice versa. For each n ∈ [ s : N ], let π min s ( n ) (resp., π max s ( n ))

be the least (resp., greatest) member in Π s ( n ). Note that π min s ( s ) = π min s ( s ) = 0. As F s ( ) + i c s ( i, n ) is submodular in ( i, n ) on the edge lattice of G s , both π min s ( n ) and π max s ( n ) increase with n ∈ [ s +1 : N ]. The minimal (resp., maximal ) SPT T min s (resp., T max s ) in G s is the SPT in G s defined by π min s (resp., π max s ).

For each n ∈ [ s : N ], let D s ( n ) be the set of numbers of links in all shortest s n -paths in G s , and d min s ( n ) (respectively, d max s ( n )) be the least (respectively, greatest) member in D s ( n ). Clearly, D s ( s ) = { } 0 . For each n ∈ [ s +1 : N ], each shortest s n -path in G s with m ∈ D s ( n ) links must belong to P ∗ s ( m,n ) and have length f s ( m,n ); hence

$$F _ { s } \left ( n \right ) & = \min _ { ( m, n ) \in \mathcal { L } _ { s } } f _ { s } \left ( m, n \right ) = \min _ { m \in [ n - s ] } f _ { s } \left ( m, n \right ), \\ D _ { s } \left ( n \right ) & = \arg \min _ { m \in [ n - s ] } f _ { s } \left ( m, n \right ).$$

Thus, the collection of shortest s n -paths in G s is exactly the union of P ∗ s ( m,n ) over all m ∈ D s ( n ). The theorem below asserts that T min s (resp, T max s ) is also a shallowest (resp., deepest ) SPT.

Theorem 3.1 The depth of each n ∈ [ s : N ] in T min s (resp., T max s ) is exactly d min s ( n ) (resp., d max s ( n ) ). In addition, all nodes with the same depth in T min s (resp, T max s ) are consecutive.

To prove the above theorem, we describe a path swapping operation which is more direct and explicit than the variants in [2, 3, 8]. Consider two paths

$$P & = ( u _ { 0 }, u _ { 1 }, \cdots, u _ { m _ { 1 } } ) \,, \\ Q & = ( v _ { 0 }, v _ { 1 }, \cdots, v _ { m _ { 2 } } )$$

$$v _ { 0 }, v _ { 1 }, \cdots,$$

in G s with 1 ≤ m 1 ≤ m 2 and u 0 ≤ v 0 &lt; v m 2 ≤ u m 1 (see Figure 2). For any m ∈ [ m 1 : m 2 ], we construct an m -link v 0 -u m 1 path Q ⊕ m P and an ( m 1 + m 2 -m )-link u 0 -v m 2 path Q /circleminus m P in two steps:

Figure 2: Path swapping.

![Image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00227v1-figure-657c9a8c-c95e-48ca-a190-871c42a364e6.jpg)

- · Step 1 : Compute the least k ∈ [ m 1 ] with u k ≥ v m m -1 + k . Such k does exist as u m 1 ≥ v m 2 ≥ v m = v m m -1 + m 1 . Then u k -1 ≤ v m m -1 + k -1 : if k = 1 then

$$u _ { k - 1 } = u _ { 0 } \leq v _ { 0 } \leq v _ { m - m _ { 1 } } = v _ { m - m _ { 1 } + k - 1 } ;$$

otherwise u k -1 &lt; v m m -1 + k -1 by the least choice of k . Hence,

$$u _ { k - 1 } \leq v _ { m - m _ { 1 } + k - 1 } < v _ { m - m _ { 1 } + k } \leq u _ { k }.$$

- · Step 2 : Replace the edges ( u k -1 , u k ) in P and ( v m m -1 + k -1 , v m m -1 + k ) in Q respectively with the edges ( u k -1 , v m m -1 + k ) and ( v m m -1 + k -1 , u k ) to get

$$& Q \oplus _ { m } P \coloneqq ( v _ { 0 }, \cdots, v _ { m - m _ { 1 } + k - 1 }, u _ { k }, \cdots, u _ { m _ { 1 } } ) \,, \\ & Q \ominus _ { m } P \coloneqq ( u _ { 0 }, \cdots, u _ { k - 1 }, v _ { m - m _ { 1 } + k }, \cdots, v _ { m _ { 2 } } ) \,.$$

By the submodularity of c s , the two new edges have no larger sum-length than the two old edges. Thus,

$$c _ { s } \left ( P \right ) + c _ { s } \left ( Q \right ) \geq c _ { s } \left ( Q \oplus _ { m } P \right ) + c _ { s } \left ( Q \ominus _ { m } P \right ).$$

The swapping of two shortest s n -paths with d min s ( n ) and d max s ( n ) links respectively has the following direct consequence.

Lemma 3.2 Suppose n ∈ [ s +1 : N ] , and P (resp., Q ) is a shortest s n -path with d min s ( n ) (resp. d max s ( n ) ) links. Then for any m ∈ [ d min s ( n ) : d max s ( n ) ] , Q ⊕ m P is a shortest s n -path with m links. Hence, D s ( n ) = [ d min s ( n ) : d max s ( n ) ] .

For any N ≥ n 1 ≥ n 2 &gt; s and 1 ≤ m 1 ≤ m 2 ≤ n 2 -s , the swapping of a path in P ∗ s ( m ,n 1 1 ) and a path in P ∗ s ( m ,n 2 2 ) implies immediately the lemma below which is implicit in [2, 3, 8].

Lemma 3.3 Suppose N ≥ n 1 ≥ n 2 &gt; s and 1 ≤ m 1 ≤ m 2 ≤ n 2 -s . Then for any m ∈ [ m 1 : m 2 ] ,

$$f _ { s } \left ( m _ { 1 }, n _ { 1 } \right ) + f _ { s } \left ( m _ { 2 }, n _ { 2 } \right ) \geq f _ { s } \left ( m, n _ { 1 } \right ) + f _ { s } \left ( m _ { 1 } + m \, _ { 2 } - m, n _ { 2 } \right ).$$

In particular, f s ( m,n ) is a submodular function on L s .

The submodularity of f s ( m,n ) on L s and the minimizer representation of D s ( n ) in equation (2) imply the monotonicity of d min s ( n ) and d max s ( n ) with n ∈ [ s +1 : N ]. As d min s (0) = d max s ( n ) = 0, we get the following lemma.

Lemma 3.4 Both d min s ( n ) and d max s ( n ) increase with n ∈ [ s : N ] .

Now are ready to prove Theorem 3.1. Consider any n ∈ [ s +1 : N ]. By Lemma 3.4,

$$d _ { s } ^ { \min } \left ( n \right ) & = 1 + \min _ { i \in \Pi _ { s } \left ( n \right ) } d _ { s } ^ { \min } \left ( i \right ) = 1 + d _ { s } ^ { \min } \left ( \pi _ { s } ^ { \min } \left ( n \right ) \right ), \\ d _ { s } ^ { \max } \left ( n \right ) & = 1 + \max _ { i \in \Pi _ { s } \left ( n \right ) } d _ { s } ^ { \max } \left ( i \right ) = 1 + d _ { s } ^ { \max } \left ( \pi _ { s } ^ { \max } \left ( n \right ) \right ).$$

Thus, the first part of Theorem 3.1 holds. The second part of Theorem 3.1 then follows from Lemma 3.4.

All algorithms in [4, 5, 6, 10] can compute F s in linear time and space. Given F s , π min s (resp, π max s ) can be computed in linear time and space by a single application of the SWAWK algorithm. Given π min s (resp., π max s ) , d min s (resp., d max s ) can be computed in linear space and time by a tree traversal. If we only need the depth of N and/or the tree path from s to N in T min s (resp, T max s ), then a backtrack from N to s along π min s (or π max s ) is sufficient.

In [2, 8], a tie-breaking modification to the Wilber's algorithm [10] or Klawe's algorithm [5] was proposed for computing a shortest s N -path with the fewest (resp., most) links: Whenever the lengths of two paths are compared and found to be equal, the path with fewer (resp., more) links is considered lighter. While ambiguity remains when both the lengths and the number of links of two paths are compared and found to be equal, such further tie-breaking apparently still relies on the original lexicographic rule. The argument for the (non-obvious) monotonicity of the modified parent selection, which is essential to the application of the SWAWK algorithm, was missing in [2, 8]. In contrast, the construction of T min s (resp, T max s ) eliminates the need for tie-breaking by the number of links.

## 4 Parametric Shortest Paths

For each parameter λ ∈ R , let G s ( λ ) denote the DAG obtained from G s by subtracting λ from the length of each edge. Then, G s ( λ ) is also submodular. For any ( m,n ) ∈ L s , the collection of shortest m -link s n -paths in G s ( λ ) is still P ∗ s ( m,n ), and the length of each path in P ∗ s ( m,n ) in G s ( λ ) is f s ( m,n ) -mλ . Thus, for the purpose of seeking a path in P ∗ s ( M,N ), we may seek a shortest M -link s N -path in G s ( λ ) for any λ ∈ R . The general idea of the parametric search scheme [2, 3] is to find some parameter λ such that G s ( λ ) has a shortest s N -path with M links. For any such λ , each shortest s N -path in G s ( λ ) with M links is a path in P ∗ s ( M,N ), and one such path can be computed in linear time and space. In this section, we provide a concise and precise elaboration on the parametric search scheme [2, 3].

For each n ∈ [ s : N ], let F s ( λ, n ) be the minimum length of all s n -paths in G s ( λ ), and D s ( λ, n ) := [ d min s ( λ, n ) : d max s ( λ, n ) ] be the set of numbers of links in all shortest s n -paths in G s ( λ ). Clearly, F s ( λ, s ) = 0 and D s ( λ, s ) = { 0 . } For each n ∈ [ s +1 : N ],

$$\cdot m \lambda \, ] \,.$$

$$F _ { s } \left ( \lambda, n \right ) & = \min _ { m \in [ n - s ] } \left [ f _ { s } \left ( m, n \right ) - m \lambda \right ], \\ D _ { s } \left ( \lambda, n \right ) & = \arg \min _ { m \in [ n - s ] } \left [ f _ { s } \left ( m, n \right ) - m \lambda \right ].$$

Thus, the collection of shortest s n -paths in G s ( λ ) is exactly the union of P ∗ s ( m,n ) over all m ∈ D s ( λ, n ). Let T min s ( λ ) (resp., T max s ( λ )) denote the minimal (resp., maximal) SPT of G s ( λ ). Then for each n ∈ [ s : N ], d min s ( λ, n ) (resp., d max s ( λ, n )) is the depth of n in T min s ( λ ) (resp., T max s ( λ )) by Theorem 3.1.

Suppose M ∈ D s ( λ, N ). Then each path in P ∗ s ( M,N ) is a shortest s N -path in G s ( λ ). A path in P ∗ s ( M,N ) can be computed in linear time and space as follows:

- · Compute T min s ( λ ) and T max s ( λ ) in G s ( λ ), and let P and Q be the s N -paths in T min s ( λ ) and T max s ( λ ) respectively.
- · Construct Q ⊕ M P . By Lemma 3.2, Q ⊕ M P is a shortest s N -path in G λ ( ) with M links; hence Q ⊕ M P ∈ P ∗ s ( M,N ).

Thus, computing a path in P ∗ s ( M,N ) is reducible in linear time and space to finding a parameter λ with M ∈ D s ( λ, N ).

In the sequel, we characterize the range of λ such that m ∈ D s ( λ, n ) for a given ( m,n ) ∈ L s . For any n ∈ [ s +1 : N ], let

$$f _ { s } \left ( 0, n \right ) & = f _ { s } \left ( n - s + 1, n \right ) = + \infty \\ \dots \cdots \cdots$$

as no s n -path in G s has 0 or n -s +1 links; and let

$$\delta _ { s } \left ( m, n \right ) \coloneqq f _ { s } \left ( m + 1, n \right ) - f _ { s } \left ( m, n \right )$$

for each 0 ≤ m ≤ n -s . Note that δ s ( m,n ) is finite for each m ∈ [ n -s -1], δ s (0 , n ) = -∞ , and δ s ( n -s, n ) = + ∞ . By Lemma 3.3, δ s ( m,n ) increases with m and decreases with n . The theorem below gives an equivalent condition for d min s ( λ, n ) ≤ m and an equivalent condition for d max s ( λ, n ) ≥ m .

Theorem 4.1 For any ( m,n ) ∈ L s and λ ∈ R ,

- · d min s ( λ, n ) ≤ m if and only if λ ≤ δ s ( m,n ) ;
- · d max s ( λ, n ) ≥ m if and only if λ ≥ δ s ( m -1 , n ) .

## Proof. We first show that

$$\delta _ { s } \left ( d _ { s } ^ { \min } \left ( \lambda, n \right ) - 1, n \right ) < \lambda < \delta _ { s } \left ( d _ { s } ^ { \max } \left ( \lambda, n \right ), n \right ). \\ \vdots, n \right ), \, j \in D _ { s } \left ( \lambda, n \right ) \, \text{and} \, j - 1 \notin D _ { s } \left ( \lambda, n \right ) ; \, \text{hence}$$

For j = d min s ( λ, n ), j ∈ D s ( λ, n ) and j -1 / D ∈ s ( λ, n ); hence

$$\delta _ { s } \left ( j - 1, n \right ) - \lambda = F _ { s } \left ( \lambda, n \right ) - \left [ f _ { s } \left ( j - 1, n \right ) + \left ( j - 1 \right ) \lambda \right ] < 0.$$

For j = d max s ( λ ), j ∈ D s ( λ, n ) and j +1 / D ∈ s ( λ, n ); hence

$$\delta _ { s } \left ( j, n \right ) - \lambda = \left [ f _ { s } \left ( j + 1, n \right ) + \left ( j + 1 \right ) \lambda \right ] - F _ { s } \left ( \lambda, n \right ) > 0.$$

Thus, the two strict inequalities in equation (4) hold.

Now, we show that

δ s ( d max s ( λ, n ) -1 , n ) ≤ λ ≤ δ s ( d min s ( λ, n ) , n ) . (5) If d min s ( λ, n ) = d max s ( λ, n ), the inequalities hold strictly by equation (4). Suppose d min s ( λ, n ) &lt; d max s ( λ, n ). Then f s ( j, n ) + jλ = F s ( λ, n ) for j = d min s ( λ, n ), d min s ( λ, n ) + 1, d max s ( λ, n ) -1, and d max s ( λ, n ). Thus, the two inequalities in equation (5) hold with equality.

Next, we prove the first part of the theorem. If d min s ( λ, n ) ≤ m , then by equation (5)

$$\lambda \leq \delta _ { s } \left ( d _ { s } ^ { \min } \left ( \lambda, n \right ), n \right ) \leq \delta _ { s } \left ( m, n \right ). \\ 9$$

If d min s ( λ, n ) &gt; m , then by equation (4)

$$\lambda > \delta _ { s } \left ( d _ { s } ^ { \min } \left ( \lambda, n \right ) - 1, n \right ) \geq \delta _ { s } \left ( m, n \right ). \\ \text{cond part of the theorem. If } d _ { s } ^ { \max } \left ( \lambda, n \right ) \geq m, \text{ then}$$

$$\lambda \geq \delta _ { s } \left ( d _ { s } ^ { \max } \left ( \lambda, n \right ) - 1, n \right ) \geq \delta _ { s } \left ( m - 1, n \right ). \\. \, \iota \dots \, \dots \, \iota \dots \, \nu \, \nu$$

Finally, we prove the second part of the theorem. If d max s ( λ, n ) ≥ m , then by equation (5)

If d max s ( λ, n ) &lt; m , then by equation (4)

$$\lambda < \delta _ { s } \left ( d _ { s } ^ { \max } \left ( \lambda, n \right ), n \right ) \leq \delta _ { s } \left ( m - 1, n \right ).$$

Therefore, the theorem holds.

By Theorem 4.1, for any ( m,n ) ∈ L s and λ ∈ R , m ∈ D s ( λ, n ) if and only if δ s ( m -1 , n ) ≤ λ ≤ δ s ( m,n ). With a slight notational abuse, each closed extended-real interval excludes its infinite endpoints. For any ( m,n ) ∈ L s , denote

$$\Lambda _ { s } \left ( m, n \right ) \coloneqq \left [ \delta _ { s } \left ( m - 1, n \right ), \delta _ { s } \left ( m, n \right ) \right ]. \\ \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \ tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau\tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \taut \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \tau \vend{cases}$$

Then Λ s ( m,n ) is exactly the range of λ with m ∈ D s ( λ, n ).

In the remaining of this section, we derive monotonic properties of D s ( λ, n ) and Λ s ( m,n ). By Lemma 3.4, both endpoints of D s ( λ, n ) increase with n ∈ [ s, N ]; they also increase with λ ∈ R implied by the lemma below.

$$\text{Lemma } 4. 2 \text{ For any } n \in [ s, N ] \text{ and } \lambda _ { 1 } < \lambda _ { 2 }, \, d _ { s } ^ { \max } ( \lambda _ { 1 }, n ) \leq d _ { s } ^ { \min } \left ( \lambda _ { 2 }, n \right ).$$

Proof. As D s ( λ, s ) = { } 0 , the lemma holds trivially for n = ; henceforth we assume s n &gt; s . Denote m 1 := d max s ( λ , n 1 ) and m 2 := d min s ( λ , n 2 ). Then,

$$f _ { s } \left ( m _ { 1 }, n \right ) - m _ { 1 } \lambda _ { 1 } & = F _ { s } \left ( \lambda _ { 1 }, n \right ) \leq f _ { s } \left ( m _ { 2 }, n \right ) - m _ { 2 } \lambda _ { 1 }, \\ f _ { s } \left ( m _ { 2 }, n \right ) - m _ { 2 } \lambda _ { 2 } & = F _ { s } \left ( \lambda _ { 2 }, n \right ) \leq f _ { s } \left ( m _ { 1 }, n \right ) - m _ { 1 } \lambda _ { 2 }. \\ \text{above two inequality violated}$$

Summing up the above two inequalities yields

$$& m _ { 1 } \lambda _ { 1 } + m _ { 2 } \lambda _ { 2 } \geq m _ { 2 } \lambda _ { 1 } + m _ { 1 } \lambda _ { 2 }, \\ \diamond \quad \diamond \, \ e n n { \lambda _ { 1 } + m _ { 1 } \lambda _ { 2 }, }$$

and hence m 1 ( λ 2 -λ 1 ) ≤ m 2 ( λ 2 -λ 1 ). Thus, m 1 ≤ m 2 .

By Lemma 3.3, both endpoints of Λ ( s m,n ) increase with m ∈ [ n -s ] and decrease with n ∈ [ s + m +1 , N ]. In addition, the following 'vertical' downward monotonicity holds.

Lemma 4.3 For any ( m,n ) ∈ L s and any path ( v , 0 · · · , v m ) in P ∗ s ( m,n ) ,

$$\Lambda _ { s } \left ( 1, v _ { 1 } \right ) \supseteq \Lambda _ { s } \left ( 2, v _ { 2 } \right ) \supseteq \cdots \supseteq \Lambda _ { s } \left ( m, v _ { m } \right ).$$

Proof. We show that Λ s ( i, v i ) ⊇ Λ ( s i +1 , v i +1 ) for any 1 ≤ i &lt; m . Consider any λ ∈ Λ ( s i +1 , v i +1 ). Then i + 1 ∈ D s ( λ, v i +1 ); hence the subpath ( v , 0 · · · , v i , v i +1 ) is a shortest s v -i +1 path in G s ( λ ). Accordingly, the subpath ( v , 0 · · · , v i ) is a shortest s v -i path in G s ( λ ). So, i ∈ D s ( λ, v i ); hence λ ∈ Λ ( s i, v i ). Thus, Λ s ( i +1 , v i +1 ) ⊆ Λ ( s i, v i ).

Corollary 4.4 For any 1 ≤ m ≤ M ≤ N -s -1 and any path ( v , 0 · · · , v M +1 ) in P ∗ s ( M +1 , N ) , v m +1 ∈ [ s + m +1 : N -M + m ] and δ s ( m,v m +1 ) ≤ δ s ( M,N ) .

## 5 The m -Probe

Suppose G s is a Monge DAG on [ s : N ] with edge-length function c s , and 4 ≤ M ≤ N - -s 1. Consider a parameter m ∈ [2 : M -2]. The m -probe of G s is the least r ∈ [ s + m +1 : N -M + m ] satisfying that δ s ( m,r ) ≤ δ s ( M,N ). By Corollary 4.4, such r is well-defined. The m -probe r plays a pivotal role in seeking a member of Λ s ( M,N ).

For each j ∈ [ r : N ], let

$$h \left ( j \right ) \coloneqq \min _ { s + m \leq i < r } \left [ f _ { s } \left ( m, i \right ) + c _ { s } \left ( i, j \right ) \right ].$$

Note that h j ( ) is exactly the minimum length of all ( m +1)-link s j -paths with the penultimate node among [ s + m r : -1]. The contraction G r -1 of G s is a DAG on [ r -1 : N ] obtained from G s by

- · deleting all nodes in [ s : r -2], and
- · reassigning a length h j ( ) to the edge ( r -1 , j ) for each j ∈ [ r : N ].

Let c r -1 be the edge length function of G r -1 . Since r ≤ N -M + m ,

$$2 \leq M - m \leq N - r = N - ( r - 1 ) - 1.$$

The theorem below is the cornerstone to the design of our contract-and-conquer algorithm.

Theorem 5.1 G r -1 is Monge. If δ s ( m,r ) / ∈ Λ ( s M,N ) , then Λ r -1 ( M -m,N ) in G r -1 coincides with Λ ( s M,N ) in G s .

Proof. In order to prove G r -1 is Monge, it suffices to show that the quadruple inequality

$$c _ { r - 1 } \left ( r - 1, j + 1 \right ) - c _ { r - 1 } \left ( r - 1, j \right ) \geq c _ { r - 1 } \left ( r, j + 1 \right ) - c _ { r - 1 } \left ( r, j \right )$$

holds for any r &lt; j &lt; N . Let i ∈ [ s + m r : -1] be such that

$$c _ { r - 1 } \left ( r - 1, j + 1 \right ) = f _ { s } \left ( m, i \right ) + c _ { s } \left ( i, j + 1 \right ).$$

Then

Hence,

$$& c _ { r - 1 } \left ( r - 1, j + 1 \right ) - c _ { r - 1 } \left ( r - 1, j \right ) \\ & \geq c _ { s } \left ( i, j + 1 \right ) - c _ { s } \left ( i, j \right ) \\ & \geq c _ { s } \left ( r, j + 1 \right ) - c _ { s } \left ( r, j \right ) \\ & = c _ { r - 1 } \left ( r, j + 1 \right ) - c _ { r - 1 } \left ( r, j \right ).$$

$$= c _ { r - 1 } \left ( r, j + 1 \right ) - c _ { r - 1 } \left ( r,.$$

where the second inequality is due to the submodularity of c s .

$$c _ { r - 1 } \left ( r - 1, j \right ) \leq f _ { s } \left ( m, i \right ) + c _ { s } \left ( i, j \right ).$$

Suppose δ s ( m,r ) / ∈ Λ ( s M,N ). Then,

$$\delta _ { s } \left ( m, r \right ) < \delta _ { s } \left ( M - 1, N \right ).$$

Consider any M ′ ∈ [ M -1 : M +1]. Then, M ′ -m ∈ [ M -m -1 : M -m +1]. We prove that for any shortest ( M ′ -m )-link ( r -1)N path P = ( u , u 0 1 , · · · , u M ′ -m ) in G r -1 and any shortest M ′ -link s N -path Q = ( v , v 0 1 , · · · , v M ′ ) in G s , c r -1 ( P ) = c s ( Q ). Consequently, Λ r -1 ( M -m,N ) in G r -1 is identical to Λ s ( M,N ) in G s .

We first claim that v m &lt; r ≤ v m +1 . By Lemma 4.3,

$$\delta _ { s } \left ( m, v _ { m + 1 } \right ) \leq \delta _ { s } \left ( M ^ { \prime } - 1, N \right ) \leq \delta _ { s } \left ( M, N \right ) ; \\ \text{he least choice of $r$.    Note that $s+m\leq v_{m}<v_{m+1}$.                                                                                                                                                                                                        
                                                                                                                                                                                                        }                                                                                                                                                                                                        $                                                                                                                                                                                                        "                                                                                                                                                                                                       '                                                                                                                                                                                                       -                                                                                                                                                                                                       .                                                                                                                                                                                                        +                                                                                                                                                                                                       ,                                                                                                                                                                                                        )                                                                                                                                                                                                        ;                                                                                                                                                                                                        :                                                                                                                                                                                                        (                                                                                                                                                                                                        |                                                                                                                                                                                                        <                                                                                                                                                                                                        >                                                                                                                                                                                                        \end                                                                                                                                                                                                       !$$

hence r ≤ v m +1 by the least choice of r . Note that s + m ≤ v m &lt; v m +1 . The inequality v m &lt; r holds trivially if v m = s + m . Suppose v m ≥ s + m +1. Then by Lemma 4.3 and the two conditions M ′ ≥ M -1 and δ s ( m,r ) &lt; δ s ( M -1 , N ), we have

$$\delta _ { s } \left ( m, v _ { m } \right ) \geq \delta _ { s } \left ( M ^ { \prime }, N \right ) \geq \delta _ { s } \left ( M - 1, N \right ) > \delta _ { s } \left ( m, r \right ) ; \\ \text{Fhus, the claim holds.}$$

hence v m &lt; r . Thus, the claim holds.

Now, we show that c s ( Q ) ≥ c r -1 ( P ). As Q is a shortest M ′ -link s N -path in G s , the subpath ( v , 0 · · · , v m +1 ) is a shortest ( m +1)-link s v -m +1 path in G s . The previous claim yields that

$$c _ { r - 1 } \left ( r - 1, v _ { m + 1 } \right ) = c _ { s } \left ( v _ { 0 }, \cdots, v _ { m + 1 } \right ).$$

Let Q ′ be the ( M ′ -m )-link ( r -1)N path in G r -1 obtained from Q by replacing the first m +1 nodes v , 0 · · · , v m with the node r -1. Then,

$$c _ { s } \left ( Q \right ) = c _ { r - 1 } \left ( Q ^ { \prime } \right ) \geq c _ { r - 1 } \left ( P \right ). \\ \leq c _ { r - 1 } \left ( P \right ). \text{ Let } P ^ { \prime } \text{ be the concatenation}$$

Thus, the theorem follows.

Next, we show that c s ( Q ) ≤ c r -1 ( P ). Let P ′ be the concatenation of a shortest ( m +1)-link s u -1 path in G s and the subpath ( u , 1 · · · , u M ′ -m ) of P . By the definition of c r -1 , c r -1 ( P ) = c s ( P ′ ). As c s ( P ′ ) ≥ c s ( Q ), we have c r -1 ( P ) ≥ c s ( Q ).

In the sequel, we present a procedure Probe ( s, m ) on G s which

- · either hits and returns a member δ s ( m,n ) of Λ s ( M,N ) if there is any,
- · or finds r , contracts G s into G r -1 , and reduces M by m .

In the latter case, the new lengths of edges out of r -1 in G r -1 are stored in a global array h of size N .

By Theorem 4.1,

$$r = \min \left \{ n \in ( s + m \, \colon N - M + m ] \, \colon d _ { s } ^ { \min } \left ( \delta _ { s } \left ( m, n \right ), N \right ) \leq M \right \} \\ \text{nward monotonicity of } \delta _ { s } \left ( m, n \right ) \text{ and } d _ { s } ^ { \min } \left ( \delta _ { s } \left ( m, n \right ), N \right ) \text{ in } n \in ( s + m \, \colon N - M + m$$

The downward monotonicity of δ s ( m,n ) and d min s ( δ s ( m,n ,N ) ) in n ∈ ( s + m : N -M + m ] enables the discovery of r by a combination of exponential search and binary search . Throughout the search, an integer search interval ( n ′ : n ′′ ] containing r is maintained; initially, n ′ = s + m and n ′′ = N -M + m . A basic sampling operation is to generate a sample λ = δ s ( m,n ) for some candidate n in the search interval, compute M ′ = d min s ( λ, N ), and compare M ′ against M as follows:

- · If M ′ = M , then λ is returned.
- · If M &gt; M ′ , then n &lt; r hence n ′ is lifted to n .
- · If M &lt; M ′ , then n ≥ r hence n ′′ is reduced to n .

The procedure Probe ( s, m ) runs in three phases, exponential search, binary search, and contraction, which are elaborated below.

The exponential search is outlined in Table 2. It takes k := /ceilingleft log ( r -s -m +1) /ceilingright iterations to either hit a member λ ∈ Λ ( s M,N ) or reach

$$\cdot m \Big \}.$$

For each j ∈ [ k ], the j -th iteration selects the candidate

$$n ^ { \prime } & = ( s + m - 1 ) + 2 ^ { k - 1 }, \\ n ^ { \prime \prime } & = \min \left \{ ( s + m - 1 ) + 2 ^ { k }, N - M + m \right \}. \\ - t h \, \text{iteration selects the candidate}$$

$$n = \min \left \{ ( s + m - 1 ) + 2 ^ { j }, N - M + m \right \}, \\ \text{on } G _ { s } \text{ to compute } f \left ( i \right ) = f _ { s } \left ( m, i \right ) \text{ for } s + m \leq i \leq n \text{ a}$$

invokes PBF ( s, m, n ) on G s to compute f ( ) i = f s ( m,i ) for s + m ≤ i ≤ n and f ( ) i = f s ( m +1 , i ) for s + m + 1 ≤ i ≤ n , and completes the sampling operation on λ = δ s ( m,n ) = f ( n ) -f ( n ). If the sampling operation reduces n ′′ to n , then the binary search follows, inheriting f ( ) = i f s ( m,i ) for s + m ≤ i ≤ n ′′ and f ( ) = i f s ( m +1 , i ) for s + m +1 ≤ i ≤ n ′′ .

![Image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00227v1-figure-a9255c92-7a7e-434e-897d-1375c0396946.jpg)

←

Table 2: Outline of exponential search.

The binary search is outlined in Table 3. As long as n ′′ -n &gt; ′ 1, a binary-search iteration chooses the median n := /ceilingleft ( n ′ + n ′′ ) / 2 /ceilingright and completes the sampling operation on λ = δ s ( m,n ) = f ( n ) -f ( n ). When n ′′ -n ′ = 1, r = n ′′ and the membership of λ = δ s ( m,r ) = f ( r ) -f ( r ) in Λ s ( M,N ) is tested by comparing M ′′ = d max s ( λ, N ) against M . If M ′′ ≥ M then δ s ( m,r ) ∈ Λ ( s M,N ) and is thus returned. Otherwise,

$$\delta _ { s } \left ( m, r \right ) < \delta _ { s } \left ( M - 1, N \right ) \leq \delta _ { s } \left ( M, N \right ) < \delta _ { s } \left ( m, r - 1 \right ).$$

and the contraction phase follows.

Table 3: Outline of binary search.

![Image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00227v1-figure-c06619eb-2f1f-43d4-8ce2-612f65ed04f1.jpg)

The contraction phase is outlined in Table 4. It first computes

$$h \left ( j \right ) = \min _ { s + m \leq i < r } \left [ f \left ( i \right ) + c _ { s } \left ( i, j \right ) \right ]$$

for each j ∈ [ r : N ]. Since f ( ) + i c s ( i, j ) is submodular in ( i, j ) on the lattice [ s + m r : -1] × [ r : N ], h j ( ) for j ∈ [ r : N ] can be computed by the SWAWK algorithm. Subsequently, s is overwritten with r -1 and M is decreased by m .

![Image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00227v1-figure-d2cc80ad-73c7-4b94-ac70-049c2f227bd0.jpg)

| // contraction:                                                                               |
|-----------------------------------------------------------------------------------------------|
| for j = r to N do //SMAWK h ( j ) ← min s + m ≤ i<r [ f ( i ) + c s ( i, j )]; s r 1, M M m ; |

← -

←

-

Table 4: Outline of the contraction phase.

In the remaining of this section, we derive the time and space complexity of the procedure Probe ( s, m ).

Lemma 5.2 The procedure Probe ( s, m ) runs in

$$O \left ( m \left ( r - s - m + 1 \right ) + \left ( N - s + 1 \right ) \log \left ( r - s - m + 1 \right ) \right ).$$

time and O N ( ) space.

Proof. The worst-case running time occurs when the contraction phase is reached. The contraction phase has O N ( -s +1) running time. The total running time of the other two phases is dominated by the invocations of PBF ( s, m, n ) and the computations of d min s ( λ, N ) or d max s ( λ, N ). We show that the former's total running time is

$$O \left ( m \left ( r - s - m + 1 \right ) \right )$$

and the latter's total running time is

$$O \left ( \left ( N - s + 1 \right ) \log \left ( r - s - m + 1 \right ) \right ),$$

from which the lemma follows.

Let

$$k & = \left \lceil \log \left ( r - s - m + 1 \right ) \right \rceil. \\ \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot.$$

Then the exponential search takes k iterations. In the j -th iteration with j ∈ [ k ],

$$n = \min \left \{ ( s + m - 1 ) + 2 ^ { j }, N - M + m \right \} ; \\ \text{BF} ( s, m, n ) \text{ has running time}$$

hence the invocation PBF ( s, m, n ) has running time

Since

$$O \left ( m \left ( n - s + 1 - m \right ) \right ) = O \left ( m 2 ^ { j } \right ).$$

$$m \sum _ { j = 1 } ^ { k } 2 ^ { j } = 2 m \left ( 2 ^ { k } - 1 \right ) < 4 m \left ( r - s - m + 1 \right ), \\ \mathbb { R } \, \text{$\mathbb{E}$} \, ( \mathbb { e } \, m \, n ) \, \text{ in the environmental search is}$$

the invocations of PBF ( s, m, n ) in the exponential search is

$$O \left ( m \left ( r - s - m + 1 \right ) \right ).$$

The exponential search takes k computations of d min s ( λ, N ). At the beginning of the binary search,

$$n ^ { \prime }$$

$$n ^ { \prime } & = ( s + m - 1 ) + 2 ^ { k - 1 }, \\ n ^ { \prime \prime } & \leq ( s + m - 1 ) + 2 ^ { k }.$$

As n ′′ -n ′ ≤ 2 k -1 , the binary search takes at most k -1 iterations, hence has at most k -1 computations of d min s ( λ, N ) and one computation of d max s ( λ, N ). Thus, there at most 2 k computations of d min s ( λ, N ) or d max s ( λ, N ) in total, and each computation takes O N ( -s +1) time. So, the total time by the computations of d min s ( λ, N ) or d max s ( λ, N ) is

$$O \left ( ( N - s + 1 ) \log \left ( r - s - m + 1 \right ) \right ).$$

The linear space complexity of Probe ( s, m ) follows from that both PBF ( s, m, n ) and the computation of d min s ( λ, N ) or d max s ( λ, N ) require linear space.

## 6 The Contract-and-Conquer Algorithm

Suppose G 1 = G is a Monge DAG on [ N ] with edge-length function c 1 = , and 2 c ≤ M ≤ N -2. Denote Λ ∗ := Λ 1 ( M,N ). Computing a path in P ∗ 1 ( M,N ) is reducible in linear time and space to finding a member λ ∈ Λ . ∗ In this section, we present a contract-and-conquer (C&amp;C) algorithm for finding a member λ ∈ Λ ∗ in linear space and O ( √ NM N ( -M ) log ( N -M ) ) time.

If M N ( -M ) ≤ 4 N log ( N -M ), then the C&amp;C algorithm simply invokes PBF (1 , M, N ) on G 1 and returns λ = δ 1 ( M,N ) in linear space and

$$O \left ( M \left ( N - M \right ) \right ) = O \left ( \sqrt { N M \left ( N - M \right ) \log \left ( N - M \right ) } \right )$$

time. In the remaining of this section, we assume

$$M \left ( N - M \right ) > 4 N \log \left ( N - M \right ).$$

Then 16 &lt; M &lt; N -16. Indeed, N -M &gt; 16 follows from

$$\left ( N - M \right ) / \log \left ( N - M \right ) > 4 N / M > 4,$$

which further implies

Let

Then 2 &lt; K &lt; √ M as

$$\text{puses} M > 4 \frac { N } { N - M } \log \left ( N - M \right ) > 4 \log \left ( N - M \right ) > 1 6.$$

$$K \coloneqq \left \lceil \sqrt { \frac { M \left ( N - M \right ) } { N \log \left ( N - M \right ) } } \right \rceil.$$

$$\text{1 as} & 2 < K \leq \left [ \sqrt { \frac { M } { \log \left ( N - M \right ) } } \right ] \leq \left \lceil \sqrt { M } / 2 \right ] < \sqrt { M }. \\ \overline { M } \ > \ \text{$\mathcal{ }$} \quad \mathcal { D } \underset { \mathcal { M } \sim \mathcal { C } } \ \mathcal { N } ^ { \prime } \ = \ \mathcal { N } \ \mathcal { M } \underset { \mathcal { M } \sim \mathcal { C } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \text{d } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \mathcal { D } \ \vec { \ } \.$$

$$m _ { k } = \begin{cases} \ \lfloor M / K \rfloor \,, & \text{if $1\leq k\leq K^{\prime}$;} \\ \lceil M / K \rceil \,, & \text{if $K^{\prime}<k\leq K$.} \end{cases}$$

Hence K/M &gt; √ M &gt; 4. Denote K ′ := K -M mod K , and partition M evenly into K integers m ,m , 1 2 · · · , m K where

Then, m k ≥ 4 for each 1 ≤ k ≤ K .

The C&amp;C algorithm implicitly maintains a Monge DAG G s on [ s : N ] with edge length function c s for some s ≥ 1. Initially, s = 1. Each G s with s &gt; 1 is generated from G 1 by successive contractions and is explicitly represented by a global array h of size N such that h j ( ) = c s ( s, j ) for each j ∈ [ s +1 : N ]. The C&amp;C algorithm proceeds in at most K successive stages. At the beginning of the stage k ≤ K , the following invariant properties are maintained:

- · M = ∑ K i = k m i ≤ N -s -1; · Λ ( s M,N ) in G s is Λ . ∗

These properties hold trivially for the first stage k = 1 where s = 1. The stage k runs as follows depending on whether k = K or not.

Suppose k &lt; K . As

$$4 & \leq m _ { k } = M - \sum _ { i = k + 1 } ^ { K } m _ { i } \leq M - 4, \\ 4 & \leq M \leq N - s - 1, \\ \intertext { a n n e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e n e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m e m o n n }$$

the stage k invokes Probe ( s, m k ) on G s . If the invocation of Probe ( s, m k ) finds a member λ ∈ Λ ( s M,N ) = Λ , then the C&amp;C algorithm ∗ terminates with the output λ . Otherwise, the invocation of Probe ( s, m k ) contracts G s by updating s and h and reduces M by m k . After the contraction,

- · M = ∑ K i = +1 k m i ≤ N -s -1;
- · Λ ( s M,N ) in G s is Λ ∗ by Theorem 5.1.

The C&amp;C algorithm then moves on to the stage k +1.

Suppose k = K . Then the (last) stage K simply invokes PBF ( s, M, N ) on G s , computes λ = δ s ( M,N ), and terminates with the output λ .

The data structures needed by the C&amp;C algorithm are just a few global arrays indexed of size N . The array h is used for representing the graph G s . Two arrays f and f are used by the procedure PBF ( s, m, n ). The computation of d min s ( λ, N ) or d max s ( λ, N ) and the invocation of SMAWK algorithm require linear working space. We remark that there is no need to explicitly maintain the sequence m ,m , 1 2 · · · , m K . They can be easily derived from the stage number k and K ′ = K -M mod K . Thus, the C&amp;C algorithm has linear space complexity.

Next, we derive the time complexity of the C&amp;C algorithm.

$$\text{Theorem $6.1$ the $\mathcal{C}C$ algorithm has time complexity $O\left(\sqrt{N M \left(N - M \right) \log \left(N - M \right) } \right)$}.$$

Proof. Clearly, the worst-case running time occurs when the stage K is reached. For each 1 ≤ k ≤ k , let s k be the root s at the beginning of the stage k . Then, s 1 = 1; and for each k &lt; K , s k +1 +1 is exactly the pivot r in stage k . Thus, for each k &lt; K , s k +1 +1 ≥ s k + m k +1 implying that s k +1 ≥ s k + m k . At the beginning of the last stage K m , K ≤ N -s K -1; hence

$$s _ { K } + m _ { K } + 1 \leq N.$$

By Lemma 5.2, each stage k &lt; K has running time

$$& O \left ( m _ { k } \left ( s _ { k + 1 } - s _ { k } - m _ { k } + 2 \right ) \right ) + \\ & O \left ( \left ( N - s _ { k } + 1 \right ) \log \left ( s _ { k + 1 } - s _ { k } - m _ { k } + 2 \right ) \right ). \\.$$

The stage K has running time

$$O \left ( m _ { K } \left ( N - s _ { K } - m _ { K } + 1 \right ) \right ).$$

So, the total running time is

$$\dots \dots \circ \dots \dots \dots \\ O & \left ( \sum _ { k = 1 } ^ { K - 1 } m _ { k } \left ( s _ { k + 1 } - s _ { k } - m _ { k } + 2 \right ) + m _ { K } \left ( N - s _ { K } - m _ { K } + 1 \right ) \right ) \\ & + O \left ( \sum _ { k = 1 } ^ { K - 1 } \left ( N - s _ { k } + 1 \right ) \log \left ( s _ { k + 1 } - s _ { k } - m _ { k } + 2 \right ) \right ) \\ \text{the two sums in the big-O$ notations are bounded respectively by}$$

We show the two sums in the bigO notations are bounded respectively by

$$& \frac { M } { K } \left ( N - M \right ) + N + M, \\ & N \left ( K - 1 \right ) \log \left ( n - M \right ).$$

$$\ast$$

By the definition of m k for k ∈ [ K ], we have

$$\text{definition of } m _ { k } & \text{ for } k \in [ K ], \, \text{ we have} \\ & \sum _ { k = 1 } ^ { K - 1 } m _ { k } \left ( s _ { k + 1 } - s _ { k } - m _ { k } + 2 \right ) + m _ { K } \left ( N - s _ { K } - m _ { K } + 1 \right ) \\ & < \sum _ { k = 1 } ^ { K - 1 } m _ { k } \left ( s _ { k + 1 } - s _ { k } - m _ { k } \right ) + m _ { K } \left ( N - s _ { K } - m _ { K } \right ) + 2 M \\ & \leq \left \lceil \frac { M } { K } \right \rceil \sum _ { k = 1 } ^ { K - 1 } \left ( s _ { k + 1 } - s _ { k } - m _ { k } \right ) + \left \lceil \frac { M } { K } \right \rceil \left ( N - s _ { K } - m _ { K } \right ) + 2 M \\ & = \left \lceil \frac { M } { K } \right \rceil \left ( N - M - 1 \right ) + 2 M \\ & < \frac { M } { K } \left ( N - M \right ) + N + M. \\ \text{concavity of the logarithm function and the inequality in equation } \left ( 7 \right ), \, \text{ we have} \\ & \quad \kappa _ { - 1 }$$

By the concavity of the logarithm function and the inequality in equation (7), we have

$$\mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A A A B } _ { \ast } \quad \mathcal { A } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \ast } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \mathcal { A A B } _ { \nu } \quad \nu }$$

Finally, by the choice of K in equation (6), and

$$\frac { M } { K } \left ( N - M \right ) \leq \frac { M \left ( N - M \right ) } { \sqrt { \frac { M \left ( N - M \right ) } { N \log \left ( N - M \right ) } } } = \sqrt { N M \left ( N - M \right ) \log \left ( N - M \right ) }.$$

$$& N \left ( K - 1 \right ) \log \left ( n - M \right ) \leq N \sqrt { \frac { M \left ( N - M \right ) } { N \log \left ( N - M \right ) } } \log \left ( N - M \right ) \\ & = \sqrt { N M \left ( N - M \right ) \log \left ( N - M \right ) }. \\ \text{he theorem holds. } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{\ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text{ } \text$$

Therefore, the theorem holds.

The rationale for the choice of K , the number of stages, given by equation (6) is now clear from the above proof. This choice is to strike a balance between the invocations of PBF ( s, m, n ) and the computations of d min s ( λ, N ) or d max s ( λ, N ).

## 7 Conclusion

For the O poly ( (log N )) and N -O poly ( (log N )) regimes of M , the C&amp;C algorithm has running time O N ( · poly (log N )). It remains open whether there is O N ( · poly (log N ))-time algorithm in the regime of M where both M and N -M are at least Ω ( poly (log N )). It seems quite possible that with some additional cleverness our algorithm could be made to run faster. Note that the membership test of λ in Λ ∗ = Λ ( 1 M,N ) via d min s ( λ, N ) and d max s ( λ, N ) in G s ( λ ) can also be done via d min 1 ( λ, N ) and d max 1 ( λ, N ) in G 1 ( λ ), and the same asymptotic upper bound O ( √ NM N ( -M ) log ( N -M ) ) on the total running time is still valid. Each time we compute d min 1 ( λ, N ) or d max 1 ( λ, N ), we actually produce the parametric shortest-path tree T min 1 ( λ, N ) or T max 1 ( λ, N ). Our current algorithm utilizes only the value d min 1 ( λ, N ) or d max 1 ( λ, N ) and throws away all the information about the shortest-path tree. Possibly some information of the shortest-path trees could be reused to achieve an improved running time. All strongly polynomial algorithms seek a member of Λ ∗ from the finite candidate pool of δ s ( m,n ) for ( m,n ) ∈ L s . One may expand the finite candidate pool with extra candidates which can be generated easily and lead to faster progress. Ultimately, the disparate dependence on M of the running times of different algorithms suggests that a faster 'hybrid' algorithm may be composed in an adaptive manner.

## References

- [1] A. Aggarwal, M. Klawe, S. Moran, P. Shor, and R. Wilber, Geometric applications of a matrixsearching algorithm, Algorithmica 2: 195-208, 1987.
- [2] A. Aggarwal, B. Schieber, and T. Tokuyama, Finding a minimum weight K -link path in graphs with Monge property and applications, Discrete Comput. Geometry 12: 263-280, 1994.
- [3] W. Bein, L. Larmore, and J. Park, The d -edge shortest-path problem for a Monge graph, Preprint, 1992.
- [4] Z. Galil and K. Park, A linear-time algorithm for concave one-dimensional dynamic programming, Inform. Process. Lett. 33 (6): 309-311. 1990.
- [5] M. Klawe, A simple linear time algorithm for concave one-dimensional dynamic programming, Technical Report 89-16 , University of British Columbia, Vancouver, 1989.
- [6] L. Larmore and B. Schieber, On-line dynamic programming with applications to the prediction of RNA secondary structure, Journal of Algorithms 12 (3): 490-515, 1991.
- [7] N. Megiddo, Applying parallel computation algorithms in the design of serial algorithms, J. Assoc. Comput. Mach. 30: 852-865, 1983.
- [8] B. Schieber, Computing a minimum weight k -link path in graphs with the concave monge property, Journal of Algorithms 29: 204-222, 1998.
- [9] D. Topkis. Supermodularity and complementarity , Princeton University Press, 2011.
- [10] R. Wilber, The concave least weight subsequence problem revisited, Journal of Algorithms 9: 418425, 1988.
Joy Z. Wan
Finding a Shortest $M$-link Path in a Monge Directed Acyclic Graph
A Monge directed acyclic graph (DAG) $G$ on the nodes $1,2,\cdots,N$ has
edges $\left( i,j\right) $ for $1\leq i<j\leq N$ carrying submodular
edge-lengths. Finding a shortest $M$-link path from $1$ to $N$ in $G$ for any
given $1<M<N-1$ has many applications. In this paper, we give a
contract-and-conquer algorithm for this problem which runs in $O\left(
\sqrt{NM\left( N-M\right) \log\left( N-M\right) }\right) $ time and $O\left(
N\right) $ space. It is the first $o\left( NM\right) $-time algorithm with
linear space complexity, and its time complexity decreases with $M$ when $M\geq
N/2$. In contrast, all previous strongly polynomial algorithms have running
time growing with $M$. For both $O\left( poly\left( \log N\right) \right) $ and
$N-O\left( poly\left( \log N\right) \right) $ regimes of $M$, our algorithm has
running time $O\left( N\cdot poly\left( \log N\right) \right) $, which
partially answers an open question rased in \cite{AST94} affirmatively.