Parameterized and approximation complexity of the detection pair problem in graphs

We study the complexity of the problem DETECTION PAIR. A detection pair of a graph $G$ is a pair $(W,L)$ of sets of detectors with $W\subseteq V(G)$, the watchers, and $L\subseteq V(G)$, the listeners, such that for every pair $u,v$ of vertices that are not dominated by a watcher of $W$, there is a listener of $L$ whose distances to $u$ and to $v$ are different. The goal is to minimize $|W|+|L|$. This problem generalizes the two classic problems DOMINATING SET and METRIC DIMENSION, that correspond to the restrictions $L=\emptyset$ and $W=\emptyset$, respectively. DETECTION PAIR was recently introduced by Finbow, Hartnell and Young [A. S. Finbow, B. L. Hartnell and J. R. Young. The complexity of monitoring a network with both watchers and listeners. Manuscript, 2015], who proved it to be NP-complete on trees, a surprising result given that both DOMINATING SET and METRIC DIMENSION are known to be linear-time solvable on trees. It follows from an existing reduction by Hartung and Nichterlein for METRIC DIMENSION that even on bipartite subcubic graphs of arbitrarily large girth, DETECTION PAIR is NP-hard to approximate within a sub-logarithmic factor and W[2]-hard (when parameterized by solution size). We show, using a reduction to SET COVER, that DETECTION PAIR is approximable within a factor logarithmic in the number of vertices of the input graph. Our two main results are a linear-time $2$-approximation algorithm and an FPT algorithm for DETECTION PAIR on trees.


Introduction
In order to monitor faults in a network, one can place detectors on its nodes. One possibility is to use "local" devices that are able to detect the location of a fault within distance one (we call them watchers). Another kind of detectors, that are more far-reaching, are able to determine the exact distance of a fault to the device, but not its precise location (we call such detectors listeners). If we wish to monitor a network by using only watchers, we have the classic problem Dominating Set [14,GT2] (see the books [19,20] for a survey of results on this problem). If, on the other hand, we want to use only listeners, we have the problem Metric Dimension [14,GT61] (see for example the papers [2,4,15,17,22,24] and references therein). However, it can be useful to use both kinds of detectors: for example, one watcher is enough to monitor a complete graph of order n, while we would need n − 1 listeners to do so. On the other hand, one listener would suffice to monitor a path of order n, but for the same task we would need ⌈n/3⌉ watchers. Therefore, Finbow, Hartnell and Young [12] recently proposed the concept of a detection pair in a graph G, that is, a pair (W, L) where W ⊆ V (G) is a set of watchers and L ⊆ V (G) is a set of listeners that, together, monitor the graph G.
More formally, we say that a vertex w dominates all the vertices in the closed neighbourhood N [w] of w (that is, N [w] is the set of neighbours of w together with w itself). Moreover, a vertex l separates two vertices u and v if the distance d(u, l) is different from the distance d(v, l). Given a pair (W, L) of sets with W ⊆ V (G) (the watchers) and L ⊆ V (G) (the listeners), we say that a vertex u is distinguished by (W, L) either if u is dominated by a watcher of W , or if for every other vertex v, either v is dominated by a watcher of W , or u and v are separated by a listener of L. Then, (W, L) is a detection pair of G if every vertex of G is distinguished by (W, L). The size of (W, L) is the sum |W | + |L| and is denoted by ||(W, L)||. Note that we may have W ∩ L = ∅ if we choose to place both a listener and a watcher at the same position. We denote by DP (G) the minimum size of a detection pair of G. Any vertex of (W, L) is called a detector.
If we have a detection pair (∅, L) in a graph G, then L is called a resolving set of G, and the smallest size of a resolving set of G is called its metric dimension, denoted M D(G). On the other hand, if we have a detection pair (W, ∅), then W is a dominating set of G, and the smallest size of a dominating set of G is its domination number, denoted γ(G). Clearly, we have DP (G) ≤ min{γ(G), M D(G)}, and the inequality can be strict [12]. It follows that for any graph G without isolated vertices, we have DP (G) ≤ γ(G) ≤ |V (G)|/2 [19].
The goal of this paper is to study the decision and optimization problems that are naturally associated to the notion of a detection pair (other computational problems that are mentioned in this paper are defined formally in Section 2).

Detection Pair
Instance: A graph G, a positive integer k. Question: Is there a detection pair (W, L) of G with ||(W, L)|| ≤ k?

Opt-Detection Pair
Instance: A graph G. Task: Compute an optimal detection pair of G.
A c-approximation algorithm for a given optimization problem Π O is an algorithm that returns a solution whose size is always at most c times the optimum. We refer to the book [1] for more details. For a decision problem Π and for some parameter p of the instance, an algorithm for Π is said to be fixed parameter tractable (FPT for short) if it runs in time f (p)n c , where f is a computable function, n is the input size, and c is a constant. In this paper we will always consider the solution size k as the parameter. We refer to the books [8,23] for more details.
Finbow, Hartnell and Young proved that Detection Pair is NP-complete on trees [12], while Opt-Detection Pair is linear-time solvable on trees containing no pair of leaves with a common neighbour. This hardness result is quite surprising since the related problems Opt-Dominating Set and Opt-Metric Dimension, while being NP-hard in general [14,GT2,GT61], can be solved in linear time on trees (see respectively [5] and [15,24]). We note that Dominating Set is among the most classic and well-studied graph problems (see the books [19,20]), and that Metric Dimension has enjoyed a lot of interest in the recent years: see the papers [3,6,9,10,11,13,17,18].
In this paper, we continue the study of the complexity of Detection Pair and Opt-Detection Pair initiated in [12]. In Section 3, we describe a reduction to Opt-Set Cover that shows that Opt-Detection Pair can be solved within a factor logarithmic in the size of the input graph. On the other hand, we observe that a reduction of Hartung and Nichterlein [16,17] for Opt-Metric Dimension can also be applied to Opt-Detection Pair. This implies that Opt-Detection Pair is NP-hard to approximate within a factor that is sublogarithmic in the input graph's order, and that Detection Pair is W[2]-hard when parameterized by the solution size k. (These hardness results hold even for graphs that are bipartite, subcubic, and have arbitrarily large girth.) In Section 4, we prove that Opt-Detection Pair is 2-approximable in linear time on trees. In Section 5, we show that there is an algorithm for Detection Pair running in FPT time 2 O(k log k) n 2 on trees. 1 We start the paper with some preliminary considerations in Section 2, and conclude in Section 6.

Preliminaries
We start with some preliminary considerations.

Definitions of used computational problems
We now formally define a few auxiliary computational problems that are used or mentioned in this paper.
Dominating Set [14,GT2] Instance: A graph G, a positive integer k. Question: Do we have γ(G) ≤ k, that is, is there a dominating set D of G with |D| ≤ k?
Opt-Dominating Set Instance: A graph G. Task: Compute an optimal dominating set of G.
Metric Dimension [14,GT61] Instance: A graph G, a positive integer k. Question: Do we have M D(G) ≤ k, that is, is there a resolving set R of G with |R| ≤ k?

Opt-Metric Dimension
Instance: A graph G. Task: Compute an optimal resolving set of G.
Set Cover [14,SP5] Instance: A hypergraph H = (X, S), a positive integer k. Question: Is there a set cover C of H with |C| ≤ k (that is, C ⊆ S and each vertex of X belongs to some set of C)?
Opt-Set Cover Instance: A hypergraph H. Task: Compute an optimal set cover of H.

Specific terminology
In a graph G, a vertex of degree 1 is called a leaf. A vertex is called a branching point if its degree is at least 3. A branching point v is special if there is a path L starting at v and ending at a vertex of degree 1, and whose inner-vertices all have degree 2. Path L − v is called a leg of v, and we say that L is attached to v (note that vertex v does not belong to the leg). A special branching point with t leaves as neighbours is called a t-stem. 2 Given a special branching point x of a tree T , we define the subtree L(x) of T as the tree containing x and all legs of T attached to x.

The classic algorithm for Opt-Metric Dimension on trees
We will use the following results of Slater [24] about Opt-Metric Dimension on trees, that are classic in the literature about metric dimension. See also [15,22] for similar considerations.
Proposition 1 (Slater [24]). Let T be a tree and R be the set of vertices containing, for each special branching point x of T that has ℓ legs attached, the leaves of the ℓ − 1 longest of these legs. Then, R is an optimal resolving set of T .
We have the following consequence of Proposition 1.
Theorem 2 (Slater [24]). Opt-Metric Dimension can be solved optimally in linear time on trees.

Observations and lemmas about detection pairs
The following easy observations and lemmas will be useful.
Observation 3. Let G be a graph and B 2 + the set of its special branching points with at least two legs attached. Then, we have DP (G) ≥ |B 2 + |.
Proof. Let (W, L) be a detection pair of G. We show that for each special branching point x of B 2 + , there is at least one detector of (W, L) among x and the vertices belonging to a leg attached to x. Indeed, if not, then any two neighbours of x belonging to this set would neither be dominated by a watcher, nor separated by a listener, a contradiction. Proof. If there is a watcher at x, assume for a contradiction that two legs L 1 and L 2 of L x contain no detector. Then, neither the listeners of (W, L) nor the watcher at x can distinguish the two vertices of L 1 and L 2 that are at distance 2 from x, a contradiction. A similar argument holds for vertices at distance 1 of x when x has no watcher.
Lemma 5. Let G be a graph with a special branching point x having a leg attached, whose leaf is y. If G has a detection pair (W, L) with x ∈ L, then (W, L \ {x} ∪ {y}) is also a detection pair of G.
Proof. Let V x be the set of vertices containing x and the vertices of the leg attached to x whose leaf is y. Clearly, a pair u, v of vertices in V (G) \ V x are separated by x if and only if they are separated by y. Moreover, all the vertices in the leg containing y are clearly distinguished, because each such vertex is the unique one with its distance to y. This completes the proof.

General approximability and non-approximability
In this section, we discuss the general approximation complexity of Opt-Detection Pair.
Theorem 6. Opt-Detection Pair can be approximated within a factor 2 log n + 1 on graphs of order n.
Proof. Given a graph G, we build an instance (X, S) of Opt-Set Cover as follows. We let X be the set of vertex pairs of G. For each vertex v of G, we have a set W v of S that contains an element {x, y} of X if v dominates at least one of x and y. We also have a set L v that contains an element {x, y} of X if we have d(v, x) = d(v, y). Therefore we have |X| = |V (G)| 2 and |S| = 2|V (G)|. Now, we claim that we have a one-to-one correspondance between the detection pairs of G and the set covers of (X, S). Indeed, for every vertex v of G, the set W v of S corresponds to a watcher placed at vertex v, and the set L v corresponds to a listener placed at vertex v. Moreover set U v of S (with U ∈ {W, L}) covers exactly the elements of X that correspond to a pair that is separated by the according detector placed on v in G. Since Opt-Set Cover is approximable within a factor of log(|X|) + 1 in polynomial time [21], the result follows.
Hartung and Nichterlein [17] provided a reduction from Dominating Set to Metric Dimension. This reduction was improved by Hartung in his PhD thesis [16] to get a reduction mapping any instance (G, k) to an instance (G ′ , k + 4), where G ′ is a bipartite graph of maximum degree 3 and has girth 4|V (G)| + 6. In fact, it is not difficult to see that for any detection pair P of G ′ of size k ′ , there is a detection pair P ′ of G ′ of size at most k ′ containing no watchers. In other words, we have DP (G ′ ) = M D(G ′ ), and therefore the aforementioned reduction is also a reduction to Detection Pair. Hence we have the following. 3 Theorem 7 (Hartung and Nichterlein [16,17]). Opt-Detection Pair is NP-hard to approximate within a factor of (1 − ǫ) log n (for any ǫ > 0) for instances of order n, and Detection Pair is W [2]-hard (parameterized by the solution size k). Let g ≥ 4 be an arbitrary integer. These results hold even for instances that are bipartite, have maximum degree 3, and girth at least g.

A 2-approximation algorithm on trees
In this section, we prove the following approximability result.
Theorem 8. There is a linear-time 2-approximation algorithm for Opt-Detection Pair on trees.
Proof. Given an input tree T , we denote by S 3 + , the set of vertices of T that are t-stems for some t ≥ 3. Moreover, we define T ′ as the tree obtained from T as follows. For each vertex v of S 3 + (that is, v is a t-stem for some t ≥ 3), assuming that there are ℓ legs of length at least 2 attached to v in T , we remove from T : Let us describe our algorithm A.
1. Compute the set S 3 + and build T ′ from T .

Compute an optimal resolving set
We first prove that A(T ) is a detection pair of T . Notice that the distances from listeners in R ′ and vertices of V (T ′ ) are the same in T and T ′ . Therefore, all pairs of vertices of V (T ′ ) are distinguished in T by the listeners of A(T ). On the other hand, all vertices of V (T ) − V (T ′ ) are dominated by the watchers of S 3 + . Therefore, A(T ) is a detection pair of T .
Moreover, it is clear that S 3 + and T ′ can be computed in linear time, and R ′ can be computed in linear time using Slater's algorithm (Theorem 2). Therefore A is a linear-time algorithm.
It remains to prove that ||A(T )|| = |S 3 + | + M D(T ′ ) ≤ 2 · DP (T ) for any tree T . Notice that A(T ) contains only vertices that are part of some subtree L(x), where x is a special branching point of T ; indeed, any vertex of S 3 + is a special branching point of T , and any special branching point of T ′ is also a special branching point of T (by Proposition 1, any optimal resolving set of T ′ only contains vertices that belong to some subtree L(x) of T ′ ). Therefore, it suffices to prove that for any detection pair D = (W, L) of T , for any optimal resolving set R ′ of T ′ and for every special branching point x of T , we have To this end, let us assume that x is a t-stem for some t ≥ 0, and that there are ℓ legs of length at least 2 attached to x. We distinguish the following cases.
Case 1: ℓ ≤ 1. Then, L(x) contains at most two detectors of A(T ). Indeed, if t ≤ 2, it contains one or two listeners; if t ≥ 3, it contains one watcher and one listener. By Lemma 4, there is at least one detector in L(x), which completes the proof of this case.
Case 2: ℓ ≥ 2. Then, by Lemma 4, any detection pair (W, L) of T has a detector in at least ℓ − 1 legs of length at least 2 of L(x). If t ≥ 3 (that is, x ∈ S 3 + ), A(T ) has exactly ℓ − 1 listeners and one watcher in L(x). Therefore, for any detection pair (W, L) of T , we have Hence, assume that t ≤ 2. Then, L(x) contains only listeners of A(T ), that is, precisely t + ℓ − 1 leaves of L(x) that belong to R ′ . If t ≤ 1, we have ℓ−1 ≥ t and then, for any detection pair (W, L) of )|, and we are done. If however, t = 2, by Lemma 4, there are at least ℓ detectors of (W, L) in L(x). Hence, This completes the proof.
There are two infinite families of trees that show that our algorithm has no better approximation ratio than 2.
The first family consists of trees T 1 ℓ (ℓ ≥ 1) that are built from ℓ disjoint stars with at least three leaves each, all whose centers are adjacent to an additional single vertex. We have ||A(T 1 ℓ )|| = 2ℓ (this solution set contains one watcher and one listener for every star), while DP (T 1 ℓ ) ≤ ℓ (simply let every center of a star be a watcher, and select no listener). Hence the approximation ratio of A on T 1 ℓ is 2. A second family consists of trees T 2 ℓ (ℓ ≥ 1) built from a path P of ℓ+2 vertices. For each of the two end-vertices of P , add two leaves that are adjacent to this end-vertex. For each degree 2-vertex v of P , build a star S v with three leaves and subdivide one of its edges once. Moreover, the center of S v is made adjacent to v. We have ||A(T 2 ℓ )|| = 2ℓ + 2 (each star contains two listeners, and two additional listeners are selected among the four degree 1-vertices adjacent to end-vertices of P ), while DP (T 2 ℓ ) ≤ ℓ + 2 (put a watcher on each center of a star, and add one neighbour of each endpoint of P as a listener). The approximation ratio of A on T 2 ℓ is 2 − 2 ℓ+2 .

A fixed parameter tractable algorithm on trees
In this section, we provide an exact algorithm for Detection Pair that is FPT for the natural parameter k, the solution size. The idea of the algorithm is as follows. We first search for a solution with |L| ≤ 1. After this step, we may assume that |L| ≥ 2, which is a technical condition required for the subsequent steps of the algorithm. Then we proceed in three phases. In the first phase, we handle the solution around the special branching points of the tree. As we will see, there is only a fixed set of possibilities to try for each such branching point. Then, in the second phase, we determine the set of remaining listeners. Here, we are able to compute a set (whose size is bounded in terms of k) of possible vertices that may contain a listener in an optimal solution. Finally, in the third phase, we determine the set of remaining watchers, and again we are able to compute a set of vertices (whose size is bounded in terms of k) that may be used as a watcher. The algorithm then checks the validity of each possible choice of these placements.

Preliminary lemmas
Before describing the algorithm, we prove a series of lemmas that will be essential.
The first lemma is useful to handle special branching points of the tree, by reducing the problem around these vertices to a fixed number of cases.  Proof. Clearly, if there are any watchers among {x} ∪ S x , we may replace them by a single watcher at x and obtain a valid detection pair. We now distinguish two cases.
Case 1: ℓ ≤ 1. Then, we have t ≥ 1. If V x contained a unique detector of (W, L) that is a watcher, then it must have dominated a leaf neighbour of x (since t ≥ 1, such a neighbour exists).
Then as observed at the beginning of the proof, we may replace this detector by a watcher at x, and we are in Case 1(a). If V x had a unique detector of (W, L) that is a listener, then by Lemma 4 we must have had t + ℓ = 1. Note that any listener in V x seperates the same set of pairs of vertices from V (G) \ V x . Hence we may replace the existing listener by a listener at the leaf of a longest leg attached to x, which separates at least as many vertices as any other listener in V x . Then we are in Case 1(c) and we are done. Hence, we assume that V x contained at least two detectors of (W, L). Then, using similar arguments one can check that the solution of Case 1(b) yields a valid detection pair of G that is not larger than (W, L).
Case 2: ℓ ≥ 2. As observed before, we can replace all watchers in {x} ∪ S x by a single watcher at x. If x has a watcher, we let L + x = L x ; otherwise, we let L + x be the set of all legs attached to x. Let ℓ + = |L + x |. By Lemma 4, at least ℓ + − 1 ≥ 1 of the legs in L + x contain a detector of (W, L). Assume first that (W, L) contained at least ℓ + detectors of (W, L) on the legs of L + x . Then, we replace all such detectors by a listener at the leaf of each leg of L + x . Then, any vertex of a leg L i of L + x is distinguished by its distance to the listener placed at the leaf of L i . Since any listener in V x separates the same set of pairs in V (G) \ V x , we have obtained a valid detection pair that is not larger than (W, L) and we are in Case 2(a) or 2(c). Suppose now that there are exactly ℓ + − 1 detectors of (W, L) on the legs of L + x . We replace these detectors by a listener at the leaf of each of the ℓ + −1 longest legs of L + x . By similar arguments as above, all vertices in V x that do not belong to the unique leg L 1 of L + x without a detector are distinguished. Again, any listener in V x separates the same set of pairs of V (G) \ V x . Hence, if some vertex is not distinguished by the new detection pair, it must be a vertex u of L 1 that is not separated from a vertex v of V (G) \ V x . This implies that d(u, x) = d(v, x) (otherwise u and v would be separated by any of the listeners placed in V x ). We know that u and v were separated by some detector of (W, L), which must have been a detector in the leg L 1 (no detector in another leg of L + x could possibly separate u and v since d(u, x) = d(v, x)). But we know that there was one leg L 2 of L + x that contained no detector of (W, L). Since L 1 is a shortest leg of L + x , there is a vertex u ′ in L 2 with d(x, u) = d(x, u ′ ). But then, u ′ and v were not distinguished by (W, L), a contradiction. Hence we have a valid detection pair whose size is not greater than ||(W, L)|| and we are in Case 2(b) or 2(d), and we are done.
The next two lemmas are used in our algorithm to choose the placement of the listeners.  u and v).
. Note that if for two vertices x and y, δ u,v (x) = δ u,v (y), then x and y are separated by u and v.
Clearly, u and v are distinguished. Let w be a vertex of V (P + ) \ {u, v}, and assume for a contradiction that there is some vertex z with d(u, w) = d(u, z) and d(v, w) = d(v, z). In particular, δ u,v (w) = δ u,v (z).
Note that for every two vertices p, q of P , we have δ u,v (p) = δ u,v (q), therefore at most one of the vertices w and z can belong to P . We assume w.l.o.g. that z does not belong to P .
The shortest paths from z to both u and v must go through an inner-vertex of P , say s. Then, we have δ u,v (z) = δ u,v (s) = δ u,v (w), which implies that all shortest paths from w to u and v also go through s. But then, we have d(w, s) = d(z, s), a contradiction because by the structure of V (P + ) this implies that w = z. Lemma 12. Let G be a graph with two vertices u and v connected by a unique path P , such that each inner-vertex of P has either degree 2 or a single leg attached. Moreover let V (P + ) be the set of inner-vertices of P together with the vertices of each leg attached to an inner-vertex of degree 3 of P . Then, for every detection pair (W, L) of G, one can obtain a valid detection pair of G by replacing all detectors of (W ∪ L) ∩ V (P + ) by two listeners at u and v.
Proof. By Lemma 11, all vertices in V (P + ) are distinguished by u and v. Note that no watcher of V (P + ) could possibly distinguish any vertex outside of V (P + ) ∪ {u, v} (and u, v are clearly distinguished). Furthermore, since P is the unique path connecting u and v, for any listener l ∈ L in V (P + ), the set of pairs in V (G) \ V (P + ) separated by l is the same as the set of pairs separated by u (and by v). This completes the proof.
The next lemma will be used in the algorithm to determine the placement of watchers in parts of the tree where there is no listener.
Lemma 13. Let T be a tree with a vertex x and an optimal detection pair (W, L) of T with |L| ≥ 1.
Let T x be a subtree of T containing x and assume that (i) T x contains no t-stems for any t ≥ 2, (ii) for each listener l of L and each vertex v of T x , the shortest path from l to v goes through x (in particular T x − x contains no listener) and (iii) T x is maximal with respect to (i) and (ii). Then, there is a set X of size at most 63|W Proof. We may view T x as a rooted tree whose root is x. Consider the partition P of V (T x ) into parts P 0 , P 1 , . . . , P d where P i contains the vertices of V (T x ) that have distance i to x. Since |L| ≥ 1 and by (ii) all shortest paths from any listener of L to a vertex of T x go through x, the set L of listeners separates a pair u, v of V (T x ) if and only if u and v belong to different parts of P. Therefore, since (W, L) is a detection pair of G, for any two distinct vertices u and v from the same part P i , at least one of u, v is dominated by a watcher of W .
Let S 2 + be the set of parts of P of size at least 2 (that is, those parts where at least one vertex must be dominated by a watcher). Let F x be the forest induced by the set of vertices of T x that belong to some part of S 2 + , together with their neighbours in T x . We let X = V ( F x ), and we shall prove that X satisfies the claim. First, we show that (W ∩ V (T x )) ⊆ X. Assume by contradiction that this is not the case, and let w be a watcher of W that belongs to V (T x ) \ X. By the optimality of (W, L), (W \ {w}, L) is not a detection pair of T . Therefore, there must be some vertex u dominated by w that is not separated by L from some other vertex v (and v is not dominated by a watcher of W \ {w}). In other words, for every listener l ∈ L, we have d T (u, l) = d T (v, l). Thus, since T is a tree, all shortest paths from l to both u and v have a common part (say from l until some vertex y) and then are disjoint. By (iii), T x is maximal with respect to (i) and (ii), which implies that y = x and both u and v belong to T x . However, observe that u belongs to a part of S 2 + (otherwise w would belong to X). Therefore, u is uniquely determined (within T x ) by its distance to x. Since |L| ≥ 1 and by (ii), this implies that u and v are in fact distinguished by L, a contradiction.
Thus, we have shown that W ∩ V (T x ) ⊆ X. It is moreover clear that X can be computed in time linear in |V (T x )| by using the distances of the vertices of T x to x. Therefore, it remains only to bound the size of X.
First, we show that F x contains vertices of at most 9|W | distinct parts of P. To each part P i of S 2 + , we can associate the two parts P i−1 and P i+1 , that may have vertices in F x but that may not be in S 2 + . Hence, the total number of parts with a vertex in F x is at most 3|S 2 + |. Since a watcher may dominate vertices from at most three parts of S 2 + and each part in S 2 + has at least one vertex dominated by a watcher, we have |S 2 + | ≤ 3|W |, hence F x contains vertices of at most 9|W | distinct parts of P.
Second, we prove that F x has at most |W | + 2|S 2 + | ≤ 7|W | leaves. Note that a leaf of F x is either an actual leaf in T , or it is a vertex of a part P i with |P i | = 1 (or both). We claim that F x can contain at most |W | leaves of T belonging to a part of S 2 + . Indeed, each such leaf must be dominated by a watcher, but it can be dominated only by itself or by its parent in T x . But since by (i) there are no t-stems for t ≥ 2 in T x , no parent can dominate more than one leaf, which proves the bound. Furthermore, F x contains vertices from at most 2|S 2 + | parts of P of size 1, hence the number of leaves of F x that are not in a part of |S 2 + | is at most 2|S 2 + | ≤ 6|W | since |S 2 + | ≤ 3|W |. Hence in total, we have at most 7|W | leaves in F x .
But any rooted forest with at most 9|W | levels and with at most 7|W | leaves may have at most 63|W | 2 vertices, hence X = V ( F x ) has size at most 63|W | 2 . This completes the proof.

The algorithm (proof of Theorem 9)
We now describe the claimed FPT algorithm for Detection Pair on trees and prove its correctness and running time.
Proof of Theorem 9. Let us describe the algorithm, that seeks to build a detection pair (W, L) with at most k detectors of an input tree T of order n.
Preliminary phase: Searching for a solution with |L| ≤ 1. A first step of the algorithm is to check whether there is a solution with |L| ≤ 1. If we set L = ∅, the problem is equivalent to finding a dominating set of T of size at most k. This can be done in linear time [5]. If we set |L| = 1, one may try the n possibilities for the placement of the unique listener. For each possibility (say we have placed the listener at vertex v), we create a subtree T v of T rooted at v as follows. First of all, let T v = T . Then, for each t-stem x of T with t ≥ 2 (except if v is a leaf attached to x and x is a 2-stem), we may assume that x belongs to W (by a similar argument as in the proof of Lemma 10, Cases 1a and 2a.). Thus, we add x to W and we we remove from T v all leaves but one that are attached to x (if v is one such leaf, we keep v in T v ). Now T v has no t-stems for t ≥ 2 and we can apply Lemma 13. Thus, there is a set X of at most 63k 2 vertices that may contain a watcher (X is computable in linear time). Then, it suffices to try all the possibilities of selecting k − |W | − 1 additional watchers from this set. There are at most 63k 2 k ∈ O 2 O(k log k) such possibilities. For each of them, we check in linear time whether we have a valid detection pair. In total this phase takes 2 O(k log k) n 2 time. If we find a valid solution in this phase, we return YES.
Next, we assume that |L| ≥ 2 and proceed in three phases.
Phase 1: Handling the special branching points. We now do a preprocessing step using Lemma 10. First compute (in linear time) the set of special branching points of T , and let B 2 + be the set of those special branching points that have at least two legs attached. Note that by Observation 3, if |B 2 + | > k we can return NO. Hence, assume that |B 2 + | ≤ k. Now, for each special branching point x of B 2 + , by Lemma 10 we can assume that there are at most four different choices for the set of detectors on x and the vertices belonging to a leg attached to x. Therefore, we may go through each of the possible combinations of these choices; there are at most 4 k of them. Of course we discard the choices for which there are more than k detectors. For a combination C i , Let (W i , L i ) be the partial detection pair corresponding to C i . In the remainder, we show how to decide whether there is a detection pair (W, L) of T with W i ⊆ W , L i ⊆ L and ||(W, L)|| ≤ k.  Proof of claim. We prove that each tree of F must contain a detector of (W, L). Assume for contradiction that there is a tree T xa of F such that no detector of (W, L) belongs to T xa . By definition, T xa contains a vertex w not distinguished by (W i , L i ), hence there is a vertex w ′ of T − T * i (say, w ′ ∈ T x b ) not separated by any listener of L i and none of w, w ′ is dominated by a watcher of W i . Then, w ′ must belong to T xa (hence a = b), indeed by definition of T * i there are two listeners u and v of L i whose path contains x a and x b . But then, if a = b, clearly u and v would separate w and w ′ , a contradiction. But since w and w ′ both belong to T xa , no listener outside of T xa can separate them, and clearly no watcher outside of T xa can dominate them, which proves the claim.
By Claim 9.A, if we have |F | > k, we can discard the combination C i ; hence, we assume that |F | ≤ k. Now, from each tree T xj of F , we build the subtree T xj of T xj as follows: (i) remove all legs in T xj whose closest special branching point has only one leg attached; (ii) remove each leaf of T xj that is adjacent to a watcher of W i . We also denote by F the forest containing each tree T xa with T xa ∈ F . We next claim the following.
Claim 9.B. If there is a detection pair (W, L) of T with W i ⊆ W , L i ⊆ L and k a detectors on T xa , then T xa has at most 2k a leaves.
Proof of claim. Let us consider the legs of T xa containing no detector of (W i , L i ). By (i) of the construction of T xa , such a leg must be attached to a special branching point having at least two legs attached. (Note that operation (i) did not create any new special branching point.) Moreover, by (ii), if this leg has length 1 in T xa , its unique vertex will not be dominated by a watcher, since the set of detectors on this leg and its special branching point are determined by the combination C i . Note that in (ii), if we create a new leg, this leg contains a detector (a watcher).
Let v be a special branching point of T xa and let L v be the set of legs in T xa attached to v that do not contain any detector of (W i , L i ). By the previous discussion, we have |L v | ≥ 2. If some leg of L v has length 1, as we observed there will be no watcher on v. Hence, in order to separate all the neighbours of v on the legs of L v , we need a detector in at least |L v | − 1 ≥ |L v |/2 of these legs. Otherwise, we still need that many detectors in order to separate all the vertices at distance 2 of v on the legs of L v . Hence, at most half of the leaves of T xa belong to a leg with no detector, which proves the claim.
By Claim 9.B, T xj has at most 2k j leaves (where k j is the set of detectors placed on T xj ). Therefore, if the total number of leaves in the forest F is more than 2k, we can discard the current combination C i . Hence, we can assume that the total number of leaves in F is at most 2k.
Therefore, the total number of vertices of degree at least 3 in F is at most 2k. Let us consider the sets of maximal threads in F (that is, paths with inner-vertices of degree 2). The endpoints of such threads are vertices of degree 1 or at least 3 in F , and therefore the number of such threads is at most the number of these vertices, which is upper-bounded by 4k.
Each such thread P uv between two vertices u and v of a tree T xj of F, corresponds (in T xj ) to a path whose inner-vertices either have a single leg attached, or contain a watcher of W i with a set of leaves attached. Hence, we may assume that P uv contains at most two listeners: if it contained more than two, by Lemma 12, we could replace them with the two endpoints u and v of P uv . Moreover, if P uv contained exactly one listener, similarly we may assume it is placed on one of the endpoints of P uv . Indeed, since |L| ≥ 2, there will be another listener in the solution set. If this listener is closer to u, similarly as in Lemma 11, a listener on v would distinguish all vertices on V (P + uv ) (where V (P + uv ) contains all vertices of P uv and the vertices of legs attached to inner-vertices of P uv ). Moreover, the set of pairs of vertices outside of V (P + uv ) separated by u and by v are the same. Note that by Lemma 5, if we choose to place a listener on an endpoint u of a path P uv that is a thread in T xj and this endpoint has a leg attached, instead of placing the listener on u we can instead place the listener on the leaf of this leg.
Therefore, for each thread P uv of T xa , there are four possibilities for the placement of the listeners: a listener on both u and v (or the leaf of a corresponding leg attached to u or v); a single listener at u; a single listener at v; no listener. There are therefore at most 4 4k possibilities to guess the placement of listeners on tree T xa . For each such placement P j , we obtain a set L j of listeners (of course, if ||(W, L i ∪ L j )|| > k we do not consider this placement). Now, we can assume that L = L i ∪ L j , that is, that there will be no more listeners in the sought solution (W, L). Hence, it remains to check whether we can obtain a valid solution of size k by only adding watchers.
Phase 3: Determining the set of watchers. We compute a tree T * i,j similarly as T * i but using the new set L i ∪ L j of listeners. Similarly as before, we define the set X ′ of vertices of T * i,j having a neighbour in T − T * i,j , and the set of trees T ′ xj . We also let F ′ be the forest containing those trees T ′ xj that have at least one vertex not distinguished by (W i , L i ∪ L j ). We know that for each tree T ′ xj of F ′ , we will use only watchers to distinguish the vertices not yet distinguished. For each tree T ′ xj in F ′ , let T ′ xj be the tree obtained from T ′ xj by removing all leaves already dominated by a watcher of W i . If this process has created a t-stem with t ≥ 2, then at least t − 1 leaf neighbours of this t-stem have a watcher of W i ; simply remove them. Then, the obtained tree T ′ xj has no t-stems with t ≥ 2. Hence, we can apply Lemma 13 to T ′ xj (if necessary, we augment T ′ xj to satisfy the maximality condition (iii) in Lemma 13). Thus, there is a set X j of at most 63k 2 vertices of T ′ xj that may possibly contain a watcher, and X j can be computed in time linear in |V ( T ′ xj )|. As before, there are at most k trees in F ′ and hence in total the set X = ∪ j X j of possible placements for the remaining watchers has size at most 63k 3 (and is computable in linear time). Therefore, we can check all the 63k 3 k ∈ O 2 O(k log k) possibilities of placing the remaining watchers. If we find a valid detection pair (W, L) with W i ⊆ W , we return YES; otherwise, we discard the placement P j and move on to the next possibility.
It is clear, by the lemmas used in the description in the algorithm, that this algorithm is correct. The running time of the preliminary phase is 2 O(k log k) n 2 . The running time of Phases 1 to 3 is at most 4 k 4 4k 2 O(k log k) n which is 2 O(k log k) n. This completes the proof.

Conclusion
We have obtained a linear-time 2-approximation algorithm for Opt-Detection Pair on trees, but perhaps this algorithmic upper bound could be improved to a PTAS? It seems that the reduction of [12] does not show the inapproximability of Opt-Detection Pair for any constant greater than one. Therefore, it remains to settle the exact approximation complexity of Opt-Detection Pair on trees.
As a second question, can the factor 2 O(k log k) in our FPT algorithm for Detection Pair be improved to single-exponential FPT time 2 O(k) (or even sub-exponential time 2 o(k) )? For this, the bottleneck is our use of Lemma 13 in the preliminary phase and in Phase 3 of the algorithm, during which we search through all possible subsets of size k of some sets of size O(k 2 ) and O(k 3 ), respectively. Moreover, it is perhaps possible to obtain a linear running-time (in terms of n) by reducing the running-time of the preliminary phase.
As an extension of our results, it would be of interest to determine whether, on further graph classes, Opt-Detection Pair is constant-factor approximable and whether Detection Pair is FPT. One natural research direction is to consider the class of planar graphs or its subclasses, the outerplanar graphs and the series-parallel graphs (that is, graphs of treewidth 2). These three classes contain all trees. Although both questions are settled in the affirmative for Opt-Dominating Set and Dominating Set (see [20] and [8,23]), as far as we know they also remain open for Opt-Metric Dimension and Metric Dimension (though, a polynomial-time algorithm exists for Opt-Metric Dimension on outerplanar graphs [6]).