1 Introduction

In this paper we revisit an old key technique from what currently are the theoretically fastest parameterized algorithms for treewidth and pathwidth, namely the use of typical sequences, and give additional structural insights for this technique. In particular, we show a structural lemma, which we call the Merge Dominator Lemma. The technique of typical sequences brings with it a partial order on sequences of integers, and a notion of possible merges of two integer sequences; surprisingly, the Merge Dominator Lemma states that for any pair of integer sequences there exists a single merge that dominates all merges of these integer sequences, and this dominating merge can be found in linear time. On its own, this lemma does not lead to asymptotically faster parameterized algorithms for treewidth and pathwidth, but, as we discuss below, it is a concrete step towards such algorithms.

The notion of typical sequences was introduced independently in 1991 by Lagergren and Arnborg [17] and Bodlaender and Kloks [8]. In both papers, it is a key element in an explicit dynamic programming algorithm that given a tree decomposition of bounded width , decides if the pathwidth or treewidth of the input graph G is at most a constant k. Lagergren and Arnborg build upon this result and show that the set of forbidden minors of graphs of treewidth (or pathwidth) at most k is computable; Bodlaender and Kloks show that the algorithm can also construct a tree or path decomposition of width at most k, if existing, in the same asymptotic time bounds. The latter result is a main subroutine in Bodlaender’s linear time algorithm [3] for treewidth-k. If one analyses the running time of Bodlaender’s algorithm for treewidth or pathwidth ≤ k, then one can observe that the bottleneck is in the subroutine that calls the Bodlaender-Kloks dynamic programming subroutine, with both the subroutine and the main algorithm having time \(\mathcal {O}(2^{\mathcal {O}(k^{3})}n)\) for treewidth, and \(\mathcal {O}(2^{\mathcal {O}(k^{2})}n)\) for pathwidth. See also the recent work by Fürer for pathwidth [13], and the simplified versions of the algorithms of [3, 8] by Althaus and Ziegler [1]. Now, over a quarter of a century after the discovery of these results, even though much work has been done on treewidth recognition algorithms (see e.g. [2, 5, 11,12,13, 16, 18, 19]), these bounds on the function of k are still the best known, i.e., no \(\mathcal {O}(2^{o(k^{3})}n^{O(1)})\) algorithm for treewidth, and no \(\mathcal {O}(2^{o(k^{2})}n^{O(1)})\) algorithm for pathwidth is known. An interesting question, and a long-standing open problem in the field [4, Problem 2.7.1], is whether such algorithms can be obtained. Possible approaches to answer such a question is to design (e.g. ETH or SETH based) lower bounds, find an entirely new approach to compute treewidth or pathwidth in a parameterized setting, or improve upon the dynamic programming algorithms of [17] and [8]. Using our Merge Dominator Lemma we can go one step towards the latter, as follows.

The algorithms of Lagergren and Arnborg [17] and Bodlaender and Kloks [8] are based upon tabulating characteristics of tree or path decompositions of subgraphs of the input graph; a characteristic consists of an intersection model, that tells how the vertices in the current top bag interact, and for each part of the intersection model, a typical sequence of bag sizes.Footnote 1 The set of characteristics for a join node is computed from the sets of characteristics of its (two) children. In particular, each pair of characteristics with one from each child can give rise to exponentially (in k) many characteristics for the join node. This is because exponentially many typical sequences may arise as the merges of the typical sequences that are part of the characteristics. In the light of our Merge Dominator Lemma, only one of these merges has to be stored, reducing the number of characteristics arising from each pair of characteristics of the children from \(2^{\mathcal {O}(k)}\) to just 1. Moreover, this dominating merge can be found using \(\mathcal {O}(k)\) integer operations (which translates to time linear in the size of the sequence) with no large hidden constants.

Merging typical sequences at a join node is however not the only way the number of characteristics can increase throughout the algorithm, e.g. at introduce nodes, the number of characteristics increases in a different way. Nevertheless, the number of intersection models is \(\mathcal {O}(k^{\mathcal {O}(k)})\) for pathwidth and \(\mathcal {O}(k^{\mathcal {O}(k^{2})})\) for treewidth; perhaps, with additional techniques, the number of typical sequences per part can be better bounded — in the case that a single dominating typical sequence per part suffices, this would reduce the number of table entries per node to \(\mathcal {O}(k^{\mathcal {O}(k)})\) for pathwidth-k, and to \(\mathcal {O}(k^{\mathcal {O}(k^{2})})\) for treewidth-k, and yield \(\mathcal {O}(k^{\mathcal {O}(k)} n)\) and \(\mathcal {O}(k^{\mathcal {O}(k^{2})} n)\) time algorithms for the respective problems. Concretely, suppose one could prove an analogue to the Merge Dominator Lemma for introduce nodes, stating that given a characteristic stored at their child, there is a single characteristic that dominates all the others that could potentially arise. Then the above mentioned bound of a single dominating typical sequence per part in the intersection model would follow and therefore, so would the improved algorithms for computing treewidth and pathwidth.

We give direct algorithmic consequences of the Merge Dominator Lemma in the realm of computing width parameters of directed acyclic graphs (DAGs). Specifically, we show that the (Weighted) Cutwidth and Modified Cutwidth problems on DAGs, which given a directed acyclic graph ask for the topological order that minimizes the cutwidth and modified cutwidth, respectively,Footnote 2 can be solved in polynomial time on series parallel digraphs. Note that the restriction of the solution to be a topological order has been made as well in other works, e.g. [6].

Our algorithm for Cutwidth of series parallel digraphs has the same structure as the dynamic programming algorithm for undirected Cutwidth [6], but, in addition to obeying directions of edges, we have a step that only keeps characteristics that are not dominated by another characteristic in a table of characteristics. Now, with help of our Merge Dominator Lemma, we can show that in the case of series parallel digraphs, there is a unique dominating characteristic; the dynamic programming algorithm reverts to computing for each intermediate graph a single ‘optimal partial solution’. This strategy also works in the presence of edge weights, which gives the algorithm for the corresponding Weighted Cutwidth problem on series parallel digraphs. Note that the cutwidth of a directed acyclic graph is at least the maximum indegree or outdegree of a vertex; e.g., a series parallel digraph formed by the parallel composition of n − 2 paths with three vertices has n vertices and cutwidth n − 2. To compute the modified cutwidth of a series parallel digraph, we give a linear time reduction to the Weighted Cutwidth problem on series parallel digraphs.

This paper is organized as follows. In Section 2, we give a number of preliminary definitions, and review existing results, including several results on typical sequences from [8]. In Section 3, we state and prove the main technical result of this work, the Merge Dominator Lemma. Section 4 gives our algorithmic applications of this lemma, and shows that the directed cutwidth and directed modified cutwidth of a series parallel digraph can be computed in polynomial time. Some final remarks are made in Section 5.

2 Preliminaries

We use the following notation. For two integers \(a, b \in \mathbb {Z}\) with ab, we let [a..b] := {a, a + 1,…, b} and for a > 0, we let [a] := [1..a]. If X is a set of size n, then a linear order is a bijection π: X → [n]. Given a subset \(X^{\prime } \subseteq X\) of size \(n^{\prime } \le n\), we define the restriction of π to \(X^{\prime }\) as the bijection \(\pi |_{X^{\prime }} \colon X^{\prime } \to [n^{\prime }]\) which is such that for all \(x^{\prime }, y^{\prime } \in X^{\prime }\), \(\pi |_{X^{\prime }}(x^{\prime }) < \pi |_{X^{\prime }}(y^{\prime })\) if and only if \(\pi (x^{\prime }) < \pi (y^{\prime })\).

Integer Operations In this work, the runtime of several algorithms is stated in terms of the number of required integer operations. Here, by integer operations we mean basic manipulations such as adding two integers, or comparing two integers. For integers whose absolute value is at most some \(n \in \mathbb {N}\), such operations can be performed in \(\mathcal {O}(\log n)\) time. Moreover, whenever we give the runtime of an algorithm in terms of the number of integer operations, then the time it takes to execute the algorithm is also upper bounded in terms of the time it takes to execute these integer operations. For instance, an algorithm that ‘uses \(\mathcal {O}(f(n))\) integer operations’ where the value of each integer in the instance is upper bounded by m runs in \(\mathcal {O}(f(n)\log m)\) time.

Sequences and Matrices We denote the elements of a sequence s by s(1),…, s(n). We denote the length of s by l(s), i.e., l(s) := n. For two sequences a = a(1),…, a(m) and b = b(1),…, b(n), we denote their concatenation by ab = a(1),…, a(m), b(1),…, b(n). For two sets of sequences A and B, we let AB := {abaAbB}. For a sequence s of length n and a set \(X \subseteq [n]\), we denote by s[X] the subsequence of s induced by X, i.e., let X = {x1,…, xm} be such that for all i ∈ [m − 1], xi < xi+ 1; then, s[X] := s(x1),…, s(xm). For x1, x2 ∈ [n] with x1x2, we use the shorthand ‘s[x1..x2]’ for ‘s[[x1..x2]]’.

An (integer) matrix \(M \in \mathbb {Z}^{m \times n}\) is said to have m rows and n columns.Footnote 3 For sets \(X \subseteq [m]\) and \(Y \subseteq [n]\), we denote by M[X, Y ] the submatrix of M induced by X and Y, which consists of all the entries from M whose indices are in X × Y. For x1, x2 ∈ [m] with x1x2 and y1, y2 ∈ [n] with y1y2, we use the shorthand ‘M[x1..x2, y1..y2]’ for ‘M[[x1..x2],[y1..y2]]’. For a sequence s(1), s(2),…, s() of indices of a matrix M, we let

$$ \begin{array}{@{}rcl@{}} M[s] := M[s(1)], M[s(2)], \ldots, M[s(\ell)] \end{array} $$
(1)

be the corresponding sequence of entries from M.

For illustrative purposes we enumerate the columns of a matrix in a bottom-up fashion throughout this paper, i.e., we consider the index (1,1) as the ‘bottom left corner’ and the index (m, n) as the ‘top right corner’.

Integer Sequences Let s be an integer sequence of length n. We use the shorthand ‘\(\min \limits (s)\)’ for ‘\(\min \limits _{i \in [n]} s(i)\)’ and ‘\(\max \limits (s)\)’ for ‘\(\max \limits _{i \in [n]} s(i)\)’; we use the following definitions. We let

$$ \arg\!\min(s) := \{i \in [n] \mid s(i) = \min(s)\} \text{ and } \arg\!\max(s) := \{i \in [n] \mid s(i) = \max(s)\} $$

be the set of indices at whose positions there are the minimum and maximum element of s, respectively. Whenever we write \(i \in \arg \!\min \limits (s)\) (\(j \in \arg \!\max \limits (s)\)), then the choice of i (j) can be arbitrary. In some places we require a canonical choice of the position of a minimum or maximum element, in which case we will always choose the smallest index. Formally, we let

$$ \arg\!{\min}^{\ast}(s) := \min \arg\!\min(s), \text{ and } \arg\!{\max}^{\ast}(s) := \min \arg\!\max(s). $$

The following definition contains two notions on pairs of integer sequences that are necessary for the definitions of domination and merges.

Definition 2.1

Let r and s be two integer sequences of the same length n.

  1. (i)

    If for all i ∈ [n], r(i) ≤ s(i), then we write ‘rs’.

  2. (ii)

    We write q = r + s for the integer sequence q(1),…, q(n) with q(i) = r(i) + s(i) for all i ∈ [n].

Definition 2.2 (Extensions)

Let s be a sequence of length n. We define the set E(s) of extensions of s as the set of sequences that are obtained from s by repeating each of its elements an arbitrary number of times, and at least once. Formally, we let

$$ E(s) := \{s_{1} \circ s_{2} \circ {\cdots} \circ s_{n} \mid \forall i \in [n] \colon l(s_{i}) \ge 1 \wedge \forall j \in [l(s_{i})] \colon s_{i}(j) = s(i)\}. $$

Definition 2.3 (Domination)

Let r and s be integer sequences. We say that r dominates s, in symbols ‘rs’, if there are extensions rE(r) and sE(s) of the same length such that rs. If rs and sr, then we say that r and s are equivalent, and we write rs.

If r is an integer sequence and S is a set of integer sequences, then we say that r dominates S, in symbols ‘rS’, if for all sS, rs.

Remark 2.4 (Transitivity of ‘≺’)

In [8, Lemma 3.7], it is shown that the relation ‘≺’ is transitive. As this is fairly intuitive, we may use this fact without stating it explicitly throughout this text.

A merge of two integer sequences r and s is the sum of an extension of r and an extension of s of the same length.

Definition 2.5 (Merges)

Let r and s be two integer sequences. We define the set of all merges of r and s, denoted by rs, as rs := {r + srE(r), sE(s), l(r) = l(s)}.

2.1 Typical Sequences

We now define typical sequences, show how to construct them using linearly many integer operations, and restate several lemmas due to Bodlaender and Kloks [8] that will be used throughout this text.

Definition 2.6

Let s = s(1),…, s(n) be an integer sequence of length n. The typical sequence of s, denoted by τ(s), is obtained from s by an exhaustive application of the following two operations:

Removal of Consecutive Repetitions If there is an index i ∈ [n − 1] such that s(i) = s(i + 1), then we change the sequence s from s(1),…, s(i), s(i + 1),…, s(n) to s(1),…, s(i), s(i + 2),…, s(n).

Typical Operation If there exist i, j ∈ [n] such that ji ≥ 2 and for all ikj, s(i) ≤ s(k) ≤ s(j), or for all ikj, s(i) ≥ s(k) ≥ s(j), then we change the sequence s from s(1),…, s(i), s(i + 1),…, s(j),…, s(n) to s(1),…, s(i), s(j),…, s(n), i.e., we remove all elements (strictly) between index i and j.

To support intuition, we illustrate the rough shape of a typical sequence in Fig. 1. It is not difficult to see that the typical sequence can be computed using a quadratic amount of integer operations, by an exhaustive application of the definition. Here we discuss how to do it using a linear amount of integer operations. We may view a typical sequence τ(s) of an integer sequence s as a subsequence of s. While τ(s) is unique, the choice of indices that induce τ(s) may not be unique. We show that we can find a set of indices that induce the typical sequence with help of the following structural proposition.

Fig. 1
figure 1

Illustration of the shape of a typical sequence

Proposition 2.7

Let s be an integer sequence and let \(i^{\star } \in \{\arg \!{\min \limits }^{*}(s), \arg \!{\max \limits }^{*}(s)\}\). Let 1 =: j0 < j1 < j2 < … < jt < jt+ 1 := i be pairwise distinct integers, such that s(j0),…, s(jt+ 1) are pairwise distinct. If for all h ∈ [0..t],

  • if s(jh) > s(jh+ 1) then \(j_{h} = \arg \!{\max \limits }^{*}(s[1..j_{h+1}])\) and \(j_{h+1} = \arg \!{\min \limits }^{*}(s[1..j_{h+1}])\), and

  • if s(jh) < s(jh+ 1) then \(j_{h} = \arg \!{\min \limits }^{*}(s[1..j_{h+1}])\) and \(j_{h+1} = \arg \!{\max \limits }^{*}(s[1..j_{h+1}])\),

then the typical sequence of s restricted to [i] is equal to s(j0), s(j1),…, s(jt), s(jt+ 1).

Proof

First, we observe that by the choice made in the definition of \(\arg \!\min \limits ^{*}\) and \(\arg \!\max \limits ^{*}\),

$$ \begin{array}{@{}rcl@{}} \text{for each $h \in [0..(t+1)]$ there is no $i < j_{h}$ such that } s(i) = s(j_{h}). \end{array} $$
(2)

We prove the following statement. Under the stated conditions, for a given h ∈ [0..t + 1], the typical sequence of s restricted to [jh..i] is equal to s(jh), s(jh+ 1), …, s(jt+ 1). The proposition then follows from the case h = 0. The proof is by induction on d := (t + 1) − h. For d = 0, it trivially holds since the minimum and the maximum element are always part of the typical sequence, and since [jt+ 1..i] = {i}.

Now suppose d > 0, and for the induction hypothesis that the claim holds for d − 1. Suppose that s(jh) > s(jh+ 1), meaning that \(j_{h} = \arg \!\max \limits ^{*}(s[1..j_{h+1}])\), and \(j_{h+1} = \arg \!{\min \limits }^{*}(s[1..j_{h+1}])\), the other case is symmetric. By the induction hypothesis, the typical sequence of s restricted to [jh+ 1..i] is equal to s(jh+ 1), …, s(jt+ 1), in particular it implies that s(jh+ 1) is an element of the typical sequence. To prove the induction step, we have to show that the typical sequence of s restricted to [jh..jh+ 1] is equal to s(jh), s(jh+ 1). We first argue that if there is an element of the typical sequence in [jh..(jh+ 1 − 1)], then it must be equal to s(jh). By (2), we have that there is no i < jh+ 1 such that s(i) = s(jh+ 1), and together with the fact that s(jh+ 1) is the minimum value of s[1..jh+ 1], we conclude that [jh..(jh+ 1 − 1)] cannot contain any element of the typical sequence that is equal to s(jh+ 1). Next, since the typical operation removes all elements i ∈ [(jh + 1)..(jh+ 1 − 1)] with s(jh) > s(i) > s(jh+ 1), and since \(j_{h} = \arg \!{\max \limits }^{*}(s[1..j_{h+1}])\), the only elements from [jh..(jh+ 1 − 1)] that the typical sequence may contain have value s(jh).

It remains to argue that s(jh) is indeed an element of the typical sequence. Suppose not, then there are indices \(i, i^{\prime }\) with \(i < j_{h} < i^{\prime }\), such that either \(s(i) \le s(j_{h}) \le s(i^{\prime })\), or \(s(i) \ge s(j_{h}) \ge s(i^{\prime })\), and we may assume that at least one of the inequalities is strict in each case. For the latter case, since \(j_{h} = \arg \!{\max \limits }^{*}(s[1..j_{h+1}])\), we would have that s(i) = s(jh), which is a contradiction to (2). Hence, we may assume that \(s(i) \le s(j_{h}) \le s(i^{\prime })\). There are two cases to consider: \(i^{\prime } \in [(j_{h}+1)..j_{h+1}]\), and \(i^{\prime } > j_{h+1}\). If \(i^{\prime } \in [(j_{h}+1)..j_{h+1}]\), then \(s(i^{\prime }) = s(j_{h})\), as \(s(j_{h}) = \arg \!\max \limits (s[1..j_{h+1}])\). We can conclude that in this case, the typical sequence must contain an element equal to \(s(i^{\prime })\), and hence equal to s(jh). If \(i^{\prime } > j_{h+1}\), then the typical operation corresponding to i and \(i^{\prime }\) also removes s(jh+ 1), a contradiction with the induction hypothesis which asserts that s(jh+ 1) is part of the typical sequence induced by [jh+ 1..i]. We can conclude that s(jh) is part of the typical sequence, finishing the proof. □

From the previous proposition, we have the following consequence about the structure of typical sequences ending in the minimum element, which will be useful in the proof of Lemma 3.10.

Corollary 2.8

Let t be a typical sequence of length n such that \(n \in \arg \!\min \limits (t)\). Then, for each \(k \in \left [\lfloor \frac {n}{2} \rfloor \right ]\), \(n - 2k + 1 \in \arg \!\max \limits (t[1..(n - 2k + 1)])\) and \(n - 2k \in \arg \!\min \limits (t[1..(n - 2k)])\).

Equipped with Proposition 2.7, we can now proceed and give the algorithm that computes a typical sequence of an integer sequence using linearly many integer operations.

Lemma 2.9

Let s be an integer sequence of length n. Then, one can compute τ(s), the typical sequence of s, in \(\mathcal {O}(n)\) integer operations.

Proof

First, we check for each i ∈ [n − 1] whether s(i) = s(i + 1), and if we find such an index i, we remove s(i). We assume from now on that after these modifications, s has at least two elements, otherwise it is trivial. As observed above, the typical sequence of s contains \(\min \limits (s)\) and \(\max \limits (s)\). A closer look reveals the following observation.

Observation 2.9.1Let \(i^{\star } := {\min \limits } \arg \!\min \limits (s) \cup \arg \!\max \limits (s)\) and \(k^{\star } := {\max \limits } \arg \!\min \limits (s) \cup \arg \!\max \limits (s)\).

  1. (i)

    If \(i^{\star } \in \arg \!\min \limits (s)\) and \(k^{\star } \in \arg \!\max \limits (s)\) or \(i^{\star } \in \arg \!\max \limits (s)\) and \(k^{\star } \in \arg \!\min \limits (s)\), then τ(s) restricted to [i..k] is equal to s(i), s(k).

  2. (ii)

    If \(\{i^{\star }, k^{\star }\} \subseteq \arg \!\min \limits (s)\), then τ(s) restricted to [i..k] is equal to \(s(i^{\star }), \max \limits (s), s(k^{\star })\).

  3. (iii)

    If \(\{i^{\star }, k^{\star }\} \subseteq \arg \!\max \limits (s)\), then τ(s) restricted to [i..k] is equal to \(s(i^{\star }), \min \limits (s), s(k^{\star })\).

Let \(i^{\star } := {\min \limits } \arg \!\min \limits (s) \cup \arg \!\max \limits (s)\) and \(k^{\star } := {\max \limits } \arg \!\min \limits (s) \cup \arg \!\max \limits (s)\). Using Observation 2.9.1, it remains to determine the indices that induce the typical sequence on s[1..i] and on s[k..n]. To find the indices that induce the typical sequence on s[1..i], we will describe a marking procedure that marks a set of indices satisfying the preconditions of Proposition 2.7. Next, we observe that nk is the smallest index of any occurrence of \(\min \limits (s)\) or \(\max \limits (s)\) in the reverse sequence of s, therefore a symmetric procedure, again using Proposition 2.7, yields the indices that induce τ(s) on s[k..n].

figure a

We execute Algorithm 1, which processes the integer sequence s[1..i] from the first to the last element, storing two counters \(j_{\min \limits }\) and \(j_{\max \limits }\) that store the leftmost position of the smallest and of the greatest element seen so far, respectively. Whenever a new minimum is encountered, we mark the current value of the index \(j_{\max \limits }\), as this implies that \(s(j_{\max \limits })\) has to be an element of the typical sequence. Similarly, when encountering a new maximum, we mark \(j_{\min \limits }\). These marked indices are stored in a set M, which at the end of the algorithm contains the indices that induce τ(s) on [1..i]. This, i.e., the correctness of the procedure, will now be argued via Proposition 2.7.

Claim 2.9.2 The set M of indices marked by the above procedure induceτ(s) on[1..i].

Proof Let M = {j0, j1,…, jt+ 1} be such that for all h ∈ [0..t], jh < jh+ 1. We prove that j0,…, jt+ 1 meet the preconditions of Proposition 2.7. First, we observe that the above algorithm marks both the index 1 and index i, in particular that j0 = 1 and jt+ 1 = i.

We verify that the indices j0,…, jt+ 1 satisfy the property that for each h ∈ [0..(t + 1)], the index jh is the leftmost (i.e., smallest) index whose value is equal to s(jh): whenever an index is added to the marked set, it is because in some iteration, the element at its position was either strictly greater than the greatest previously seen element, or strictly smaller than the smallest previously seen element. (This also ensures that s(j0),…, s(jt+ 1) are pairwise distinct.)

We additionally observe that if we have two indices 1 and 2 such that 2 is the index that the algorithm marked right after it marked 1, then either 1 was \(j_{\min \limits }\) and 2 was \(j_{\max \limits }\) or vice versa: when updating \(j_{\min \limits }\), we mark \(j_{\max \limits }\), and when updating \(j_{\max \limits }\), we mark \(j_{\min \limits }\). This lets us conclude that when we have two indices jh, jh+ 1 such that s(jh) < s(jh+ 1), then jh was equal to \(j_{\min \limits }\) when it was marked, and jh+ 1 was \(j_{\max \limits }\) when it was marked.

We are ready to prove that j0,…, jt+ 1 satisfy the precondition of Proposition 2.7. Suppose for a contradiction that for some h ∈ [0..t + 1], jh violates this property. Assume that s(jh) < s(jh+ 1) and note that the other case is symmetric. The previous paragraph lets us conclude that jh was equal to \(j_{\min \limits }\) when it was marked, and that jh+ 1 was \(j_{\max \limits }\) when it was marked.

We either have that \(j_{h} \neq \arg \!\min \limits ^{*}(s[1..j_{h+1}])\) or that \(j_{h+1} \neq \arg \!\max \limits ^{*}(s[1..j_{h+1}])\). Suppose the latter holds. This immediately implies that there is some j∈ [jh+ 1 − 1] such that s(j) > s(jh+ 1), which implies that \(j_{\max \limits }\) would never have been set to jh+ 1 and hence jh+ 1 would have never been marked. Suppose the former holds, i.e., \(j_{h} \neq \arg \!\min \limits ^{*}(s[1..j_{h+1}])\), for an illustration of the following argument see Fig. 2. Let \(j^{*} := \arg \!\min \limits ^{*}(s[1..j_{h+1}])\). If j < jh, then at iteration jh, \(s(j_{\min \limits }) \le s(j_{h})\), so \(j_{\min \limits }\) would never have been set to jh, and hence, jh would never have been marked. We may assume that j > jh. Since jh was marked, there is some > jh that triggered jh being marked. This also means that at that iteration s() was greater than the previously observed maximum, so we may assume that s() > s(jh). We also may assume that jh+ 1. If j∈ [(jh + 1)..( − 1)], then the algorithm would have updated \(j_{\min \limits }\) to j in that iteration, before marking jh, and for the case j∈ [( + 1)..(jh+ 1 − 1)] we observe that jh+ 1, and that the algorithm would mark as the next index instead of jh+ 1.

Fig. 2
figure 2

Illustration of the final argument in the proof of Claim 2.9.2. We assume that s(jh) < s(jh+ 1), and mark the possible positions for \(j^{*} = \arg \!\min \limits ^{*}(s[1..j_{h+1}])\) with jjh

This establishes the correctness of the algorithm. We observe that each iteration takes \(\mathcal {O}(1)\) comparisons of numbers in s, and that there are \(\mathcal {O}(n)\) iterations.

We summarize several lemmas from [8] regarding integer sequences and typical sequences that we will use in this work.□

Lemma 2.10 (Bodlaender and Kloks 8)

Let r and s be two integer sequences.

  1. (i)

    (Cor. 3.11 in [8]). We have that rs if and only if τ(r) ≺ τ(s).

  2. (ii)

    (Lem. 3.13 in [8]). Suppose r and s are of the same length and let y = r + s. Let r0r and s0s. Then there is an integer sequence y0r0s0 such that y0y.

  3. (iii)

    (Lem. 3.14 in [8]). Let qrs. Then, there is an integer sequence \(q^{\prime } \in \tau (r) \oplus \tau (s)\) such that \(q^{\prime } \prec q\).

  4. (iv)

    (Lem. 3.15 in [8]). Let qrs. Then, there is an integer sequence \(q^{\prime } \in r \oplus s\) with \(\tau (q^{\prime }) = \tau (q)\) and \(l(q^{\prime }) \le l(r) + l(s) -1\).

  5. (v)

    (Lem. 3.19 in [8]). Let \(r^{\prime }\) and \(s^{\prime }\) be two more integer sequences. If \(r^{\prime } \prec r\) and \(s^{\prime } \prec s\), then \(r^{\prime } \circ s^{\prime } \prec r \circ s\).

2.2 Directed Acyclic Graphs

A directed graph (or digraph) G is a pair of a set of verticesV (G) and a set of ordered pairs of vertices, called arcs, \(A(G) \subseteq V(G) \times V(G)\). (If A(G) is a multiset, we call G multidigraph.) We say that an arc a = (u, v) ∈ A(G) is directed from u to v, and we call u the tail of a and v the head of a. A sequence of vertices v1,…, vr is called a walk in G if for all i ∈ [r − 1], (vi, vi+ 1) ∈ A(G). A cycle is a walk v1,…, vr with v1 = vr and all vertices v1,…, vr− 1 pairwise distinct. If G does not contain any cycles, then we call G acyclic or a directed acyclic graph, DAG for short.

Let G be a DAG on n vertices. A topological order of G is a linear order π: V (G) → [n] such that for all arcs (u, v) ∈ A(G), π(u) < π(v). We denote the set of all topological orders of G by π(G). We now define the width measures studied in this work. Note that we restrict the orders of the vertices that we consider to topological orders.

Definition 2.11

Let G be a directed acyclic graph and let π ∈π(G) be a topological order of G.

  1. (i)

    The cutwidth of π is \(\textsf {cutw}(\pi ) \!:=\! \max \limits _{i \in [n - 1]} |{\{(u, v) \!\in \! A(G) \mid \pi (u) \!\!\le \! i \!\wedge \! \pi (v) \!>\! i\}}\).

  2. (ii)

    The modified cutwidth of π is \(\textsf {mcutw}(\pi ) := \max \limits _{i \in [n]} |\{(u, v) \in A(G) \mid \) π(u) < iπ(v) > i}.

We define the cutwidth and modified cutwidth of a directed acyclic graph G as the minimum of the respective measure over all topological orders of G.

We now introduce series parallel digraphs. Note that the following definition coincides with the notion of ‘edge series-parallel multidigraphs’ in [25]. For an illustration see Fig. 3.

Fig. 3
figure 3

A series parallel digraph G on the left, and a decomposition tree that yields G on the right

Definition 2.12 (Series Parallel Digraph (SPD))

A (multi-)digraph G with an ordered pair of distinct terminals(s, t) ∈ V (G) × V (G) is called series parallel digraph (SPD), often denoted by (G,(s, t)), if one of the following hold.

  1. (i)

    (G,(s, t)) is a single arc directed from s to t, i.e., V (G) = {s, t}, A(G) = {(s, t)}.

  2. (ii)

    (G,(s, t)) can be obtained from two series parallel digraphs (G1,(s1, t1)) and (G2,(s2, t2)) by one of the following operations.

    1. (a)

      Series Composition. (G,(s, t)) is obtained by taking the disjoint union of G1 and G2, identifying t1 and s2, and letting s = s1 and t = t2. In this case we write (G,(s, t)) = (G1,(s1, t1)) ∙ (G2,(s2, t2)) or simply G = G1G2.

    2. (b)

      Parallel Composition. (G,(s, t)) is obtained by taking the disjoint union of G1 and G2, identifying s1 and s2, and identifying t1 and t2, and letting s = s1 = s2 and t = t1 = t2. In this case we write (G,(s, t)) = (G1,(s1, t1))//(G2,(s2, t2)), or simply G = G1//G2.

It is not difficult to see that each series parallel digraph is acyclic. One can naturally associate a notion of decomposition trees with series parallel digraphs as follows. A decomposition tree T is a rooted and ordered binary tree whose leaves are labeled with a single arc, and each internal node tV (T) with left child and right child r is either a series node or a parallel node. We then associate an SPD Gt with each node tV (T). If t is a leaf, then Gt is a single arc oriented from one terminal to the other. If t is an internal node, then Gt is GGr if t is a series node and G//Gr if t is a parallel node. It is clear that for each SPD G, there is a decomposition tree T with root \(\mathfrak {r}\) such that \(G = G_{\mathfrak {r}}\). In that case we say that T yields G. Valdes et al. [25] have shown that one can decide in linear time whether a directed graph G is an SPD and if so, find a decomposition tree that yields G.

Theorem 2.13 (Valdes et al. 25)

Let G be a directed graph on n vertices and m arcs. There is an algorithm that decides in time \(\mathcal {O}(n + m)\) whether G is a series parallel digraph and if so, it outputs a decomposition tree that yields G.

3 The Merge Dominator Lemma

In this section we prove the main technical result of this work. It states that given two integer sequences, one can find a merge that dominates all merges of those two sequences using linearly many integer operations.

Lemma 3.1 (Merge Dominator Lemma)

Let r and c be integer sequence of length m and n, respectively. There exists a dominating merge of r and c, i.e., an integer sequence trc such that trc, and this dominating merge can be computed using \(\mathcal {O}(m + n)\) integer operations.

Outline of the Proof of the Merge Dominator Lemma First, we show that we can restrict our search to finding a dominating path in a matrix that, roughly speaking, contains all merges of r and c of length at most l(r) + l(c) − 1. The goal of this step is mainly to increase the intuitive insight to the proofs in this section. Next, we prove the ‘Split Lemma’ (Lemma 3.7 in Section 3.2) which asserts that we can obtain a dominating path in our matrix M by splitting M into a submatrix M1 that lies in the ‘bottom left’ of M and another submatrix M2 in the ‘top right’ of M along a minimum row and a minimum column, and appending a dominating path in M2 to a dominating path in M1. In M1, the last row and column are a minimum row and column, respectively, and in M2, the first row and column are a minimum row and column, respectively. This additional structure will be exploited in Section 3.3 where we prove the ‘Chop Lemmas’ that come in two versions. The ‘bottom version’ (Lemma 3.10) shows that in M1, we can find a dominating path by repeatedly chopping away the last two rows or columns and remembering a vertical or horizontal length-2 path. The ‘top version’ (Corollary 3.12) is the symmetric counterpart for M2. The proofs of the Chop Lemmas only hold when r and c are typical sequences, and in Section 3.4 we present the ‘Split-and-Chop Algorithm’ that computes a dominating path in a merge matrix of two typical sequences. Finally, in Section 3.5, we generalize this result to arbitrary integer sequences, using the Split-and-Chop Algorithm and one additional construction.

3.1 The Merge Matrix, Paths, and Non-Diagonality

Let us begin by defining the basic notions of a merge matrix and paths in matrices.

Definition 3.2 (Merge Matrix)

Let r and c be two integer sequences of length m and n, respectively. Then, the merge matrix of r and c is an m × n integer matrix M such that for (i, j) ∈ [m] × [n], M[i, j] = r(i) + c(j).

We would like to point out that the following definition of a path in a matrix can be viewed as a special case of the notion of lattice paths, see [22], or [14] for a related application.

Definition 3.3 (Path in a Matrix)

Let M be an m × n matrix. A path in M is a sequence p(1),…, p() of indices from M such that

  1. (i)

    p(1) = (1,1) and p() = (m, n), and

  2. (ii)

    for h ∈ [ − 1], let p(h) = (i, j); then, p(h + 1) ∈{(i + 1, j),(i, j + 1),(i + 1, j + 1)}.

We denote by \(\mathcal {P}(M)\) the set of all paths in M. A sequence p(1),…, p() that satisfies the second condition but not necessarily the first is called a partial path in M. For two paths \(p, q \in \mathcal {P}(M)\), we may simply say that p dominates q, if M[p] dominates M[q].Footnote 4 We also write \(p \prec \mathcal {P}(M)\) to express that for each path \(q \in \mathcal {P}(M)\), pq.

A (partial) path is called non-diagonal if the second condition is replaced by the following.

  1. (ii)’

    For h ∈ [ − 1], let p(h) = (i, j); then, p(h + 1) ∈{(i + 1, j),(i, j + 1)}.

An extension e of a path p in a matrix M is as well a sequence of indices of M, and we again denote the corresponding integer sequence by M[e]. A consequence of Lemma 2.10(i) and (iv) is that we can restrict ourselves to all paths in a merge matrix when trying to find a dominating merge of two integer sequences: it is clear from the definitions that in a merge matrix M of integer sequences r and c, \(\mathcal {P}(M)\) contains all merges of r and c of length at most l(r) + l(c) − 1. Furthermore, suppose that there is a merge qrs such that qrs and l(q) > l(r) + l(s) − 1. By Lemma 2.10(iv), there is a merge \(q^{\prime } \in r \oplus s\) such that \(l(q^{\prime }) \le l(r) + l(s) - 1\), and \(\tau (q^{\prime }) = \tau (q)\). The latter yields \(\tau (q^{\prime }) \equiv \tau (q)\) and therefore, by Lemma 2.10(i), \(q^{\prime } \equiv q\), in particular, \(q^{\prime } \prec q \prec r \oplus s\).

Corollary 3.4

Let r and c be integer sequences and M be the merge matrix of r and c. There is a dominating merge in rc, i.e., an integer sequence trc such that trc, if and only if there is a dominating path in M, i.e., a path \(p \in \mathcal {P}(M)\) such that \(p \prec \mathcal {P}(M)\).

We now consider a type of merge that corresponds to non-diagonal paths in the merge matrix. These merges will be used in a construction presented in Section 3.5, and in the algorithmic applications of the Merge Dominator Lemma given in Section 4. For two integer sequences r and s, we denote by \(r \boxplus s\) the set of all non-diagonal merges of r and s, which are not allowed to have ‘diagonal’ steps: we have that for all \(t \in r \boxplus s\) and all i ∈ [l(t) − 1], if t(i) = r(ir) + s(is), then t(i + 1) ∈{r(ir + 1) + s(is), r(ir) + s(is + 1)}. As each non-diagonal merge directly corresponds to a non-diagonal path in the merge matrix (and vice versa), we can consider a non-diagonal path in a merge matrix to be a non-diagonal merge and vice versa. We now show that for each merge that uses diagonal steps, there is always a non-diagonal merge that dominates it.

Lemma 3.5

Let r and s be two integer sequences of length m and n, respectively. For any merge qrs, there is a non-diagonal merge \(q^{\prime } \in r \boxplus s\) such that \(q^{\prime } \prec q\). Furthermore, given q, \(q^{\prime }\) can be found using \(\mathcal {O}(m + n)\) integer operations.

Proof

This can be shown by the following local observation. Let i ∈ [l(q) − 1] be such that q(i), q(i + 1) is a diagonal step, i.e., there are indices ir ∈ [l(r) − 1] and is ∈ [l(s) − 1] such that q(i) = r(ir) + s(is) and q(i + 1) = r(ir + 1) + s(is + 1). Then, we insert the element \(x := \min \limits \{r(i_{r}) + s(i_{s} + 1), r(i_{r} + 1) + s(i_{s})\}\) between q(i) and q(i + 1). Since

$$x \le \max\{r(i_{r}) + s(i_{s}), r(i_{r} + 1) + s(i_{s} + 1)\} =: y,$$

we can repeat y twice in an extension of q so that one of the occurrences aligns with x, and we have that in this position, the value of \(q^{\prime }\) is at most the value of the extension of q.

Let \(q^{\prime }\) be the sequence obtained from q by applying this operation to all diagonal steps, then by the observation just made, we have that \(q^{\prime } \prec q\). It is clear that this can be implemented using \(\mathcal {O}(m + n)\) integer operations. □

Next, we define two special paths in a matrix M that will reappear in several places throughout this section. These paths can be viewed as the ‘corner paths’, where the first one follows the first row until it hits the last column and then follows the last column (\(p_{\lrcorner }(M)\)), and the second one follows the first column until it hits the last row and then follows the last row (\(p_{\ulcorner }(M)\)). Formally, we define them as follows:

$$ \begin{array}{@{}rcl@{}} p_{\lrcorner}(M) &:= (1, 1), (1, 2), \ldots, (1, n), (2, n), \ldots, (m, n) \\ p_{\ulcorner}(M) &:= (1, 1), (2, 1) \ldots, (m, 1), (m, 2), \ldots, (m, n) \end{array} $$

We use the shorthands ‘\(p_{\lrcorner }\)’ for ‘\(p_{\lrcorner }(M)\)’ and ‘\(p_{\ulcorner }\)’ for ‘\(p_{\ulcorner }(M)\)’ whenever M is clear from the context.

For instance, these paths appear in the following special cases of the Merge Dominator Lemma, which will be useful for several proofs in this section.

Lemma 3.6

Let r and c be integer sequences of length m and n, respectively, and let M be the merge matrix of r and c. Let \(i \in \arg \!\min \limits (r)\) and \(j \in \arg \!\min \limits (c)\).

  1. (i)

    If i = 1 and j = n, then \(p_{\lrcorner }\) dominates all paths in M, i.e., \(p_{\lrcorner } \prec \mathcal {P}(M)\).

  2. (ii)

    If i = m and j = 1, then \(p_{\ulcorner }\) dominates all paths in M, i.e., \(p_{\ulcorner } \prec \mathcal {P}(M)\).

Proof

(i) For an illustration of this proof see Fig. 4. Let q be any path in M and let \(t^{*} := \arg \!\max \limits ^{*}(q)\). Let furthermore \(q(t^{*}) = (t^{*}_{r}, t^{*}_{c})\). We divide \(p_{\lrcorner }\) and q in three consecutive parts each to show that \(p_{\lrcorner }\) dominates q.

  • We let \(p_{\lrcorner }^{1} := p_{\lrcorner }(1), \ldots , p_{\lrcorner }(t^{*}_{c} - 1)\) and q1 := q(1),…, q(t− 1).

    Fig. 4
    figure 4

    Situation in the proof of Lemma 3.6(i). The dot (light/dark) within each element of the corner path \(p_{\lrcorner }\) indicates with which elements of the path q it is ‘matched up’ in the extensions constructed in the proof

  • We let \(p_{\lrcorner }^{2} := p_{\lrcorner }(t^{*}_{c}), \ldots , p_{\lrcorner }(n + t^{*}_{r} - 1)\) and q2 := q(t).

  • We let \(p_{\lrcorner }^{3} := p_{\lrcorner }(n + t^{*}_{r}), \ldots , p_{\lrcorner }(m + n - 1)\) and q3 := q(t + 1),…, q(l(q)).

Since r(1) is a minimum row in M, we have that for all (k, ) ∈ [m] × [n], M[1, ] ≤ M[k, ]. This implies that there is an extension e1 of \(p_{\lrcorner }^{1}\) of length t− 1 such that M[e1] ≤ M[q1]. To clarify, the extension e1 can be obtained as follows. For each h ∈ [t− 1], let q(h) = (hr, hc). Then, at position h, e1 contains (1, hc). Since q is a path, e1 is indeed an extension of \(p_{\lrcorner }^{1}\). Similarly, there is an extension e3 of \(p_{\lrcorner }^{3}\) of length l(q) − t such that M[e3] ≤ M[q3]. Finally, let f2 be an extension of q2 that repeats its only element, q(t), \(n - t_{c}^{*} + t_{r}^{*}\) times. Since M[q(t)] is the maximum element on the sequence M[q] and r(1) is a minimum row and c(n) a minimum column in M, we have that \(M[p_{\lrcorner }^{2}] \le M[f_{2}]\): for all \(h \in [t_{c}^{*}..n]\), there is some hq ∈ [l(q)] such that q(hq) = (j, h) for some row j, so \(M[p_{\lrcorner }(h)] = M[1, h] \le M[j, h] = M[q(h_{q})] \le M[q(t^{*})]\) (similarly for all \(h \in [n..(n+t_{r}^{*}-1)]\)).

We define an extension e of \(p_{\lrcorner }\) as \(e := e_{1} \circ p_{\lrcorner }^{2} \circ e_{3}\) and an extension f of q as f := q1f2q3. Note that \(l(e) = l(f) = l(q) + n + t_{r}^{*} - (t_{c}^{*} + 1)\), and by the above discussion, we have that M[e] ≤ M[f]. (ii) follows from a symmetric argument. □

3.2 The Split Lemma

In this section we prove the first main step towards the Merge Dominator Lemma. It is fairly intuitive that a dominating merge has to contain the minimum element of a merge matrix. (Otherwise, there is a path that cannot be dominated by that merge.) The Split Lemma states that in fact, we can split the matrix M into two smaller submatrices, one that has the minimum element in the top right corner, and one that has the minimum element in the bottom left corner, compute a dominating path for each of them, and paste them together to obtain a dominating path for M.

Lemma 3.7 (Split Lemma)

Let r and c be integer sequences of length m and n, respectively, and let M be the merge matrix of r and c. Let \(i \in \arg \!\min \limits (r)\) and \(j \in \arg \!\min \limits (c)\). Let M1 := M[1..i,1..j] and M2 := M[i..m, j..n] and for all h ∈ [2], let \(p_{h} \in \mathcal {P}(M_{h})\) be a dominating path in Mh, i.e., \(p_{h} \prec \mathcal {P}(M_{h})\). Then, p1p2 is a dominating path in M, i.e., \(p_{1} \circ p_{2} \prec \mathcal {P}(M)\).

Proof

Let q be any path in M. If q contains (i, j), then q has two consecutive parts, say q1 and q2, such that \(q_{1} \in \mathcal {P}(M_{1})\) and \(q_{2} \in \mathcal {P}(M_{2})\). Hence, p1q1 and p2q2, so by Lemma 2.10(v), p1p2q1q2.

Now let p := p1p2 and suppose q does not contain (i, j). Then, q either contains some \((i, j^{\prime })\) with \(j^{\prime } < j\), or some \((i^{\prime }, j)\) with \(i^{\prime } < i\). We show how to construct extensions of p and q that witness that p dominates q in the first case, and remark that the second case can be shown symmetrically. We illustrate this situation in Fig. 5.

Fig. 5
figure 5

Situation in the proof of Lemma 3.7

Suppose that q contains \((i, j^{\prime })\) with \(j^{\prime } < j\). We show that pq. First, q also contains some \((i^{\prime }, j)\), where \(i^{\prime } > i\). Let h1 be the index of \((i, j^{\prime })\) in q, i.e., \(q(h_{1}) = (i, j^{\prime })\), and h2 denote the index of \((i^{\prime }, j)\) in q, i.e., \(q(h_{2}) = (i^{\prime }, j)\). We derive the following sequences from q.

  • We let q1 := q(1),…, q(h1) and \(q_{1}^{+} := q_{1} \circ (i, j^{\prime } + 1), \ldots , (i, j)\).

  • We let q12 := q(h1),…, q(h2).

  • We let q2 := q(h2),…, q(l(q)) and \(q_{2}^{+} := (i, j), (i + 1, j), \ldots , (i^{\prime }, j) \circ q_{2}\).

Since \(q_{1}^{+} \in \mathcal {P}(M_{1})\) and \(p_{1} \prec \mathcal {P}(M_{1})\), we have that \(p_{1} \prec q_{1}^{+}\), similarly that \(p_{2} \prec q_{2}^{+}\) and considering \(M_{3} := M[i^{\prime }..i,j..j^{\prime }]\), we have by Lemma 3.6(i) that \(p_{12} := p_{\lrcorner }(M_{3}) = (i, j^{\prime }), (i, j^{\prime } + 1), \ldots , (i, j), (i+1, j), \ldots , (i^{\prime }, j)\) dominates q12.

Consequently, we consider the following extensions of these sequences.

  1. (I)

    We let e1E(p1) and \(f_{1} \in E(q_{1}^{+})\) such that l(e1) = l(f1) and M[e1] ≤ M[f1].

  2. (II)

    We let e12E(p12), and f12E(q12) such that l(e12) = l(f12) and M[e12] ≤ M[f12].

  3. (III)

    We let e2E(p2), and \(f_{2} \in E(q_{2}^{+})\) such that l(e2) = l(f2) and M[e2] ≤ M[f2].

We construct extensions \(e^{\prime } \in E(p)\) and \(f^{\prime } \in E(q)\). The idea of this construction is that we stretch e1e2, the extensions of p1 and p2 to obtain \(e^{\prime }\) and we stretch the extensions of the the three parts of q, namely q1, q12, and q2, to obtain \(f^{\prime }\) in such a way that the relations between these extensions can be used to guarantee that in the end, \(M[e^{\prime }] \le M[f^{\prime }]\). The most crucial step uses the fact that \(q_{1}^{+}\) shares a horizontal subpath with p12 and that \(q_{2}^{+}\) shares a vertical subpath with p12. Since \(q_{1}^{+}\) is a path in M1, \(p_{1} \prec q_{1}^{+}\), and since p12q12 this allows for ‘transferring’ the domination property of p1 over \(q_{1}^{+}\) to a part of q12, via the subpath that \(q_{1}^{+}\) shares with p12. Similar for the other part of p12, using p2.

Let z be the last index in q of any element that is matched up with (i, j) in the extensions of (II). (Following the proof of Lemma 3.6, this would mean z is the index of \(\max \limits (q_{12})\) in q.) We first construct a pair of extensions \(e_{j}^{\prime } \in E(p_{1})\), and \(f_{j}^{\prime } \in E(q[1..z])\) with \(l(e_{j}^{\prime }) = l(f_{j}^{\prime })\) and \(M[e_{j}^{\prime }] \le M[f_{j}^{\prime }]\). With a symmetric procedure, we can obtain extensions of p2 and of q[(z + 1)..l(q)], and use them to obtain extensions of p = p1p2 and q = q[1..z] ∘ q[(z + 1)..l(q)] witnessing that pq.

We give the details of the first part of the construction. Let a be the index of the last repetition in f1 of q(h1 − 1), i.e., the index that appears just before \(q(h_{1}) = (i, j^{\prime })\) in f1. We let \(e_{j^{\prime }-1}^{\prime }[1..a] := e_{1}[1..a]\) and \(f_{j^{\prime }-1}^{\prime }[1..a] := f_{1}[1..a]\). By (I), \(M[e_{j^{\prime }-1}^{\prime }] \le M[f_{j^{\prime }-1}^{\prime }]\).

For \(x = j^{\prime }, j^{\prime } + 1, \ldots , j\), we inductively construct \(e_{x}^{\prime }\) and \(f_{x}^{\prime }\) using \(e_{x-1}^{\prime }\) and \(f_{x-1}^{\prime }\), for an illustration see Fig. 6. We maintain as an invariant that \(l(e_{x-1}^{\prime }) = l(f_{x-1}^{\prime })\) and that \(M[e_{x-1}^{\prime }] \le M[f_{x-1}^{\prime }]\). Let a1,…, ac denote the indices of the occurrences of (i, x) in f1, and b1,…, bd denote the indices of the occurrences of (i, x) in e12. If c = d, meaning that f1 and e12 repeat (i, x) the same number of times, then we can append e1[a1..ac] to \(e_{x-1}^{\prime }\) to obtain \(e_{x}^{\prime }\) and f12[b1..bd] to \(f_{x-1}^{\prime }\) to obtain \(f_{x}^{\prime }\). This way, we append the same number of elements to \(e_{x-1}^{\prime }\) and to \(f_{x-1}^{\prime }\); furthermore we know for each α ∈ [a1..ac] and each β ∈ [b1..bd] that M[e1(α)] ≤ M[i, x] ≤ M[f12(β)] by the properties of the extensions that we use. Therefore, \(M[e_{x}^{\prime }] \le M[f_{x}^{\prime }]\).

Fig. 6
figure 6

Constructing extensions in the proof of Lemma 3.7

If cd, then we repeat the last element of the shorter one of e1[a1..ac] and f12[b1..bd] the corresponding number of times to obtain extensions of the same length. The argument that \(M[e_{x}^{\prime }] \le M[f_{x}^{\prime }]\) after this step is the same as the one outlined in the previous case. Formally, we let:

$$ \begin{array}{@{}rcl@{}} \begin{array}{ll} e_{x}^{\prime} := e_{x-1}^{\prime} \circ e_{1}[a_{1}..a_{c}] \text{ and } f_{x}^{\prime} := f_{x-1}^{\prime} \circ f_{12}[b_{1}..b_{d}], &\text{ if } c = d \\ e_{x}^{\prime} := e_{x-1}^{\prime} \circ e_{1}[a_{1}..a_{c}] \circ \overbrace{e_{1}(a_{c}), \ldots, e_{1}(a_{c})}^{d - c \text{ times}} \text{ and } f_{x}^{\prime} := f_{x-1}^{\prime} \circ f_{12}[b_{1}..b_{d}], &\text{ if } c < d \\ e_{x}^{\prime} := e_{x-1}^{\prime} \circ e_{1}[a_{1}..a_{c}] \text{ and } f_{x}^{\prime} := f_{x-1}^{\prime} \circ f_{12}[b_{1}..b_{d}] \circ \overbrace{f_{12}(b_{d}), \ldots, f_{12}(b_{d})}^{c - d \text{ times}}, &\text{ if } c > d \end{array} \end{array} $$

In each case, we extended \(e_{x-1}^{\prime }\) and \(f_{x-1}^{\prime }\) by the same number of elements; furthermore we know by (I) that for y ∈{a1,…, ac}, M[e1(y)] ≤ M[f1(y)], by choice we have that for all \(y^{\prime } \in \{b_{1}, \ldots , b_{d}\}\), \(f_{1}(y) = e_{12}(y^{\prime })\) and we know that \(M[e_{12}(y^{\prime })] \le M[f_{12}(y^{\prime })]\) by (II). Hence, \(M[e_{x}^{\prime }] \le M[f_{x}^{\prime }]\) in either of the above cases. In the end of this process, we have \(e_{j}^{\prime } \in E(p_{1})\) and \(f_{j}^{\prime } \in E(q[1..z])\), and by construction, \(l(e_{j}^{\prime }) = l(f_{j}^{\prime })\) and \(M[e_{j}^{\prime }] \le M[f_{j}^{\prime }]\). □

3.3 The Chop Lemmas

Assume the notation of the Split Lemma. If we were to apply it recursively, it only yields a size reduction whenever (i, j)∉{(1,1),(m, n)}. Motivated by this issue, we prove two more lemmas to deal with the cases when (i, j) ∈{(1,1),(m, n)}, and we coin them the ‘Chop Lemmas’. It will turn out that when applied to typical sequences, a repeated application of these lemmas yields a dominating path in M. This insight crucially helps in arguing that the dominating path in a merge matrix can be found using linearly many integer operations. Before we present their statements and proofs, we need another auxiliary lemma.

Lemma 3.8

Let r and c be two integer sequences of length 3 where for all s ∈{r, c},

$$s(3) \le s(1) \le s(2).$$

Let L be the merge matrix of r and c. If L[1,2] ≤ L[2,1], then \(p_{\lrcorner }(L) \prec p_{\ulcorner }(L)\).

Proof

This can be witnessed by the following extensions \(e \in E(p_{\lrcorner }(L))\) and \(f \in E(p_{\ulcorner }(L))\):

$$ \begin{array}{@{}rcl@{}} e &\colon (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), (3, 3), (3, 3) \\ f &\colon (1, 1), (2, 1), (2, 1), (2, 1), (3, 1), (3, 2), (3, 3) \end{array} $$

We argue that ef:

$$ \begin{array}{@{}rcl@{}} L[1, 2] \le L[2, 1] &&~~~\text{(by assumption)} \\ L[1, 3] \le L[1, 2] \le L[2, 1] &&~~~\text{(since $c(3) \le c(2)$ and by assumption)} \\ L[2, 3] \le L[2, 1] &&~~~\text{(since $c(3) \le c(1)$)} \\ \forall i \in [3]\colon L[3, 3] \le L[3, i] &&~~~\text{(since $c(3) \le c(1) \le c(2)$)} \end{array} $$

Remark 3.9

We would like to stress that up to this point, all results in this section were shown in terms of arbitrary integer sequences. For the next lemma, we require the sequences considered to be typical sequences. In Section 3.5 we will generalize the results that rely on the following lemmas to arbitrary integer sequences. The generalization to arbitrary integer sequences is necessary for the applications in Section 4, since the integer sequences arising there are in general not typical sequences.

We are now ready to prove the Chop Lemmas for typical sequences. They come in two versions, one that is suited for the case of the bottom left submatrix after an application of the Split Lemma to M, and one for the top right submatrix. In the former case, we have that the last row is a minimum row and that the last column is a minimum column. We will prove this lemma in more detail and observe that the other case follows by symmetry with the arguments given in the following proof. For an illustration of the setting in the following lemma, see Fig. 7b.

Fig. 7
figure 7

Visual aides to the proof of Lemma 3.10. ( a) Typical sequence ending in the minimum. ( b) The general setting in Lemma 3.10

Lemma 3.10 (Chop Lemma - Bottom)

Let r and c be typical sequences of length m ≥ 3 and n ≥ 3, respectively, and let M be the merge matrix of r and c. Suppose that \(m \in \arg \!\min \limits (r)\) and \(n \in \arg \!\min \limits (c)\) and let M1 := M[1..(m − 2),1..n] and M2 := M[1..m,1..(n − 2)] and for all h ∈ [2], let \(p_{h} \prec \mathcal {P}(M_{h})\). Let \(p_{1}^{+} := p_{1} \circ (m-1, n), (m, n)\) and \(p_{2}^{+} := p_{2} \circ (m, n-1), (m, n)\).

  1. (i)

    If M[m − 2, n − 1] ≤ M[m − 1, n − 2], then \(p_{1}^{+} \prec \mathcal {P}(M)\).

  2. (ii)

    If M[m − 1, n − 2] ≤ M[m − 2, n − 1], then \(p_{2}^{+} \prec \mathcal (M)\).

Proof

Let s ∈{r, c}. Since s is a typical sequence and \(l(s) \in \arg \!\min \limits (s)\), we know by Corollary 2.8 that for all \(k \in \left [\left \lfloor l(s)/2 \right \rfloor \right ]\),

$$ \begin{array}{@{}rcl@{}} l(s) - 2k + 1 \!\in\! \arg\!\max(s[1..(l(s) - 2k + 1)]) \text{ and } l(s) - 2k \!\in\! \arg\!\min(s[1..(l(s) - 2k)]). \end{array} $$

Informally speaking, this means that the last element of s is the minimum, the (l(s) − 1)-th element of s is the maximum, the (l(s) − 2)-th element is ‘second-smallest’ element, and so on. We will therefore refer to the element at position l(s) − 2k (2kl(s)) as ‘\(\min \limits _{k+1}(s)\)’ (note that the minimum is achieved when k = 0, hence the ‘+ 1’), and elements at position l(s) − 2k + 1 (2k + 1 ≤ l(s) − 1) as ‘\(\max \limits _{k}(s)\)’. For an illustration of the shape of s see Fig. 7a and for an illustration of the general setting of this proof see Fig. 7b. We prove (i) and remark that the argument for (ii) is symmetric.

First, we show that each path in M is dominated by at least one of \(p_{1}^{+}\) and \(p_{2}^{+}\).

Claim 3.10.1 Let \(q \in \mathcal {P}(M)\). Then, for somer ∈ [2], \(p_{r}^{+} \prec q\).

Proof We may assume that q does not contain (m − 1, n − 1): if so, we could easily obtain a path \(q^{\prime }\) from q by some local replacements such that \(q^{\prime }\) dominates q, since M[m − 1, n − 1] is the maximum element of the matrix M. We may assume that q either contains (m − 1, n) or (m, n − 1). Assume that the former holds, and note that an argument for the latter case can be given analogously. Since q contains (m − 1, n), and since q does not contain (m − 1, n − 1), we may assume that q contains (m − 2, n): if not, we can simply add (m − 2, n) before (m − 1, n) to obtain a path that dominates q (recall that n is the column indexed by the minimum of c). Now, let \(q|_{M_{1}}\) be the restriction of q to M1, we then have that \(q = q|_{M_{1}} \circ (m-1, n), (m, n)\). Since p1 dominates all paths in M1, it dominates \(q|_{M_{1}}\) and so \(p_{1}^{+} \prec q\).

The remainder of the proof is devoted to showing that \(p_{1}^{+}\) dominates \(p_{2}^{+}\) which yields the lemma by Claim 3.10.1 and transitivity. To achieve that, we will show in a series of claims that we may assume that p2 contains (m − 2, n − 2). In particular, we show that if p2 does not contain (m − 2, n − 2), then there is another path in M2 that does contain (m − 2, n − 2) and dominates p2.

Claim 3.10.2 We may assume that there is a uniquej ∈ [n − 2] such thatp2 contains(m − 1, j).

Proof Clearly, p2 has to pass through the row m − 1 at some point. We show that we may assume that there is a unique such point. Suppose not and let j1,…, jt be such that p2 contains all (m − 1, ji), where i ∈ [t]. By the definition of a path in a matrix, we have that ji+ 1 = ji + 1 for all i ∈ [t − 1]. Let \(p_{2}^{\prime }\) be the path obtained from p2 by replacing, for each i ∈ [t − 1], the element (m − 1, ji) with the element (m − 2, ji). Since r(m − 2) ≤ r(m − 1) (recall that \(m-1 \in \arg \!\max \limits (r)\)), it is not difficult to see that \(p_{2}^{\prime }\) dominates p2, and clearly, \(p_{2}^{\prime }\) satisfies the condition of the claim.

Claim 3.10.3 Let j ∈ [n − 3] be such that p2 contains(m − 1, j). If j = n − 2k + 1 for some \(k \in \mathbb {N}\) with2k + 1 ≤ n − 1, then there is a path \(p_{2}^{\prime }\) that dominates p2 and contains (m − 1, j + 1).

Proof For an illustration see Fig. 8a. First, by Claim 3.10.2, we may assume that j is unique. Moreover, since j = n − 2k + 1 and j + 1 = n − 2k + 2 = n − 2(k − 1), we have that \(c(j) = \max \limits _{k}(c)\) and \(c(j+1) = \min \limits _{k}(c)\), respectively, and therefore c(j + 1) ≤ c(j). Hence, we may assume that the element after (m − 1, j) in p2 is (m, j + 1): if p2 contained (m, j) we could simply remove (m, j) from p2 without changing the fact that p2 is a dominating path since M[m, j] > M[m, j + 1]. We modify p2 as follows. We remove (m − 1, j), and add (m − 2, j) (if not already present), followed by (m − 2, j + 1) and then (m − 1, j + 1). For each x ∈{M[m − 2, j], M[m − 2, j + 1], M[m − 1, j + 1]}, we have that x < M[m − 1, j] (recall that r(m − 2) < r(m − 1) and c(j + 1) < c(j)). Hence, the resulting path dominates p2 and it contains (m − 1, j + 1).

Fig. 8
figure 8

Visualization of the arguments that lead to the conclusion that we may assume that p2 contains (m − 2, n − 2) in the proof of Lemma 3.10. (a) Situation of Claim 3.10.3. (b) Situation of Claim 3.10.4

Claim 3.10.4 Let j ∈ [n − 4] be such that p2 contains(m − 1, j). If j = n − 2(k − 1) for some \(k \in \left [3..\left \lfloor \frac {n}{2}\right \rfloor \right ]\), then there is a path \(p_{2}^{\prime }\) that dominates p2 and contains (m − 1, j + 2).

Proof For an illustration see Fig. 8b. Again, by Claim 3.10.2, we may assume that j is unique. Since j = n − 2(k − 1), we have that \(c(j) = \min \limits _{k}(c)\). First, if not already present, we insert (m − 2, j) just before (m − 1, j) in p2. This does not change the fact that p2 is a dominating path, since M[m − 2, j] < M[m − 1, j] (recall that r(m − 2) < r(m − 1)). Next, consider the 3 × 3 submatrix L := M[(m − 2)..m, j..(j + 2)]. Note that L is the submatrix of M restricted to the rows \(\min \limits (r)\), \(\max \limits (r)\), and \(\min \limits _{2}(r)\), and the columns \(\min \limits _{k}(c)\), \(\max \limits _{k - 1}(c)\), and \(\min \limits _{k-1}(c)\). Furthermore, we may assume that p2 restricted to L is equal to \({p}_{\ulcorner }(L)\): We know that p2 contains (m − 2, j) and (m − 1, j), and with Claim 3.10.2, by which we can assume that p2 contains no other element from row m − 1, we can derive that the next element in p2 is (m, j) or (m, j + 1). In the latter case we can insert (m, j) before (m, j + 1) since M[m, j] ≤ M[m, j + 1].

We show that \({p}_{\lrcorner }(L)\) dominates \({p}_{\ulcorner }(L)\), from which we can conclude that we can obtain a path \(p_{2}^{\prime }\) from p2 that contains (m − 1, j + 2) and dominates p2 by replacing \({p}_{\ulcorner }(L)\) with \({p}_{\lrcorner }(L)\). By Lemma 3.8, it suffices to show that M[m − 2, j + 1] ≤ M[m − 1, j], in other words, that \(\max \limits _{k-1}(c) + \min \limits _{2}(r) \le \max \limits (r) + \min \limits _{k}(c)\).

By the assumption of the lemma, we have that M[m − 2, n − 1] ≤ M[m − 1, n − 2], hence,

$$ \begin{array}{@{}rcl@{}} \max(c) + \min_{2}(r) \!\le\! \max(r) + \min_{2}(c), \text{ and so: } \max(c) - \min_{2}(c) \!\le\! \max(r) - \min_{2}(r). \end{array} $$

Next, we have that for all \(j \in \left [\left \lfloor n/2 \right \rfloor \right ]\),

$$ \begin{array}{@{}rcl@{}} \max(c) - \min_{2}(c) \ge \max_{j}(c) - \min_{j+1}(c). \end{array} $$

Putting the two together, we have that

$$ \begin{array}{@{}rcl@{}} \max_{k-1}(c) - \min_{k}(c) \le \max(r) - \min_{2}(r), \text{ and so: } \max_{k-1}(c) + \min_{2}(r) \!\le\! \max(r) + \min_{k}(c), \end{array} $$

which concludes the proof of the claim.

We are now ready to conclude the proof.

Claim 3.10.5 \(p_{1}^{+} \prec p_{2}^{+}\).

Proof By repeated application of Claims 3.10.3 and 3.10.4, we know that there is a path \(p_{2}^{\prime }\) in M2 that contains (m − 1, n − 2) and such that \(p_{2}^{\prime } \prec p_{2}\). Furthermore, we may assume that \(p_{2}^{\prime }\) contains (m − 2, n − 2) as well: we can simply add this element if it is not already present; since M[m − 2, n − 2] ≤ M[m − 1, n − 2], this does not change the property that \(p_{2}^{\prime } \prec p_{2}\). Now, let \(p_{2}^{\prime \prime }\) be the subpath of \(p_{2}^{\prime }\) ending in (m − 2, n − 2). (Note that \(p_{2}^{\prime \prime } \circ (m-2, n-1), (m-2, n) \in \mathcal {P}(M_{1})\).) Then, the following hold:

$$ \begin{array}{@{}rcl@{}} p_{1}^{+} &&\prec p_{2}^{\prime\prime} \circ (m-2, n-1), (m-2, n), (m-1, n), (m, n) \end{array} $$
(3)
$$ \begin{array}{@{}rcl@{}} &&\prec p_{2}^{\prime} \circ (m, n-1), (m, n) \end{array} $$
(4)
$$ \begin{array}{@{}rcl@{}} &&\prec p_{2}^{+} \end{array} $$
(5)

Here, (3) is due to \(p_{1} \prec \mathcal (M_{1})\) and therefore \(p_{1} \prec p_{2}^{\prime \prime } \circ (m-2, n-1), (m-2, n)\). Next, (5) is guaranteed since \(p_{2}^{\prime } \prec p_{2}\). We justify (4) as follows: Let L := M[(m − 2)..m,(n − 2)..n]. Then, \(p_{2}^{\prime \prime } \circ (m-2, n-1), (m-2, n), (m-1, n), (m, n)\) restricted to L is \({p}_{\lrcorner }(L)\) and \(p^{\prime } \circ (m, n-1), (m, n)\) restricted to L is \({p}_{\ulcorner }(L)\). Since L[1,2] = M[m − 2, n − 1] ≤ M[m − 1, n − 2] = L[2,1] by the assumption of this lemma (Lemma 3.10) we know that \({p}_{\lrcorner }(L) \prec {p}_{\ulcorner }(L)\) by Lemma 3.8.This concludes the proof of (i) and (ii) can be shown symmetrically. □

As the previous lemma always assumes that m ≥ 3 and n ≥ 3, we observe the corresponding base case which occurs when either m ≤ 2 or n ≤ 2. This base case is justified by the observation that in the bottom case, the last row and column of M are minimum.

Observation 3.11 (Base Case - Bottom)

Let r and c be typical sequences of length m and n, respectively, and let M be the merge matrix of r and c. Suppose that \(m \in \arg \!\min \limits (r)\) and \(n \in \arg \!\min \limits (c)\). If m ≤ 2 (n ≤ 2), thenFootnote 5

$$ p^{*} := (1,1), (m, 1), (m, 2), \ldots, (m, n) ~~~ (p^{*} := (1, 1), (1, n), (2, n), \ldots, (m, n)) $$

dominates \(\mathcal {P}(M)\), i.e., \(p^{*} \prec \mathcal {P}(M)\).

By symmetry, we have the following consequence of Lemma 3.10.

Corollary 3.12 (Chop Lemma - Top)

Let r and c be typical sequences of length m ≥ 3 and n ≥ 3, respectively, and let M be the merge matrix of r and c. Suppose that \(1 \in \arg \!\min \limits (r)\) and \(1 \in \arg \!\min \limits (c)\) and let M1 := M[3..m,1..n] and M2 := M[1..m,3..n] and for all h ∈ [2], let \(p_{h} \prec \mathcal {P}(M_{h})\). Let \(p_{1}^{+} := (1, 1), (2, 1) \circ p_{1}\) and \(p_{2}^{+} := (1, 1), (1, 2) \circ p_{2}\).

  1. (i)

    If M[3,2] ≤ M[2,3], then \(p_{1}^{+} \prec \mathcal {P}(M)\).

  2. (ii)

    If M[2,3] ≤ M[3,2], then \(p_{2}^{+} \prec \mathcal {P}(M)\).

Again, we observe the corresponding base case.

Observation 3.13 (Base Case - Top)

Let r and c be typical sequences of length m and n, respectively, and let M be the merge matrix of r and c. Suppose that \(1 \in \arg \!\min \limits (r)\) and \(1 \in \arg \!\min \limits (c)\). If m ≤ 2 (n ≤ 2), then

$$ p^{*} := (1,1), (1, 2), \ldots, (1, n), (m, n) ~~~ (p^{*} := (1, 1), (2, 1), \ldots, (m, 1), (m, n)) $$

dominates \(\mathcal {P}(M)\), i.e., \(p^{*} \prec \mathcal {P}(M)\).

3.4 The Split-and-Chop Algorithm

Equipped with the Split Lemma and the Chop Lemmas, we are now ready to give the algorithm that computes a dominating merge of two typical sequences. Consequently, we call this algorithm the ‘Split-and-Chop Algorithm’.

figure b

Lemma 3.14

Let r and c be typical sequences of length m and n, respectively. Then, there is an algorithm that finds a dominating path in the merge matrix of r and c using \(\mathcal {O}(m + n)\) integer operations.

Proof

The algorithm practically derives itself from the Split Lemma (Lemma 3.7) and the Chop Lemmas (Lemma 3.10 and Corollary 3.12). However, to make the algorithm run in the claimed bound, we are not able to construct the merge matrix of r and c. This turns out to be not necessary, as we can simply read off the crucial values upon which the recursion of the algorithm depends from the sequences directly. The details are given in Algorithm 2.

The number of integer operations in the Chop-subroutines can be computed as \(T(m + n) \le T(m + n - 2) + \mathcal {O}(1)\), which resolves to \(\mathcal {O}(m + n)\). Correctness follows from Lemmas 3.7 and 3.10 and Corollary 3.12 with the base cases given in Observations 3.11 and 3.13. □

3.5 Generalization to Arbitrary Integer Sequences

In this section we show how to generalize Lemma 3.14 to arbitrary integer sequences. In particular, we will show how to construct from a merge of two typical sequences τ(r) and τ(s) that dominates all of their merges, a merge of r and s that dominates all merges of r and s. The claimed result then follows from an application of Lemma 3.14. We illustrate the following construction in Fig. 9.

Fig. 9
figure 9

Illustration of the typical lift. On the left side, the view of the merge matrix M, with the rows and columns corresponding to elements of the typical sequences highlighted. Inside there, Mτ can be seen as a highlighted submatrix. The merge \(t^{\prime }\) is depicted as the large highlighted squares within Mτ and the small highlighted squares outside of Mτ show its completion to the typical lift of t. On the right side, an illustration that does not rely on the ‘matrix view’

The Typical Lift Let r and s be integer sequences and let tτ(r) ⊕ τ(s). Then, the typical lift of t, denoted by ρ(t), is an integer sequence ρ(t) ∈ rs, obtained from t as follows. For convenience, we will consider ρ(t) as a path in the merge matrix M of r and s.

Step 1. :

We construct \(t^{\prime } \in \tau (r) \boxplus \tau (s)\) such that \(t^{\prime } \prec t\) using Lemma 3.5. Throughout the following, consider \(t^{\prime }\) to be a path in the merge matrix Mτ of τ(r) and τ(s).

Step 2. :

First, we initialize \({\rho _{t}^{1}} := t^{\prime }(1) = (1, 1)\). For \(i = \{2, \ldots , l(t^{\prime })\}\), we proceed inductively as follows. Let (ir, is) = t(i) and let \((i^{\prime }_{r}, i^{\prime }_{s}) = t(i-1)\). (Note that t(i − 1) and t(i) are indices in Mτ.) Let furthermore (jr, js) be the index in M corresponding to (ir, is), and let \((j^{\prime }_{r}, j^{\prime }_{s})\) be the index in M corresponding to \((i^{\prime }_{r}, i^{\prime }_{s})\). Assume by induction that \(\rho _{t}^{i-1} \in \mathcal {P}(M[1..j_{r}^{\prime }, 1..j_{s}^{\prime }])\). We show how to extend \(\rho _{t}^{i-1}\) to a path in \({\rho _{t}^{i}}\) in M[1..jr,1..js]. Since \(t^{\prime }\) is non-diagonal, we have that \((i_{r}^{\prime }, i_{s}^{\prime }) \in \{(i_{r} - 1, i_{s}), (i_{r}, i_{s} - 1)\}\), so one of the two following cases applies.

Case S2.1 (\(i_{r}^{\prime } = i_{r} - 1\) and \(i_{s}^{\prime } = i_{s}\)).:

In this case, we let \({\rho _{t}^{i}} := \rho _{t}^{i-1} \circ \) \( (j_{r}^{\prime } + 1, j_{s}), \ldots , (j_{r}, j_{s})\).

Case S2.2 (\(i_{r}^{\prime } = i_{r}\) and \(i_{s}^{\prime } = i_{s} - 1\)).:

In this case, we let \({\rho _{t}^{i}} := \rho _{t}^{i-1} \circ \) \( (j_{r}, j_{s}^{\prime } + 1), \ldots , (j_{r}, j_{s})\).

Step 3. :

We return \(\rho (t) := \rho _{t}^{l(t^{\prime })}\).

Furthermore, it is readily seen that the typical lift contains no diagonal steps: we obtain it from a non-diagonal path in the merge matrix of τ(r) and τ(s) by inserting vertical and horizontal paths from the merge matrix of r and s between consecutive elements. Moreover, it is computable using linearly many integer operations, with Step 1 taking linearly many integer operations by Lemma 3.5. We summarize in the following observation.

Observation 3.15

Let r and s be integer sequences of length m and n, respectively, and let tτ(r) ⊕ τ(s). Then, \(\rho (t) \in r \boxplus s\), and ρ(t) can be computed using \(\mathcal {O}(m + n)\) integer operations.

We now show that if tτ(r) ⊕ τ(s) dominates all merges of τ(r) and τ(s), then the typical lift of t dominates all merges of r and s.

Lemma 3.16

Let r and s be integer sequences and let qrs. Let tτ(r) ⊕ τ(s) such that tτ(r) ⊕ τ(s). Then, ρ(t) ≺ q.

Proof

Let \(t^{\prime } \in \tau (r) \boxplus \tau (s)\) be the non-diagonal merge such that \(t^{\prime } \prec t\) used in the construction of ρ(t). We argue that \(\rho (t) \prec t^{\prime }\). To see this, let M be the merge matrix of r and s and consider any \((j_{r}^{\prime }, j_{s}^{\prime })\) and (jr, js) as in Step 2, and suppose that \(j_{s}^{\prime } = j_{s}\). (Note that either \(j_{s}^{\prime } = j_{s}\) or \(j_{r}^{\prime } = j_{r}\).) As the only elements of the typical sequence of r in \([j_{r}^{\prime }..j_{r}]\) are \(r(j_{r}^{\prime })\) and r(jr), we know that either for all \(h_{r} \in [j_{r}^{\prime }..j_{r}]\), \(r(j_{r}^{\prime }) \le r(h_{r}) \le r(j_{r})\), or for all \(h_{r} \in [j_{r}^{\prime }..j_{r}]\), \(r(j_{r}^{\prime }) \ge r(h_{r}) \ge r(j_{r})\). Therefore, in an extension of \(t^{\prime }\), we can repeat the index that yields \(\max \limits \{M[j_{r}^{\prime }, j_{s}], M[j_{r}, j_{s}]\}\) sufficiently many (i.e., \(j_{r} - j_{r}^{\prime }\)) times to ensure that the value of the extension of \(t^{\prime }\) is an upper bound for all values of ρ(t) in these positions.

To finish the proof, we have by Lemma 2.10(iii) that there exists a \(q^{\prime } \in \tau (r) \oplus \tau (s)\) such that \(q^{\prime } \prec q\). Since tτ(r) ⊕ τ(s), we can conclude:

$$ \begin{array}{@{}rcl@{}} \rho(t) \prec t^{\prime} \prec t \prec q^{\prime} \prec q. \end{array} $$

We wrap up and prove the Merge Dominator Lemma (Lemma 3.1), stated here in the slightly stronger form that the dominating merge is non-diagonal (which is necessary for the applications in Section 4).

Lemma 3.17 (Merge Dominator Lemma)

Let r and c be integer sequence of length m and n, respectively. There exists a dominating non-diagonal merge of r and c, i.e., an integer sequence \(t \in r \boxplus c\) such that trc, and this dominating merge can be computed using \(\mathcal {O}(m + n)\) integer operations.

Proof

The algorithm proceeds in the following steps.

  • Step 1. Compute τ(r) and τ(c).

  • Step 2. Apply the Split-and-Chop Algorithm on input (τ(r), τ(c)) to obtain tτ(r) ⊕ τ(c).

  • Step 3. Return the typical lift ρ(t) of t.

Correctness of the above algorithm follows from Corollary 3.4 and Lemmas 3.14 and 3.16 which together guarantee that ρ(t) ≺ rc, and by Observation 3.15, ρ(t) is a non-diagonal merge, i.e., \(\rho (t) \in r \boxplus c\). By Lemma 2.9, Step 1 can be done using \(\mathcal {O}(m + n)\) integer operations, by Lemma 3.14, Step 2 takes \(\mathcal {O}(m + n)\) integer operations as well, and by Observation 3.15, the typical lift of t can also be computed using \(\mathcal {O}(m + n)\) integer operations. Hence, the overall number of integer operations needed is \(\mathcal {O}(m + n)\). □

4 Directed Width Measures of Series Parallel Digraphs

In this section, we give algorithmic consequences of the Merge Dominator Lemma. In Section 4.1, we provide a polynomial time algorithm that computes the (weighted) cutwidth of (arc-weighted) series parallel digraphs. In Section 4.2 we provide a linear time transformation that allows for computing the modified cutwidth of an SPD on n vertices in polynomial time using the algorithm that computes the weighted cutwidth of an arc-weighted SPD.

4.1 Cutwidth

Recall that given a topological order v1,…, vn of a directed acyclic graph G, its cutwidth is the maximum over all i ∈ [n − 1] of the number of arcs that have their tail vertex in {v1,…, vi} and their head vertex in {vi+ 1,…, vn}, and that the cutwidth of G is the minimum cutwidth over all its topological orders.

To give the algorithm for the corresponding Cutwidth of Series Parallel Digraphs problem, we consider a generalized version where the input digraph has edge weights and we want to find a topological order that minimizes the weighted cutwidth.

Definition 4.1

Let G be a directed acyclic graph and \(\omega \colon A(G) \to \mathbb {N}\) be a weight function.Footnote 6 Fora topological order π ∈π(G) of G, the weighted cutwidth of (π, ω) is defined as

$$\mathsf{wcutw}(\pi, \omega) := \max\nolimits_{i \in [n-1]}\sum\nolimits_{\stackrel{(v, w) \in A(G)}{\pi(v) \le i, \pi(w) > i}} \omega(v, w),$$

and the weighted cutwidth of (G, ω) is \(\mathsf {wcutw}(G, \omega ) := \min \limits _{\pi \in {\Pi }(G)} \mathsf {wcutw}(\pi , \omega )\).

The corresponding computational problem is defined as follows.

figure c

The Cutwidth of Series Parallel Digraphs problem is the special case of the Weighted Cutwidth of Series Parallel Digraphs problem where all arcs have weight 1. Throughout this section, we refer to arc-weighted directed acyclic graphs simply as weighted directed acyclic graphs.

Given a weighted series parallel digraph (G, ω), our algorithm follows a bottom-up dynamic programming scheme along the decomposition tree T that yields G. Each node tV (T) has a subgraph Gt of G associated with it, that is also series parallel. Naturally, we use the property that Gt is obtained either via series or parallel composition of the SPD’s associated with its two children.

To make this problem amenable to be solved using merges of integer sequences, we define the following notion of a cut-size sequence of a topological order of a directed acyclic graph which records for each position in the order, how many arcs cross it.

Definition 4.2 (Cut-Size Sequence)

Let (G, ω) be a weighted directed acyclic graph on n vertices and let π ∈π(G) be a topological order of G. The sequence x(1),…, x(n − 1), where for i ∈ [n − 1],

$$x(i) = \sum\nolimits_{\stackrel{(u, v) \in A(G)}{\pi(u) \le i, \pi(v) > i}} \omega(u, v),$$

is the cut-size sequence of π, and denoted by σ(π). For a set of topological orders \({\Pi }^{\prime } \subseteq {\Pi }(G)\), we let \(\sigma ({\Pi }^{\prime }) := \{\sigma (\pi ) \mid \pi \in {\Pi }^{\prime }\}\).

Throughout the remainder of this section, we slightly abuse notation: If G1 and G2 are SPD’s that are being composed with a series composition, and π1 ∈π(G1) and π2 ∈π(G2), then we consider π = π1π2 to be the concatenation of the two topological orders where t2 = s1 only appears once in π. Moreover, to simplify notation, we consider the weight function of the given SPD only implicitly in places where it does not crucially influence the arguments.

We first argue via two simple observations that when computing the weighted cutwidth of a weighted series parallel digraph G by following its decomposition tree in a bottom up manner, we only have to keep track of a set of topological orders that induce a set of cut-size sequences that dominate all cut-size sequences of G.

Observation 4.3

Let G be a weighted DAG and π, λ ∈π(G). If σ(π) ≺ σ(λ), then wcutw(π) ≤wcutw(λ).

This is simply due to the fact that σ(π) ≺ σ(λ) implies that \(\max \limits (\sigma (\pi )) \le \max \limits (\sigma (\lambda ))\). Next, if G is obtained from G1 and G2 via series or parallel composition, and we have π1, λ1 ∈π(G1) such that σ(π1) ≺ σ(λ1), then it is always beneficial to choose π1 over λ1, and λ1 can be disregarded.

Observation 4.4

Let G be a weighted SPD that is obtained via series or parallel composition from weighted SPD’s G1 and G2. Let π1, λ1 ∈π(G1) be such that σ(π1) ≺ σ(λ1). Let π, λ ∈π(G) be such that \(\pi |_{V(G_{1})} = \pi _{1}\), \(\lambda |_{V(G_{1})} = \lambda _{1}\), and for all vV (G2), π(v) = λ(v). Then, σ(π) ≺ σ(λ).

The previous observation is justified as follows. Let σ(λ) = x(1),…, x(n − 1) and σ(λ) = y(1),…, y(n − 1). Then, for each i ∈ [n − 1], the arcs of G2 contribute equally to the values x(i) and y(i) (in particular since G1 and G2 are arc-disjoint). Therefore, we can use extensions of σ(π1) and σ(λ1) that witnesses that σ(π1) ≺ σ(λ1) to construct extensions of σ(π) and σ(λ) that witness that σ(π) ≺ σ(λ).

The following lemma states that the cut-size sequences of a weighted SPD G can be computed by pairwise concatenation or non-diagonal merging (depending on whether G is obtained via series or parallel composition) of the two smaller SPD’s that G is obtained from. Intuitively speaking, the reason why we can only consider non-diagonal merges is the following. When G is obtained from G1 and G2 via parallel composition, then each topological order of G can be considered the ‘merge’ of a topological order of G1 and one of G2, where each position (apart from the first and the last) contains a vertex either from G1 or from G2. Now, in a merge of a cut-size sequence of G1 with a cut-size sequence of G2, a diagonal step would essentially mean that in some position, we insert both a vertex from G1 and a vertex of G2; this is of course not possible.

Lemma 4.5

Let G1 and G2 be weighted SPD’s. Then the following hold.

  1. (i)

    σ(π(G1G2)) = σ(π(G1)) ⊙ σ(π(G2)).

  2. (ii)

    \(\sigma ({\Pi }(G_{1} // G_{2})) = \sigma ({\Pi }(G_{1})) \boxplus \sigma ({\Pi }(G_{2}))\).

Proof

(i). Let σ(π) ∈ σ(π(G1G2)) be such that π is a topological order of G1G2. Then, π consists of two contiguous parts, namely \(\pi _{1} := \pi |_{V(G_{1})} \in {\Pi }(G_{1})\) followed by \(\pi _{2} := \pi |_{V(G_{2})} \in {\Pi }(G_{2})\). Since there are no arcs from V (G1) ∖{t1} to V (G2) ∖{s2}, we have that σ(π) = σ(π1) ∘ σ(π2) ∈ σ(π(G1)) ⊙ σ(π(G2)). The other inclusion follows similarly.

(ii). Let σ(π) ∈ σ(π(G1//G2)) be such that π is a topological order of G1//G2. Let \(\pi _{1} := \pi |_{V(G_{1})}\) and \(\pi _{2} := \pi |_{V(G_{2})}\). It is clear that π1 ∈π(G1) and that π2 ∈π(G2). Let σ(π) = x(1),…, x(n − 1), σ(π1) = y1(1),…, y1(n1 − 1), and σ(π2) = y2(1),…, y2(n2 − 1). For any i ∈{1,…, n − 1}, let i1 be the maximum index such that \(\pi (\pi _{1}^{-1}(i_{1})) \le i\), and define i2 accordingly. Then, the set of arcs that cross the cut between positions i and i + 1 in π is the union of the set of arcs crossing the cut between positions i1 and i1 + 1 in π1 and the set of arcs crossing the cut between positions i2 and i2 + 1 in π2. Since G1 and G2 are arc-disjoint, this means that x(i) = y1(i1) + y2(i2). Together with the observation that each vertex at position i + 1 < n in π is either from G1 or from G2, we have that

$$x(i+1) \in \{y_{1}(i_{1} + 1) + y_{2}(i_{2}), y_{1}(i_{1}) + y_{2}(i_{2} + 1)\}, $$

in other words, we have that \(\sigma (\pi ) \in \sigma (\pi _{1}) \boxplus \sigma (\pi _{2}) \subseteq \sigma ({\Pi }(G_{1})) \boxplus \sigma ({\Pi }(G_{2}))\). The other inclusion can be shown similarly, essentially using the fact that we are only considering non-diagonal merges. □

We now prove the crucial lemma of this section which states that we can compute a dominating cut-size sequence of a weighted SPD G from dominating cut-size sequences of the smaller weighted SPD’s that G is obtained from. For technical reasons, we assume in the following lemma that G has no parallel arcs.

Lemma 4.6

Let G be a weighted SPD without parallel arcs. Then there is a topological order π of G such that σ(π) dominates all cut-size sequences of G. Moreover, the following hold. Let G1 and G2 be weighted SPD’s and for r ∈ [2], let \(\pi _{r}^{*}\) be a topological order of Gr such that \(\sigma (\pi _{r}^{*})\) dominates all cut-size sequences of Gr.

  1. (i)

    If G = G1G2, then \(\pi ^{*} = \pi _{1}^{*} \circ \pi _{2}^{*}\).

  2. (ii)

    If G = G1//G2, then π can be found as the topological order of G such that σ(π) dominates \(\sigma (\pi ^{*}_{1}) \boxplus \sigma (\pi _{2}^{*})\).

Proof

We prove the lemma by induction on the number of vertices of G. If |V (G)| = 2, then the claim is trivially true (there is only one topological order). Suppose that |V (G)| =: n > 2. Since n > 2 and G has no parallel arcs, we know that G can be obtained from two SPD’s G1 and G2 via series or parallel composition with |V (G1)| =: n1 < n and |V (G2)| =: n2 < n. By the induction hypothesis, for r ∈ [2], there is a unique topological order \(\pi _{r}^{*}\) such that \(\sigma (\pi _{r}^{*})\) dominates all cut-size sequences of Gr.

Suppose G = G1G2. Since \(\sigma (\pi _{1}^{*})\) dominates all cut-size sequences of G1 and \(\sigma (\pi _{2}^{*})\) dominates all cut-size sequences of G2, we can conclude using Lemma 2.10(v) that \(\sigma (\pi _{1}^{*}) \circ \sigma (\pi _{2}^{*})\) dominates σ(π(G1)) ⊙ σ(π(G2)) which together with Lemma 4.5(i) allows us to conclude that \(\sigma (\pi _{1}^{*}) \circ \sigma (\pi _{2}^{*}) = \sigma (\pi _{1}^{*} \circ \pi _{2}^{*})\) dominates all cut-size sequences of G. This proves (i).

Suppose that G = G1G2, and let π be a topological order of G such that σ(π) dominates \(\sigma (\pi _{1}^{*}) \boxplus \sigma (\pi _{2}^{*})\). We show that σ(π) dominates σ(π(G)). Let π ∈π(G). By Lemma 4.5(ii), there exist topological orders π1 ∈π(G1) and π2 ∈π(G2) such that \(\sigma (\pi ) \in \sigma (\pi _{1}) \boxplus \sigma (\pi _{2})\). In other words, there are extensions e1 of σ(π1) and e2 of σ(π2) of the same length such that σ(π) = e1 + e2. For r ∈ [2], since \(\sigma (\pi _{r}^{*}) \prec \sigma (\pi _{r})\), we have that \(\sigma (\pi _{r}^{*}) \prec e_{r}\). By Lemma 2.10(ii),Footnote 7 there exists some \(f \in \sigma (\pi _{1}^{*}) \oplus \sigma (\pi _{2}^{*})\) such that fe1 + e2, and by Lemma 3.5, there is some \(f^{\prime } \in \sigma (\pi _{1}^{*}) \boxplus \sigma (\pi _{2}^{*})\) such that \(f^{\prime } \prec f\). Since \(\sigma (\pi ^{*}) \prec \sigma (\pi _{1}^{*}) \boxplus \sigma (\pi _{2}^{*})\), we have that \(\sigma (\pi ^{*}) \prec f^{\prime }\), and hence (ii) follows:

$$ \begin{array}{@{}rcl@{}} \sigma(\pi^{*}) \prec f^{\prime} \prec f \prec e_{1} + e_{2} = \sigma(\pi). \end{array} $$

We are now ready to prove the first main result of this section.

Theorem 4.7

Let (G, ω) be a weighted series parallel digraph on n vertices and m arcs, and let \(W := {\sum }_{(u, v) \in A(G)} \omega (u, v)\). There is an algorithm that computes in time \(\mathcal {O}((n^{2} + m)\log W)\) the weighted cutwidth of (G, ω), and outputs a topological order that achieves the upper bound.

Proof

First, we modify G so that it has no parallel arcs, without changing the weighted cutwidth. for any pair u, vV (G) such that G has p > 1 parallel (u, v)-arcs, say a1,…, ap, we replace a1,…, ap with a single arc a of weight \({\sum }_{i \in [p]} \omega (a_{i})\). It is easy to see that this does not change the cutwidth, and clearly, the resulting graph is still series parallel. Moreover, this can be done in time at most \(\mathcal {O}(m \log W)\), and we may from now on assume that \(|{A(G)}| = \mathcal {O}(n^{2})\).

We use the algorithm of Valdes et al. [25] to compute in time \(\mathcal {O}(n + |{A(G)}|) = \mathcal {O}(n^{2})\) a decomposition tree T that yields G, see Theorem 2.13. We process T in a bottom-up fashion, and at each node tV (T), compute a topological order πt of Gt, the series parallel digraph associated with node t, such that σ(πt) dominates all cut-size sequences of Gt. Let tV (T).

Case 1 (t is a leaf node).:

In this case, Gt is a single arc and there is precisely one topological order of Gt; we return that order.

Case 2 (t is a series node with left child and right child r).:

In this case, we look up π, a topological order such that σ(π) dominates all cut-size sequences of G, and πr, a topological order such that σ(πr) dominates all cut-size sequences of Gr. Following Lemma 4.6(i), we return ππr.

Case 3 (t is a parallel node with left child and right child r).:

In this case, we look up π and πr as in Case 2, and we compute πt such that σ(πt) dominates \(\sigma (\pi _{\ell }) \boxplus \sigma (\pi _{r})\) using the Merge Dominator Lemma (Lemma 3.17). Following Lemma 4.6(ii), we return πt.

Finally, we return \(\pi _{\mathfrak {r}}\), the topological order (of \(G_{\mathfrak {r}} = G\)) computed for \(\mathfrak {r}\), the root of T. Observations 4.3 and 4.4 ensure that it is sufficient to compute in each of the above cases a set \({\Pi }_{t}^{*} \subseteq {\Pi }(G_{t})\) with the following property. For each πt ∈π(Gt), there is a \(\pi _{t}^{*} \in {\Pi }_{t}^{*}\) such that \(\sigma (\pi _{t}^{*}) \prec \sigma (\pi _{t})\). By Lemma 4.6, we know that we can always find such a set of size one which is precisely what we compute in each of the above cases. Correctness of the algorithm follows. Since T has \(\mathcal {O}(n)\) nodes and each of the above cases can be handled in at most \(\mathcal {O}(n)\) integer operations by Lemma 3.17, the total runtime of the algorithm after removing parallel arcs is \(\mathcal {O}(n^{2} \log W)\), since the maximum value of any element in a cut-size sequence is trivially upper bounded by W. Therefore, the total runtime is \(\mathcal {O}((n^{2} + m)\log W)\). □

We can easily use the algorithm of the previous theorem to solve the (unweighted) Cutwidth of Series Parallel Digraphs problem.

Corollary 4.8

Let G be series parallel digraph on n vertices and m arcs. There is an algorithm that computes in time \(\mathcal {O}((n^{2} + m) \log m)\) the cutwidth of G, and outputs a topological order that achieves the upper bound.

Proof

We create a weighted SPD \((G^{\prime }, \omega ^{\prime })\) as follows. The SPD \(G^{\prime }\) is obtained from G by replacing each set of parallel arcs from one vertex to another with a single arc. We let \(\omega ^{\prime } \colon A(G^{\prime }) \to \mathbb {N}\), such that for all \((u, v) \in A(G^{\prime })\), \(\omega ^{\prime }(u, v)\) is the number of parallel (u, v)-arcs in G. It is clear that the weighted cutwidth of \((G^{\prime }, \omega ^{\prime })\) is equal to the cutwidth of G. We can therefore apply the algorithm of Theorem 4.7 to find the cutwidth of G via the weighted cutwidth of \((G^{\prime }, \omega ^{\prime })\). □

4.2 Modified Cutwidth

We now show how to use the algorithm for computing the weighted cutwidth of series parallel digraphs from Theorem 4.7 to give an algorithm that computes the modified cutwidth of a series parallel digraph in polynomial time. Recall that given a topological order v1,…, vn of a directed acyclic graph G, its modified cutwidth is the maximum over all i ∈ [n − 1] of the number of arcs that have their tail vertex in {v1,…, vi− 1} and their head vertex in {vi+ 1,…, vn}, and that the modified cutwidth of G is the minimum modified cutwidth over all its topological orders. We are dealing with the following computational problem.

figure d

To solve this problem, we will provide a transformation which allows for applying the algorithm for the Weighted Cutwidth of SPD’s problem to compute the modified cutwidth. We would like to remark that this transformation is similar to one provided in [6], however some modifications are necessary to ensure that the digraph resulting from the transformation is an SPD.

Theorem 4.9

Let G be a series parallel digraph on n vertices and m arcs. There is an algorithm that computes in time \(\mathcal {O}((n + m)^{2}\log m)\) the modified cutwidth of G, and outputs a topological order of G that achieves the upper bound.

Proof

We give a transformation that enables us to solve Modified Cutwidth of SPD’s with help of an algorithm that solves Weighted Cutwidth of SPD’s.

Let \((G^{\prime \prime }, (s, t))\) be an SPD on n vertices and m arcs. If \(G^{\prime \prime }\) has parallel arcs then we subdivide all but one of the parallel arcs for each pair of vertices. This does not change the (modified) cutwidth, and keeps a digraph series parallel. Let (G,(s, t)) denote the resulting SPD which will be the input graph to the Modified Cutwidth of SPD’s problem that we are solving. Note that \(|{V(G)}| = \mathcal {O}(n + m)\) and that \(|{A(G)}| = \mathcal {O}(m)\). We construct another digraph \(G^{\prime }\) and an arc-weight function \(\omega \colon A(G^{\prime }) \to \mathbb {N}\) as follows. For each vertex vV (G) ∖{s, t}, we add to \(G^{\prime }\) two vertices vin and vout. We add s and t to \(G^{\prime }\) and write s as sout and t as tin. We add the following arcs to \(G^{\prime }\). First, for each vV (G), we add an arc (vin, vout) and we let ω(vin, vout) := m + 1. Next, for each arc (v, w) ∈ A(G), we add an arc (vout, win) to \(G^{\prime }\) and we let ω(vout, win) := 1. For an illustration see Fig. 10.

Fig. 10
figure 10

Illustration of the transformation given in the proof of Theorem 4.9. Note that in this case, m = 6, so the arcs between vertices vin and vout have weight 7

We observe that the size of \(G^{\prime }\) is linear in the size of G, and then prove that if \(G^{\prime }\) is obtained from applying the above transformation to a series parallel digraph, then \(G^{\prime }\) is itself an SPD.

Observation 4.9.1 Let G and \(G^{\prime }\) be as above. Then, \(n^{\prime } := |{V(G^{\prime })}| \le 2|{V(G)}|\) and \(|{A(G^{\prime })}| \le |{A(G)}| + |{V(G)}|\).

Claim 4.9.2 If G is a series parallel digraph, then \(G^{\prime }\) as constructed above is an SPD.

Proof We prove the claim by induction on n, the number of vertices of G. For the base case when n = 2, we have that G is a single arc in which case \(G^{\prime }\) is a single arc as well. Now suppose n > 2. Since n > 2, G is obtained from two series parallel digraphs G1 and G2 via series or parallel composition. Since G has no parallel arcs, we can use the induction hypothesis to conclude that the graphs \(G_{1}^{\prime }\) and \(G_{2}^{\prime }\) obtained via our construction are series parallel. Now, if G = G1//G2, then it is immediate that \(G^{\prime }\) is series parallel. If G = G1G2, then we have that in \(G^{\prime }\), the vertex that was constructed since t1 and s2 were identified, call this vertex x, got split into two vertices xin and xout with a directed arc of weight m + 1 pointing from xin to xout. Call the series parallel digraph consisting only of this arc (X,(xin, xout)). We now have that \(G^{\prime } = G_{1}^{\prime } \bullet X \bullet G_{2}^{\prime }\), so \(G^{\prime }\) is series parallel in this case as well.

We are now ready to prove the correctness of this transformation. To do so, we will assume that we are given an integer k and we want to decide whether the modified cutwidth of G is at most k.

Claim 4.9.3 If G has modified cutwidth at most k, then \(G^{\prime }\) has weighted cutwidth at most m + k + 1.

Proof Take a topological order π of G such that mcutw(π) ≤ k. We obtain \(\pi ^{\prime }\) from π by replacing each vertex vV (G) ∖{s, t} by vin followed directly by vout. Clearly, this is a topological order of \(G^{\prime }\). We show that the weighted cutwidth of this order is at most m + k + 1.

Let \(i \in [n^{\prime }-1]\) and consider the cut between position i and i + 1 in \(\pi ^{\prime }\). We have to consider two cases. In the first case, there is some vV (G) such that \(\pi ^{\prime -1}(i) = v_{in}\) and \(\pi ^{\prime -1}(i+1) = v_{out}\). Then, there is an arc of weight m + 1 from vin to vout crossing this cut, and some other arcs of the form (uout, win) for some arc (u, w) ∈ A(G). All these arcs cross position π(v) in π, so since mcutw(π) ≤ k, there are at most k of them. Furthermore, for each such arc we have that ω((uout, win)) = 1 by construction, so the total weight of this cut is at most m + k + 1.

In the second case, we have that \(\pi ^{\prime -1}(i) = v_{out}\) and \(\pi ^{\prime -1}(i+1) = w_{in}\) for some v, wV (G), vw. By construction, we have that π(w) = π(v) + 1. Hence, any arc crossing the cut between i and i + 1 in \(\pi ^{\prime }\) is of one of the following forms.

  1. (i)

    It is (xout, yin) for some (x, y) ∈ A(G) with π(x) < π(v) and π(y) > π(v), or

  2. (ii)

    it is (xout, yin) for some (x, y) ∈ A(G) with π(x) < π(w) and π(y) > π(w), or

  3. (iii)

    it is (vout, win).

Since mcutw(G) ≤ k, there are at most k arcs of the first and second type, and since G has no parallel arcs, there is at most one arc of the third type. By construction, all these arcs have weight one, so the total weight of this cut is 2k + 1 ≤ m + k + 1.

Claim 4.9.4 If \(G^{\prime }\) has weighted cutwidth at most m + k + 1, then G has modified cutwidth at most k.

Proof Let \(\pi ^{\prime }\) be a topological order of \(G^{\prime }\) such that \(\mathsf {wcutw}(\pi ^{\prime }, \omega ) \le m + k + 1\). First, we claim that for all vV (G) ∖{s, t}, we have that \(\pi ^{\prime }(v_{out}) = \pi ^{\prime }(v_{in}) + 1\). Suppose not, for some vertex v. If we have that \(\pi ^{\prime }(v_{in}) < \pi ^{\prime }(w_{in}) < \pi ^{\prime }(v_{out})\) for some wV (G) ∖{s, t} and wv, then the cut between \(\pi ^{\prime }(w_{in})\) and \(\pi ^{\prime }(w_{in}) + 1\) has weight at least 2m + 2: the two arcs (vin, vout) and (win, wout) cross this cut, and they are of weight m + 1 each. Similarly, if \(\pi ^{\prime }(v_{in}) < \pi ^{\prime }(w_{out}) < \pi ^{\prime }(v_{out})\), then the cut between \(\pi ^{\prime }(w_{out}) - 1\) and \(\pi ^{\prime }(w_{out})\) has weight at least 2m + 2. Since 2m + 2 > m + k + 1, we have a contradiction in both cases.

We define a linear order π of G as follows. We let π(s) := 1, π(t) := n, and for all v, wV (G) ∖{s, t}, we have π(v) < π(w) if and only if \(\pi ^{\prime }(v_{in}) < \pi ^{\prime }(w_{in})\). It is clear that π is a topological order of G; we show that π has modified cutwidth at most k. Consider an arc (x, y) that crosses a vertex v in π, i.e., we have that π(x) < π(v) < π(y). We have just argued that \(\pi ^{\prime }(v_{out}) = \pi ^{\prime }(v_{in}) + 1\), so we have that the arc (xout, yin) crosses the cut between vin and vout in \(\pi ^{\prime }\). Recall that there is an arc of weight m + 1 from vin to vout, so since \(\mathsf {wcutw}(\pi ^{\prime }, \omega ) \le m + k + 1\), we can conclude that in π, there are at most (m + k + 1) − (m − 1) = k arcs crossing the vertex v in π.

Now, to compute the modified cutwidth of G, we run the above described transformation to obtain \((G^{\prime }, \omega )\), and compute a topological order that gives the smallest weighted cutwidth of \((G^{\prime }, \omega )\) using Theorem 4.7. We can then follow the argument given in the proof of Claim 4.9.4 to obtain a topological order for G that gives the smalles modified cutwidth of G.

By Claim 4.9.2, \(G^{\prime }\) is an SPD, so we can indeed apply the algorithm of Theorem 4.7 to solve the instance \((G^{\prime }, \omega )\). Correctness follows from Claims 4.9.3 and 4.9.4. By Observation 4.9.1, \(|{V(G^{\prime })}| = \mathcal {O}(|{V(G)}|) = \mathcal {O}(n + m)\), and \(|{A(G^{\prime })}| \le |{V(G)}| + |{A(G)}| = \mathcal {O}(m + n)\), and clearly, \((G^{\prime }, \omega )\) can be constructed in time \(\mathcal {O}(|{V(G)}| + |{A(G)}|) = \mathcal {O}(n + m)\); since \({\sum }_{(u, v) \in A(G^{\prime })} \omega (u, v) = m^{\mathcal {O}(1)}\), the overall runtime of this procedure is at most \(\mathcal {O}((n + m)^{2} \log m)\). □

5 Conclusions

In this paper, we obtained a new technical insight in a now over a quarter century old technique, namely the use of typical sequences. The insight led to new polynomial time algorithms. Since its inception, algorithms based on typical sequences give the best asymptotic bounds for linear time FPT algorithms for treewidth and pathwidth, as functions of the target parameter. It still remains a challenge to improve upon these bounds (\(2^{O(pw^{2})}\), respectively \(2^{O(tw^{3})}\)), or give non-trivial lower bounds for parameterized pathwidth or treewidth. Possibly, the Merge Dominator Lemma can be helpful to get some progress here.

As other open problems, we ask whether there are other width parameters for which the Merge Dominator Lemma implies polynomial time or XP algorithms, or whether such algorithms exist for other classes of graphs. For instance, for which width measures can we give XP algorithms when parameterized by the treewidth of the input graph?

Lastly, we present one more open problem regarding the computation of width measures of series parallel digraphs. The vertex separation number of a topological order is the maximum over all cuts induced by the order of the number of vertices on the left side that have a neighbor on the right side. Finding a topological order that minimizes the vertex separation number corresponds to an important problem in compiler optimization, specifically to a problem related to register allocation: we are given a set of expressions (a “basic block” or “straight-line code”) that have certain dependencies among each other and the task is to find a sequence for executing these expressions, respecting the dependencies, such that the number of used registers is minimized. The dependencies among these expressions form an acyclic digraph and any allowed schedule is a topological order. This problem was shown to be NP-hard by Sethi [20] while Kessler [15] gave a \(2^{\mathcal {O}(n)}\) time exact algorithm, improving over the \(n^{\mathcal {O}(n)}\) naive brute-force approach. Sethi and Ullman [21] showed in 1970 that the problem is linear time solvable if the acyclic digraph is a tree which (to the best of our knowledge) is the only known polynomial time case. It seems that with the help of the Merge Dominator Lemma, we might be able to obtain a polynomial time algorithm for this problem on series parallel digraphs. However, the application cannot be as immediate as in the case of cutwidth and modified cutwidth. The vertex separation number counts vertices rather than edges (as it is the case for cutwidth and modified cutwidth), and in a parallel composition, the sources of two SPDs are being identified. In a straightforward approach, this results in overcounting the contribution of the source vertex to several cuts, which is the main obstacle that needs to be overcome. While at first glance this may look like an issue that could be solved with rather straightforward techniques, we want to point out that (in our own experience) such direct approaches are fraught with very subtle pitfalls.