Bounded Signal Flow Over Vertices
In this subsection, we investigate how the vertex-wise structure of the source–target pairs influences the computational complexity of MAXIMUM TREE ORIENTATION. More specifically, first we consider the parameter m
v
denoting the maximum number of source–target paths passing through a vertex. We show that MTO can be solved in O(2 mv ⋅ |P| + n4) time. In other words, MTO is fixed-parameter tractable with respect to the parameter m
v
. Motivated by this positive result, we explore in more depth the structure of the source–target paths that pass through a vertex. To this end, we introduce the concept of "cross pairs" and show that for cross-pair-free instances MTO can be solved in O(n2) time. Informally speaking, an instance is cross-pair-free if the input tree can be rooted such that for each source–target pair one endpoint is an ancestor of the other one. Then, for a rooted MTO instance a cross pair is a source–target pair such that none of its endpoints is the ancestor of the other endpoint. By refining the solving strategy for cross-pair-free instances, we show that MAXIMUM TREE ORIENTATION can be solved in time, where q
v
denotes the maximum number of cross pairs passing through a vertex.
All algorithms in this subsection are based on dynamic programming, and, hence, since source–target pair weights can easily be incorporated, extend to W-MTO.
Parameter "Maximum Number of Pairs Per Vertex"
Here, we show that W-MTO is fixed-parameter tractable for the parameter m
v
denoting the maximum number of source–target pairs passing through a vertex. To this end, we prove in Theorem 1 that we can construct in polynomial time a tree decomposition of the conflict graph of treewidth at most m
v
. Recall that (weighted) MTO is equivalent to (weighted) VERTEX COVER on the conflict graph (see Proposition 1). Thus, the running time follows by the fact that (weighted) VERTEX COVER can be solved in O(2twn) time, given a tree decomposition of width tw [15]. □
Theorem 1. On n-vertex trees, WEIGHTED MAXIMUM TREE ORIENTATION is solvable in O(2 mv⋅ |P| + n4) time, where m
v
denotes the maximum number of source–target pairs passing through a vertex.
Proof. First, we show how to construct a tree decomposition of width m
v
of the conflict graph in polynomial time. Let (T = (V, E), P) denote an MTO instance and let G
c
= (P, E
c
) denote the associated conflict graph. The basic idea is that we can use T as the underlying tree of a tree decomposition of G
c
= (P, E
c
). More specifically, the tree decomposition is given by 〈{P
v
| v ∈ V}, T〉 for all v ∈ V. Recall that P
v
denotes the set of source–target pairs passing through v. Observe that each vertex p ∈ P of the conflict graph appears exactly in the bags X
v
for all v ∈ V (path
T
(p)). Moreover, note that if two source–target pairs p = [s, t] and p' = [s', t'] are in conflict (and hence are adjacent in the conflict graph), then path
T
(s, t) and path
T
(s', t') have at least one edge and thus at least two vertices in common. Hence, every edge of the conflict graph is contained in at least one of the X
v
's. Thus, all conditions of a tree decomposition are fulfilled. Moreover, the width of this tree decomposition is clearly m
v
- 1. The conflict graph, the sets P
v
, and the tree decomposition can be computed in O(n4) time. Thus, the overall running time follows by the fact that WEIGHTED VERTEX COVER can be solved in O(2tw |P|) time, given a tree decomposition of width tw of G
c
[15].
Cross Pairs
In Theorem 1, we have shown that W-MTO is fixed-parameter tractable with respect to the parameter m
v
. In the following, we will strengthen this result by showing that W-MTO is fixed-parameter tractable with respect to the parameter "number of a special type of source–target pairs (the so-called cross pairs) passing through a vertex". The idea is to identify a "trivial" (that is, polynomial-time solvable) special case of the problem and then to investigate instances that are close to these trivial instances, their closeness measured in terms of a certain parameter which is referred to as distance from triviality[19, 20].
In the following, we will always consider rooted trees. Informally speaking, a cross-pair-free instance only contains source–target pairs whose corresponding paths are directed either towards the root or towards the leaves, but do not change their direction. Cross-pair-free instances of W-MTO are of special interest since they constitute our "trivial instances".
Definition 1. Let (T = (V, E), P, ω) be an instance of W-MTO where T is a rooted tree. A source–target pair p = [a, b] ∈ P is called cross pair if neither a is an ancestor of b nor b an ancestor of a. An instance of W-MTO is called cross-pair-free if T can be rooted such that P does not contain any cross pairs.
Cross-pair-free Instances
Now, we devise a dynamic-programming-based algorithm solving W-MTO in quadratic time on cross-pair-free instances.
Theorem 2. On n-vertex trees, WEIGHTED MAXIMUM TREE ORIENTATION for cross-pair-free instances with given root can be solved in O(n2) time.
Proof. Algorithm. We present a dynamic programming algorithm with quadratic running time solving a cross-pair-free W-MTO instance (T = (V, E), P, ω) with root r. For the presentation of the algorithm, we use the following notation. For v ∈ V, let T
v
be the subtree of T rooted at v. For all v, w ∈ V with v ≺ w (that is, v is an ancestor of w) let denote the subtree of T induced by .
For ease of presentation, let . Moreover, let . That is, is the tree consisting of the path path
T
(v, w) and the subtree T
w
rooted at w, and are the pairs with both endpoints in . Finally, the weight of an orientation of is the sum of the weights of the pairs in satisfied by .
The algorithm maintains an n × n dynamic programming table S, containing for each v, w ∈ V with v ≺ w or v = w the two entries S(v, w) and S(w, v). The goal of the dynamic programming procedure is to fill S in accordance with the following definition.
For all v, w ∈ V with v ≺ w, entry S(v, w) is the maximum weight of an orientation of among all orientations of orienting the path between v and w from v to w (that is, away from the root). Analogously, S(w, v) is the maximum weight of an orientation of among all orientations of orienting the path between v and w from w to v (that is, towards the root). Note that in the case v = w we have that S(v, v) is the weight of an optimal orientation of the subtree rooted at v.
Next, we describe how our algorithm computes the entries of S in accordance with this definition. The weight of an optimal orientation of (T, P) can then be found in S(r, r).
To compute the entries of S, visit all vertices w ∈ V in a bottom-up traversal. Then, for each w consider all vertices v ∈ V with v = w or v ≺ w and set (omit the sum if w is a leaf):
(1)
(2)
Herein, A(v, w) denotes the sum of the weights of the source–target pairs with both endpoints on path
T
(v, w) that are satisfied when orienting the path between v and w from v to w, that is,
(3)
Analogously, A(v, w):= ω ({[s, t ∈ P | s, t ∈ V (path
T
(v, w)) ∧ t ≺ s}). Moreover, for ease of presentation we assume that A(v, v) = 0.
Correctness. For the correctness of the algorithm note the following. For a leaf w and an ancestor v of w, the tree is identical to the path path
T
(v, w). Hence, the sum of the weights of pairs that can be satisfied by orienting the path either from v to w or from w to v is A(v, w) and A(w, v), respectively. Next, consider the case that w is an inner vertex and let v be an ancestor of w. Moreover, let u1,…, u
ℓ
denote the children of w. We argue that the maximum weight of an orientation of orienting the edges on path
T
(v, w) towards w equals
(4)
and, hence, S(v, w) is computed correctly. To this end, consider a maximum-weight orientation of orienting the edges on path
T
(v, w) towards w. If, for a child u
i
, contains the arc (u
i
, w), then the contribution of the source–target pairs in with at least one endpoint in to the weight of is S(u
i
, w); note that no source–target pair of with exactly one endpoint in is satisfied by , and thus the contribution of these pairs is S (u
i
, w) (a smaller contribution would contradict the optimality of ). Moreover, if for a child u
i
the oriented tree contains the arc (w, u
i
), then it follows by a similar argument that the contribution of the paths in with at least one endpoint in is S(v, u
i
) - A(v, w). The only difference is that the contribution of the source–target pairs with both endpoints in V (path
T
(v, w)) is already considered in the above formula, and, hence, must be subtracted from S(v, u
i
).
Running time. For the running time bound, we show that A can be computed in O(n2) time in a preprocessing step. Then, the overall running time is clearly bounded by
(5)
since ∑
w∈V
deg
T
(w) = 2(n - 1) in trees. Clearly for v, w ∈ V with v ≺ w the matrix entries A(v, w) and A(w, v) can be computed by setting
(6)
and
(7)
where x is the neighbor of v and y is the neighbor of w on path
T
(v, w). This assumes, however, that all the entries of A for pairs with distance l - 1 are known before computing the entries of the pairs with distance l. This can be ensured by using a queue (first-in-first-out data structure) as follows. For the computation of A, first, for all edges {v, w} ∈ E with v ≺ w set A(v, w):= ω([v, w]) and A(w, v):= ω([w, v]) (let ω([s, t]):= 0 if [s, t] ∉ P) and append the pair (v, w) at the tail of the queue. After each edge has been processed, proceed as follows. Until the queue is empty, let (x, w) denote the next element at the head of the queue and let v denote the parent of x and let y denote the parent of w in T (if x = r remove (x, w) from the head position of the queue and do nothing else). It is easy to verify that the entries for the pairs (x, w) and (v, y) have already been computed and, hence, can be used to compute A(v, w) and A(w, v) as described above. Finally, we remove (x, w) from the head position of the queue and append (v, w) at the tail of the queue. Clearly, for every pair v, w of vertices with v ≺ w, we need a constant number of operations to compute the two table entries A(v, w) and A(w, v), resulting in an overall running time bound of O(n2). □
Note that if the root of a cross-pair-free W-MTO instance is not known, it can be calculated in O(n|P|) time by trying all roots and then checking for each pair if the least common ancestor is one of the two endpoints.
As an immediate consequence of Theorem 2, we can improve the cubic-time algorithm for MTO on paths by Medvedovsky et al. [3] to quadratic time. Herein, we use that every path rooted at one of its endpoints results in a cross-pair-free instance of MTO.