An O(n\log n)-Time Algorithm for the k-Center Problem in Trees

We consider a classical k-center problem in trees. Let T be a tree of n vertices and every vertex has a nonnegative weight. The problem is to find k centers on the edges of T such that the maximum weighted distance from all vertices to their closest centers is minimized. Megiddo and Tamir (SIAM J. Comput., 1983) gave an algorithm that can solve the problem in O(n\log^2 n) time by using Cole's parametric search. Since then it has been open for over three decades whether the problem can be solved in O(n\log n) time. In this paper, we present an O(n\log n) time algorithm for the problem and thus settle the open problem affirmatively.

since the vertices of the tree T have weights, it is elusive how to achieve the same goal. Indeed, this is also one main difficulty to solve the problem even in O(n log n) time (and thus make the problem open for such a long time). As will be seen later, our O(n log n) time algorithm circumvents the difficulty by combining several techniques. Based on our study, although we do not have a proof, we suspect that Ω(n log n) is a lower bound of the problem.
The rest of the paper is organized as follows. In Section 2, we review some previous techniques that will be used later. In Section 3, we describe our techniques for dealing with a so-called "stem". We finally solve the k-center problem on T in Section 4. By slightly modifying the techniques, we solve the discrete case in Section 5.

Preliminaries
In this section we review some techniques that will be used later in our algorithm.

The Feasibility Test FTEST0
Given any value λ, the feasibility test is to determine whether λ is feasible, i.e., whether λ ≥ λ * . We say that a vertex v of T is covered (under λ) by a center q if w(v) · d(v, q) ≤ λ. Note that λ is feasible if and only if we can place k centers in T such that all vertices are covered. In the following we describe a linear-time feasibility test algorithm, which is essentially the same as the one in [20].
We pick a vertex of T as the root, denoted by γ. For each vertex v, we use T (v) to denote the subtree of T rooted at v. Following a post-order traversal on T , we place centers in a bottom-up and greedy manner. For each vertex v, we maintain two values sup(v) and dem(v), where sup(v) is the distance from v to the closest center that has been placed in T (v), and dem(v) is the maximum distance from v such that if we place a center q outside T (v) \ {v} within such a distance from v then all uncovered vertices of T (v) can be covered by q. We also maintain a variable count to record the number of centers that have been placed so far. Refer to Algorithm 1 for the pseudocode.
Initially, count = 0, and for each vertex v, sup(v) = ∞ and dem(v) = λ w(v) . Following a postorder traversal on T , suppose vertex v is being visited. For each child u of v, we update sup(v) and dem(v) as follows. If sup(u) ≤ dem(u), then we can use the center of T (u) closest to u to cover the uncovered vertices of T (u), and thus we reset sup(v) = min{sup(v), sup(u) + d(u, v)}. Note that since u connects v by an edge, d(v, u) is the length of the edge. Otherwise, if dem(u) < d(u, v), then we place a center on the edge e(u, v) at distance dem(u) from u, so we update count = count+1 and sup(v) = min{sup(v), d(u, v) − dem(u)}. Otherwise (i.e., dem(u) ≥ d(u, v)), we update dem(v) = min{dem(v), dem(u) − d(u, v)}.
After the root γ is visited, if sup(γ) > dem(γ), then we place a center at γ and update count = count + 1. Finally, λ is feasible if and only if count ≤ k. The algorithm runs in O(n) time. We use FTEST0 to refer to the algorithm.
Remark. The algorithm FTEST0 actually partitions T into at most k disjoint connected subtrees such that the vertices in each subtree is covered by the same center that is located in the subtree. We will make use of this observation later.
To solve the k-center problem, the key is to compute λ * , after which we can find k centers by applying FTEST0 with λ = λ * .

A Matrix Searching Algorithm
We review an algorithm MSEARCH, which was proposed in [14] and was widely used, e.g., [15,16,17]. A matrix is sorted if elements in every row and every column are in nonincreasing order. Given a set of sorted matrices, a searching range (λ 1 , λ 2 ) such that λ 2 is feasible and λ 1 is not, and a stopping count c, MSEARCH will produce a sequence of values one at a time for feasibility tests, and after each test, some elements in the matrices will be discarded. Suppose a value λ is produced. If λ ∈ (λ 1 , λ 2 ), we do not need to test λ. If λ is feasible, then λ 2 is updated to λ; otherwise, λ 1 is updated to λ. MSEARCH will stop once the number of remaining elements in all matrices is at most c. Lemma 1 is proved in [14] and we slightly change the statement to accommodate our need.
Lemma 1. [14,15,16,17] Let M be a set of N sorted matrices {M 1 , M 2 , . . . , M N } such that M j is of dimension m j × n j with m j ≤ n j , and N j=1 m j = m. Let c ≥ 0. The number of feasibility tests needed by MSEARCH to discard all but at most c of the elements is O(max{log max j {n j }, log( m c+1 )}), and the total time of MSEARCH exclusive of feasibility tests is O(κ· N j=1 m j log( 2n j m j )), where O(κ) is the time for evaluating each matrix element (i.e., the number of matrix elements that need to be evaluated is O( N j=1 m j log( 2n j m j ))).

The 2D Sublist LP Queries
Let H = {h 1 , h 2 , . . . , h m } be a set of m upper half-planes in the plane. Given two indices i and j with 1 ≤ i ≤ j ≤ m, a 2D sublist LP query asks for the lowest point in the common intersection of h i , h i+1 , . . . , h j . The line-constrained version of the query is: Given a vertical line l and two indices i and j with 1 ≤ i ≤ j ≤ m, the query asks for the lowest point on l in the common intersection of h i , h i+1 , . . . , h j . Lemma 2 was proved in [10] z(i.e., Lemma 8 and the discussion after it; the query algorithm for the line-constrained version is used as a procedure in the proof of Lemma 8 Remark. With O(m log m) preprocessing time, any poly(log m)-time algorithms for both query problems would be sufficient for our purpose, where poly() is any polynomial function.

Line Arrangement Searching
Let L be a set of m lines in the plane. Denote by A(L) the arrangement of the lines of L, and let y(v) denote the y-coordinate of each vertex v of A(L). Let v 1 (L) be the lowest vertex of A(L) whose y-coordinate is a feasible value, and let v 2 (L) be the highest vertex of A(L) whose y-coordinate is smaller than that of v 1 (L). By their definitions, y(v 2 (L)) < λ * ≤ y(v 1 (L)), and A(L) does not have a vertex v with y(v 2 (L)) < y(v) < y(v 1 (L)). Lemma 3 was proved in [11]. Remark. Alternatively, we can use Cole's parametric search [12] to compute the two vertices. First, we sort the lines of L by their intersections with the horizontal line y = λ * , and this can be done in O((m + τ ) log m) time by Cole's parametric search [12]. Then, v 1 (L) and v 2 (L) can be found in additional O(m) time because each of them is an intersection of two adjacent lines in the above sorted order. The line arrangement searching technique, which modified the slope selection algorithms [6,22], avoids Cole's parametric search [12].
In the following, we often talk about some problems in the plane R 2 , and if the context is clear, for any point p ∈ R 2 , we use x(p) and y(p) to denote its x-and y-coordinates, respectively.

The Algorithms for Stems
In this section, we first define stems, which are similar in spirit to those proposed in [16] for the unweighted case. Then, we will present two algorithms for solving the k-center problem on a stem, and both techniques will be used later for solving the problem in the tree T .
Let P be a path of m vertices, denoted by v 1 , v 2 , . . . , v m , sorted from left to right. For each vertex v i , other than its incident edges in P , v i has at most two additional edges connecting two vertices u i and w i that are not in P . Either vertex may not exist. Let P denote the union of P and the above additional edges (e.g., see Fig. 1). For any two points p and q on P , we still use π(p, q) to denote the unique path between p and q in P , and use d(p, q) to denote the length of the path. With respect to a range (λ 1 , λ 2 ), we call P a stem if the following holds: Following the terminology in [16], we call e(v i , u i ) a thorn and e(v i , w i ) a twig. Each u i is called a thorn vertex and each w i is called a twig vertex. P is called the backbone of P , and each vertex of P is called a backbone vertex. We define m as the length of P . The total number of vertices of P is at most 3m.
Remark. Our algorithm in Section 4 will produce stems P as defined above, where P is a path in T and all vertices of P are also vertices of T . However, each thorn e(u i , v i ) may not be an original edge of T , but it corresponds to the path between u i and v i in T in the sense that the length of e(u i , v i ) is equal to the distance between u i and v i in T . This is also the case for each twig e(w i , v i ).
Our algorithm in Section 4 will maintain a range (λ 1 , λ 2 ) such that λ 1 is not feasible and λ 2 is feasible, i.e., λ * ∈ (λ 1 , λ 2 ]. Since any feasibility test will be made to a value λ ∈ (λ 1 , λ 2 ), the above definitions on thorns and twigs imply the following: For each thorn vertex u i , we can place a center on the backbone to cover it (under λ), and for each twig vertex w i , we need to place a center on the edge e(w i , v i ) \ {v i } to cover it.
In the sequel we give two different techniques for solving the k-center problem on the stem P . In fact, in our algorithm for the k-center problem on T in Section 4, we use these techniques to process a stem P , rather than directly solve the k-center problem on P . Let λ * temporarily refer to the optimal objective value of the k-center problem on P in the rest of this section, and we assume λ * ∈ (λ 1 , λ 2 ].

The First Algorithm
This algorithm is motivated by the following easy observation: there exist two vertices v and v ′ in P such that a center q is located in the path π(v, v ′ ) and We assume that all backbone vertices of P are in the x-axis of an xy-coordinate system R 2 where v 1 is at the origin and each v i has x-coordinate d(v 1 , v i ). Each v i defines two lines l + (v i ) and l − (v i ) both containing v i and with slopes w(v i ) and −w(v i ), respectively (e.g., see Fig. 2). Each thorn u i also defines two lines l + (u i ) and l − (u i ) as follows. Define u l i (resp., u r i ) to be the point in to be the line through u l i with slope w(u i ) and l − (u i ) to be the line through u r i with slope −w(u i ). Note that l + (u i ) and l − (u i ) intersects at the point whose x-coordinate is the same as that of v i and whose y-coordinate is equal to w(u i ) · d(u i , v i ). For each twig vertex w i , we define points w l i and w r i , and lines l + (w i ) and l − (w i ), in the same way as those for u i .
Consider a point q on the backbone of P to the right side of v i . It can be verified that the weighted distance w(v i ) · d(v i , q) from v i to q is exactly equal to the y-coordinate of the intersection between l + (v i ) and the vertical line through q. If q is on the left side of v i , we have a similar observation for l − (v i ). This is also true for u i and w i .
Let L denote the set of the lines in R 2 defined by all vertices of P . Note that |L| ≤ 6m. Based on the above observation, λ * is equal to the y-coordinate of a vertex of the line arrangement A(L) of L. More precisely, λ * is equal to the y-coordinate of the vertex v 1 (L), as defined in Section 2. By Lemma 3, we can compute Fig. 2. Illustrating the definitions of the lines defined by a backbone vertex vi and its thorn vertex ui.

The Second Algorithm
This algorithm relies on the algorithm MSEARCH. We first form a set of sorted matrices.
For each i ∈ [1, m], we define the two lines l + i (v i ) and l − i (v i ) in R 2 as above in Section 3.1. If u i exists, then we also define l + i (u i ) and l − i (u i ) as before; otherwise, both l + i (u i ) and l − i (u i ) refer to the x-axis. Let h 4(i−1)+j , 1 ≤ j ≤ 4, denote respectively the four upper half-planes bounded by the above four lines (their index order is arbitrary). In this way, we have a set H = {h 1 , h 2 . . . , h 4m } of 4m upper half-planes.
For any i and j with 1 ≤ i ≤ j ≤ m, we define α(i, j) as the y-coordinate of the lowest point in the common intersection of the upper half-planes of H from h 4(i−1)+1 to h 4j , i.e., all upper halfplanes defined by u t and v t for t ∈ [i, j]. Observe that if we use one center to cover all backbone and thorn vertices u t and v t for t ∈ [i, j], then α(i, j) is equal to the optimal objective value of this one-center problem.
We define a matrix M of dimension m × m: For any i and j in [1, m] For each twig w i , we define two arrays A r i and A l i of at most m elements each as follows. Let h + (w i ) and h − (w i ) denote respectively the upper half-planes bounded by the lines l + (w i ) and l − (w i ) defined in Section 3.1. The array A r i is defined on the vertices of P on the right side of v i , as follows. For each j ∈ [1, m − i + 1], if we use a single center to cover w i and all vertices u t and v t for t ∈ [i, m + 1 − j], then A r [j] is defined to be the optimal objective value of this one-center problem, which is equal to the y-coordinate of the lowest point in the common intersection of h + (w i ) and the upper half-planes of H from h 4(i−1)+1 to h 4(m+1−j) . Symmetrically, array A l i is defined on the left side of v i . Specifically, for each j ∈ [1, i], if we use one center to cover w i and all vertices u t and v t for t ∈ [j, i], then A l [j] is defined to be the optimal objective value, which is equal to the y-coordinate of the lowest point in the common intersection of h − (w i ) and the upper half-planes of H from h 4(j−1)+1 to h 4i .
Let M be the set of the matrices M and A r i and A l i for all 1 ≤ i ≤ m. The following lemma implies that we can apply MSEARCH on M to compute λ * .
H 2 ) be the set of the upper half-planes of H from h 4(i−1)+1 to h 4(m+1−j 1 ) (resp., h 4(m+1−j 2 ) ). Since j 1 < j 2 , H 2 is a subset of H 1 , and thus the lowest point in the common intersection of the upper half-planes of H 2 is not higher than that of H 1 . Hence, α(i, m The above proves M [i, . Therefore, all elements in each row are sorted in nonincreasing order. By the similar approach we can show that all elements in each column are also sorted in nonincreasing order. We omit the details. Hence, M is a sorted matrix. Now consider an array A l i . Consider any two elements The argument is similar as the above third case. Let H 1 (resp., H 2 ) be the set of h − (w i ) and the upper half-planes of H from h 4(j 1 −1)+1 (resp., h 4(j 2 −1)+1 ) to h 4i . Since j 1 < j 2 , H 2 is a subset of H 1 and the lowest point in the common intersection of the upper half-planes of H 2 is not higher than that of H 1 . Hence, . We can show that A r i is also sorted in a similar way. We omit the details. The above proves that every matrix of M is sorted. In the following, we show that λ * must be an element of one of these matrices.
Imagine that we apply our feasibility test algorithm FTEST0 on λ = λ * and the stem P by considering P as a tree with root v m . Then, the algorithm will compute at most k centers in P . The algorithm actually partitions P into at most k disjoint connected subtrees such that the vertices in each subtree is covered by the same center that is located in the subtree. Further, there must be a subtree P 1 that has a center q and two vertices v ′ and v such that w(v)·d(v, q) = w(v ′ )·d(v ′ , q) = λ * , since otherwise we could adjust the positions of the centers so that the maximum weighted distance from all vertices of P to their closest centers would be strictly smaller than λ * . Since P 1 is connected and both v and v ′ are in P 1 , the path π(v, v ′ ) is also in P 1 .
Depending on whether one of v and v ′ is a twig vertex, there are two cases. If neither vertex is a twig vertex, then we claim that all thorn vertices connecting to the backbone vertices of π(v, v ′ ) are covered by the center q. Indeed, suppose v i is a backbone vertex in π(v, v ′ ) and v i connects to a thorn vertex u i . Assume to the contrary that u i is not covered by q. Recall that by the definition of thorns, w(u i ) · d(u i , v i ) ≤ λ 1 , and since λ 1 < λ * , we have w(u i ) · d(u i , v i ) < λ * . According to FTEST0, u i is covered by a center q ′ that is not on e(u i , v i ). Hence, u i and q ′ is in a connected subtree, denoted by P 2 , in the partition of P induced by FTEST0. Clearly, v i is in π(u i , q ′ ). Since P 2 is connected and both q ′ and u i are in P 2 , every vertex of π(u i , q ′ ) is in P 2 . Because q ′ is not on e(u i , v i ), v i must be in π(u i , q ′ ) and thus is in P 2 . However, since v i is in π(v, v ′ ), v i is also in P 1 . This incurs contradiction since P 1 ∩ P 2 = ∅. This proves the claim.
If v is a backbone vertex, then let i be its index, i.e., v = v i ; otherwise, v is a thorn vertex and let i be the index such that v connects the backbone vertex v i . Similarly, define j for v ′ . Without loss of generality, assume i ≤ j. The above claims implies that λ * is equal to the y-coordinate of the lowest point in the common intersection of all upper half-planes defined by the backbone vertices v t and thorn vertices u t for all t ∈ [i, j], and thus, λ * = α(i, j), which is equal to M [i, m + 1 − j]. Therefore, λ * is in the matrix M .
Next, we consider the case where at least one of v and v ′ is a twig vertex. For each twig vertex w i of P , by definition, w(w i ) · d(w i , v i ) ≥ λ 2 , and since λ * ≤ λ 2 , the twig e(w i , v i ) must contain a center. Because both v and v ′ are covered by q, only one of them is a twig vertex (since otherwise we would need two centers to cover them since each twig must contain a center). Without loss of generality, we assume that v is a twig vertex, say, w i . If v ′ is a backbone vertex, then let j be its index; otherwise, v ′ is a thorn vertex and let j be the index such that v ′ connects the backbone vertex v j . Without loss of generality, we assume that i ≤ j.
By the same argument as the above, all thorn vertices u t with t ∈ [i, j] are covered by q. This implies that λ * is the y-coordinate of the lowest point in the common intersection of h + (w i ) and all upper half-planes defined by the backbone vertices v t and thorn vertices u t for all t ∈ [i, j]. Thus, . Therefore, λ * is in the array A r i . This proves that λ * must be in a matrix of M. The lemma thus follows. time by a 2D sublist LP query with query indices 4(j −1)+1 and 4i. Computing p * can also be done in O(log 2 m) time by slightly modifying the query algorithm for computing p ′ . We briefly discuss it below and the interested reader should refer to [10] for details (the proof of Lemma 8 and the discussion after the lemma).
The query algorithm for computing p ′ is similar in spirit to the linear-time algorithm for the 2D linear programming problem in [23]. It is a binary search algorithm. In each iteration, the algorithm computes the highest intersection p ′′ between a vertical line l and the bounding lines of the halfplanes of H ′ , and based on the local information at the intersection, the algorithm will determine which side to proceed for the search. For computing p * , we need to incorporate the additional half-plane h + (w i ). To this end, in each iteration of the binary search, after we compute the highest intersection p ′′ , we compare it with the intersection of l and the bounding line of h + (w i ) and update the highest intersection if needed. This costs only constant extra time for each iteration. Therefore, the total running time for computing p * is still O(log 2 m).
Computing the elements of arrays A r i can be done similarly. The lemma thus follows. Remark. Clearly, the first algorithm is better than the second one. However, later when we use the techniques of the second algorithm, m is often bounded by O(log 2 n) and thus log 3 m = O(log n). In fact, we use the techniques of the second algorithm mainly because we need to set the stopping count c to some non-zero value.

Solving the k-Center Problem on T
In this section, we present our algorithm for solving the k-center problem on T . We will focus on computing the optimal objective value λ * .
Frederickson [15] proposed a path-partition of T , which is a partition of the edges of T into paths where a vertex v is an endpoint of a path if and only if the degree of v in T is not equal to 2 (e.g., see Fig. 3). A path in a partition-partition of T is called a leaf-path if it contains a leaf of T .
As in [16], we generalize the path-partition to stem-partition as follows. During the course of our algorithm, a range (λ 1 , λ 2 ] that contains λ * will be maintained and T will be modified by removing some edges and adding some thorns and twigs. At any point in our algorithm, let T ′ be T with all thorns and twigs removed. A stem of T is a path in the path-partition of T ′ , along with all thorns and twigs that connect to vertices in the path. A stem-partition of T is to partition T into stems according to a path-partition of T ′ . A stem in a stem-partition of T is called a leaf-stem if it contains a leaf of T that is a backbone vertex of the stem. Our algorithm follows the first algorithmic scheme in [16]. There are two main phases: Phase 1 and Phase 2. Let r = log 2 n. Phase 1 gathers information so that the feasibility test can be made in sublinear O( n r log 3 r) time. Phase 2 computes λ * by using the faster feasibility test. If T has more than 2n/r leaves, then there is an additional phase, called Phase 0, which reduces the problem to a tree with at most 2n/r leaves. (Phase 0 is part of Phase 1 in [16], and we separates it from Phase 1 to make it clearer.) In the following, we consider the general case where T has more than 2n/r leaves. Algorithm 3 gives the pseudocode of the overall algorithm.

The Preprocessing and Computing the Vertex Ranks
We first perform some preprocessing. Recall that γ is the root of T . We compute the distances In the following, whenever we need to compute a distance d(u, v), it is always the case that one of u and v is an ancestor of the other, and thus d(u, v) can be obtained in O(1) time.
Next, we compute a "rank" rank(v) for each vertex v of T . These ranks will facilitate our algorithm later. For each vertex v, we define a point p(v) on the x-axis with x-coordinate equal to d(γ, v) in an xy-coordinate system R 2 , and define l(v) as the line through p(v) with slope equal to −w(v). Let L be the set of these n lines. Consider the line arrangement A(L) of L. Let v 1 (L) and v 2 (L) be the vertices as defined in Section 2. By Lemma 3, both vertices can be computed in O(n log n) time. Let l be a horizontal line strictly between v 1 (L) and v 2 (L). We sort all lines of L by their intersections with l from left to right, and for each vertex v, we define rank(v) = i if there are i − 1 lines before l(v) in the above order. By the definitions of v 1 (L) and v 2 (L), the above order of L is also an order of L sorted by their intersections with the horizontal line y = λ * .

Phase 0
Recall that T has more than 2n/r leaves. In this section, we reduce the problem to the problem of placing centers in a tree with at most 2n/r leaves. Our algorithm will maintain a range (λ 1 , λ 2 ] that contains λ * . Initially, λ 1 = y(v 2 (L)), the y-coordinate of v 2 (L), which is already computed in the preprocessing, and λ 2 = y(v 1 (L)). We form a stem-partition of T , which is actually a path-partition since there are no thorns and twigs initially, and this can be done in O(n) time.
Recall that r = log 2 n. While there are more than 2n/r leaves in T , we do the following.
Recall that the length of a stem is defined as the number of backbone vertices. Let S be the set of all leaf-stems of T whose lengths are at most r. Let n ′ be the number of all backbone vertices on the leaf-stems of S. For each leaf-stem of S, we form matrices by Lemma 5. Let M denote the collection of matrices for all leaf-stems of S. We call MSEARCH on M, with stopping count c = n ′ /(2r), by using the feasibility test algorithm FTEST0. After MSEARCH stops, we have an updated range (λ 1 , λ 2 ) and matrix elements of M in (λ 1 , λ 2 ) are called active values. Since c = n ′ /(2r), at most n ′ /(2r) active values of M remain, and thus at most n ′ /(2r) leaf-stems of S have active values.
For each leaf-stem P ∈ S without active values, we perform the following post-processing procedure. The backbone vertex of P closest to the root is called the top vertex. We place centers on P , subtract their number from k, and replace P by either a thorn or a twig connected to the top vertex (P is thus removed from T except the top vertex), such that solving the k-center problem on the modified T also solves the problem on the original T . The post-processing procedure can be implemented in O(m) time, where m is the length of P . The details are given below.
The post-processing procedure on P . Let z be the top vertex of P . We run the feasibility test algorithm FTEST0 on P with z as the root and λ = λ ′ that is an arbitrary value in (λ 1 , λ 2 ). After z is finally processed, depending on whether sup(z) ≤ dem(z), we do the following.
If sup(z) ≤ dem(z), then let q be the last center that has been placed. In this case, all vertices of P are covered and z is covered by q. According to algorithm FTEST0 and as discussed in the proof of Lemma 4, q covers a connected subtree of vertices, and let V (q) denote the set of these vertices excluding z. Note that V (q) can be easily identified during FTEST0. Let k ′ be the number of centers excluding q that have been placed on P . Since λ ′ ∈ (λ 1 , λ 2 ) and the matrices formed based on P do not have any active values, we have the following key observation: if we run FTEST0 with any λ ∈ (λ 1 , λ 2 ), the algorithm will also cover all vertices of P \ (V (q) ∪ {z}) with k ′ centers and cover vertices of V (q) ∪ {z} with one center. Indeed, this is true because the way we form matrices for P is consistent with FTEST0, as discussed in the proof of Lemma 4. In this case, we replace P by attaching a twig e(u, z) to z with length equal to d(u, z), where u is a vertex of V (q) with the following property: For any λ ∈ (λ 1 , λ 2 ), if we place a center q ′ on the path π(u, z) at distance λ/w(u) from u, then q ′ will cover all vertices of V (q) under λ, i.e., u "dominates" all other vertices of V (q) and thus it is sufficient to keep u (since λ 2 is feasible, any subsequent feasibility test in the algorithm will use λ ∈ (λ 1 , λ 2 )). The following lemma shows that u is the vertex of V (q) with the largest rank.
Lemma 6. Let u be the vertex of V (q) with the largest rank. For any λ ∈ (λ 1 , λ 2 ), the following holds. Fig. 4. Illustrating the proof of the case v ∈ V1(q). Note that p(v) and p(u) are the points defined respectively by v and u in Section 4.1.
, then we add a dummy edge e * extended from the root γ long enough so that q ′ is on e * ). Later we will show that λ w(u) ≤ d(u, z), which also proves that q ′ is on π(u, z). We first show that q ′ covers all vertices of V (q). Consider any vertex v ∈ V (q). Our goal is to If v = u, this trivially holds. In the following, we assume v = u.
Note that q ′ may be on a twig of P . If q ′ is on a twig e(u, v) of P , then this means that q ′ is on P and λ w(u) ≤ d(u, z) holds. In this case, if we run FTEST0 with λ, then q ′ will be a center placed by FTEST0 to cover u. On the other hand, according to the above key observation, FTEST0 with λ will use one center to cover all vertices of V (q). Hence, q ′ covers all vertices of V (q) and thus covers v. In the following, we assume that q ′ is not on a twig of P . Note that by the definition of thorns, q ′ cannot be in any thorn. Thus q ′ must be either on the backbone of P or outside P in π(z, γ) ∪ e * . We define V 1 (q) to be the set of vertices of V (q) in the subtree rooted at q ′ and let V 2 (q) = V (q) \ V 1 (q). Depending on whether v is in V 1 (q) or V 2 (q), there are two cases.
The case v ∈ V 1 (q). Recall that in Section 4.1 each vertex v ′ defines a line l(v ′ ) in R 2 . We consider the two lines l(v) and l(u). Let p v and p u denote the intersections of the horizontal line y = λ with l(v) and l(u), respectively (e.g., see Fig. 4). Note that the point q ′ corresponding to the point (x(p u ), 0) in the x-axis in the sense that d(γ, q ′ ) = x(p u ). Since rank(v) < rank(u) and λ ∈ (λ 1 , λ 2 ), by the definition of ranks, it holds that The case v ∈ V 2 (q). In this case, V 2 (q) = ∅. By the definition of V 2 (q), q ′ must be in π(u, v). According to the above key observation, we can use one center to cover all vertices of V (q) (under λ), and in particular, we can use one center to cover both u and v. By the definition of q ′ , q ′ is the closest point to v on π(u, v) that can cover u. Hence, q ′ must be able to cover v. Therefore, we Finally, we argue that λ w(u) ≤ d(u, z). Assume to the contrary that this is not true. Then, q ′ is outside P . This means that we can place a center outside P to cover all vertices of V (q) under λ. But this contradicts the above key observation that FTEST0 for λ ′ will place a center in P to cover the vertices of V (q). The lemma thus follows.
⊓ ⊔ Due to the preprocessing in Section 4.1, we can find u from V (q) in O(m) time. This finishes our post-processing procedure for the case sup(z) ≤ dem(z). Since λ w(u) ≤ d(u, z) for any λ ∈ (λ 1 , λ 2 ), we have w(u) · d(u, z) ≥ λ 2 , and thus, e(u, z) is indeed a twig.
Next, we consider the other case sup(z) > dem(z). In this case, P has some vertices other than z that are not covered yet, and we would need to place a center at z to cover them. Let V be the set of all uncovered vertices other than z, and V can be identified during FTEST0. In this case, we replace P by attaching a thorn e(u, z) to z with length equal to d(u, z), where u is a vertex of V with the following property: For any λ ∈ (λ 1 , λ 2 ), if there is a center q outside P covering u through z (by "through", we mean that π(q, u) contains z) under distance λ, then q also covers all other vertices of V (intuitively u "dominates" all other vertices of V ). Since later we will place centers outside P to cover the vertices of V through z under some λ ∈ (λ 1 , λ 2 ), it is sufficient to maintain u. The following lemma shows that u is the vertex of V with the largest rank.
Lemma 7. Let u be the vertex of V with the largest rank. Then, for any center q outside P that covers u through z under any distance λ ∈ (λ 1 , λ 2 ), q also covers all other vertices of V .
Proof. Let v be any vertex of V other than u. Our goal is to prove that d(q, v) · w(v) ≤ λ. The proof is similar to that for the case v ∈ V 1 (q) of Lemma 6 and we omit the details.
⊓ ⊔ Since a center at z would cover u, it holds that The above replaces P by attaching to z either a thorn or a twig. We perform the following additional processing.
Suppose z is attached by a thorn e(z, u). If z already has another thorn e(z, u ′ ), then we discard one of u ′ and u whose rank is smaller, because any center that covers the remaining vertex will cover the discarded one as well (the proof is similar to those in Lemma 6 and 7 and we omit it). This makes sure that z has at most one thorn.
Suppose z is attached by a twig e(z, u). If z already has another twig e(z, u ′ ), then we can discard one of u and u ′ whose rank is larger (and subtract 1 from k). The reason is the following. Without loss of generality, assume rank(u) < rank(u ′ ). Since both e(z, u) and e(z, u ′ ) are twigs, if we apply FTEST0 on any λ ∈ (λ 1 , λ 2 ), then the algorithm will place a center q on e(z, u) with distance λ/w(u) from u and place a center q ′ on e(z, u ′ ) with distance λ/w(u ′ ) from u ′ . As rank(u) < rank(u ′ ), we have the following lemma.
Proof. The analysis is similar to those in Lemma 6 and 7. Consider the lines l(u) and l(u ′ ) in R 2 defined by u and u ′ , respectively, as discussed in Section 4.1. Let p u and p u ′ be the intersections of the horizontal line y = λ with l(u) and l(u ′ ), respectively (e.g., see Fig. 5). Since rank(u) < rank(u ′ ) and On the other hand, due to that q ∈ e(z, u) and Lemma 8 tells that any vertex that is covered by q ′ in the subsequent algorithm will also be covered by q. Thus, it is sufficient to maintain the twig e(z, u). Since we need to place a center at e(z, u ′ ), we subtract 1 from k after removing e(z, u ′ ). Hence, z has at most one twig.
This finishes the post-processing procedure for P . Due to the preprocessing in Section 4.1, the running time of the procedure is O(m).
Let T be the modified tree after the post-processing on each stem P without active values. If T still has more than 2n/r leaves, then we repeat the above. The algorithm stops once T has at most 2n/r leaves. This finishes Phase 0. The following lemma gives the time analysis, excluding the preprocessing in Section 4.1. Proof. We first argue that the number of iterations of the while loop is O(log r). The analysis is very similar to those in [15,16], and we include it here for completeness.
We consider an iteration of the while loop. Suppose the number of leaf-stems in T is at least 2n/r. Then, at most n/r leaf-stems are of length larger than r. Hence, at least half of the leaf-stems are of length at most r. Thus, |S| ≥ n/r. Recall that n ′ is the total number of backbone vertices in all leaf-stems of S. Because at most n ′ /(2r) leaf-stems have active values after MSEARCH, at least |S| − n ′ /(2r) ≥ n/r − n ′ /(2r) ≥ n/r − n/(2r) = n/(2r) leaf-stems will be removed. Note that removing two such leaf-stems may make an interior vertex become a new leaf in the modified tree. Hence, the tree resulting at the end of each iteration will have at most 1 − 1 2 · n/(2r) 2n/r = 7/8 of the leaf-stems of the tree at the beginning of the iteration. Therefore, the number of iterations of the while loop needed to reduce the number of leaf-stems to at most 2n/r is O(log r).
We proceed to analyze the running time of Phase 0. In each iteration of the while loop, we call MSEARCH on the matrices for all leaf-stems of S. Since the length of each stem P of S is at most r, there are O(r) matrices formed for P . We perform the preprocessing of Lemma 5 on the matrices, so that each matrix element can be evaluated in O(log 2 r) time. The total time of the preprocessing on stems of S is O(n ′ log r). Since M has O(n ′ ) matrices and the stopping account c is n ′ /(2r), each call to MSEARCH produces O(log r) values for feasibility tests in O(n ′ log 3 r) time (i.e., O(n ′ log r) matrix elements will be evaluated). For each leaf-stem without active values, the post-processing time for it is O(r). Hence, the total post-processing time in each iteration is O(n ′ ).
Since there are O(log r) iterations, the total number of feasibility tests is O(log 2 r), and thus the overall time for all feasibility tests in Phase 0 is O(n log 2 r). On the other hand, after each iteration, at most n ′ /(2r) leaf-stems of S have active values and other leaf-stems of S will be deleted. Since the length of each leaf-stem of S is at most r, the leaf-stems with active values have at most n ′ /2 backbone vertices, and thus at least n ′ /2 backbone vertices will be deleted in each iteration. Therefore, the total sum of such n ′ in all iterations is O(n). Hence, the total time for the preprocessing of Lemma 5 is O(n log r), the total time for MSEARCH is O(n log 3 r), and the total post-processing time for leaf-stems without active values is O(n).
In summary, the overall time of Phase 0 (excluding the preprocessing in Section 4.1) is O(n log 3 r), which is O(n(log log n) 3 ) since r = log 2 n. ⊓ ⊔

Phase 1
We assume that the tree T now has at most 2n/r leaves and we want to place k centers in T to cover all vertices. Note that T may have some thorns and twigs. The main purpose of this phase is to gather information so that each feasibility test can be done in sublinear time, and specifically, O(n/r log 3 r) time. Recall that we have a range (λ 1 , λ 2 ] that contains λ * . We first form a stem-partition for T . Then, we further partition the stems into substems, each of length at most r, such that the lowest backbone vertex v in a substem is the highest backbone vertex in the next lower substem (if v has a thorn or/and a twig, then they are included in the upper substem). So this results in a partition of edges. Let S be the set of all substems. Let T c be the tree in which each node represents a substem of S and node µ in T c is the parent of node ν if the highest backbone vertex of the substem for ν is the lowest backbone vertex of the substem for µ, and we call T c the stem tree. As in [15,16], since T has at most 2n/r leaves, |S| = O(n/r) and the number of nodes of T c is O(n/r).
For each substem P ∈ S, we compute the set L P of lines as in Section 3.1. Let L be the set of all the lines for all substems of S. We define the lines of L in the same xy-coordinate system R 2 . Clearly, |L| = O(n). Consider the line arrangement A(L). Define vertices v 1 (L) and v 2 (L) of A(L) as in Section 2. With Lemma 3 and FTEST0, both vertices can be computed in O(n log n) time. We update λ 1 = max{λ 1 , y(v 2 (L)} and λ 2 = min{λ 2 , y(v 1 (L)}. Hence, we still have λ * ∈ (λ 1 , λ 2 ]. We again call the values in (λ 1 , λ 2 ) active values.
For each substem P ∈ S, observe that each element of the matrices formed based on P in Section 3.2 is equal to the y-coordinate of the intersection of two lines of L P , and thus is equal to the y-coordinate of a vertex of A(L). By the definitions of v 1 (L) and v 2 (L), no matrix element of P is active.
In the future algorithm, we will only need to test feasibilities for values λ ∈ (λ 1 , λ 2 ). In what follows, we compute a data structure on each substem P of S, so that it will help make the feasibility test faster. We will prove the following lemma and use FTEST1 to denote the feasibility test algorithm in the lemma. We first discuss the preprocessing and then present the algorithm FTEST1.

The Preprocessing for FTEST1
Consider a substem P of S. Let v 1 , v 2 , . . . , v m be the backbone vertices of P sorted from left to right, with v m as the top vertex. Each vertex v i may have a twig e(w i , v i ) and a thorn e(u i , v i ). Let λ be an arbitrary value in (λ 1 , λ 2 ). In the following, all statements made to λ is applicable to any λ ∈ (λ 1 , λ 2 ), and this is due to that none of the elements in the matrices produced by P is active. Fig. 6. Illustrating the proof of Lemma 11. Note that w l i is the point defined by wi, as discussed in Section 3.1.
By the definition of twigs, if we run FTEST0 with λ, the algorithm will place a center, denoted by q i , on each twig e(w i , v i ) at distance λ/w(w i ) from w i We first run the following cleanup procedure to remove all vertices of P that can be covered by the centers on the twigs under λ.
The cleanup procedure. We first compute a rank rank ′ (l) for each line l of L, as follows.
Let L ′ be the sequence of the lines of L sorted by their intersections with the horizontal line y = λ from left to right. By the definitions of λ 1 and λ 2 , L ′ is also the sequence of the lines of L sorted by their intersections with the horizontal line y = λ * . In fact, the sequence L ′ is unique for any λ ∈ (λ 1 , λ 2 ). For any line l ∈ L, if there are i lines before l in L ′ , then we define rank ′ (l) to be i. Clearly, rank ′ (l) for all lines l ∈ L can be computed in O(n) time.
Consider a twig e(w i , v i ) and a backbone vertex v j with j ≥ i. Recall that w i defines a line l + (w i ) of slope w(w i ) and v j defines a line l − (v j ) of slope −w(v j ) in L P (and thus are in L). We have the following lemma.
Proof. Let p i and p j be the intersections of the horizontal line y = λ with l + (w i ) and l − (v j ), respectively. Refer to Fig. 6. Let p ′ j denote the intersection of l − (v j ) with the vertical line through p i . Since q i is located on e(w i , v i ), according to the definitions of l + (w i ) and l − (v j ), y(p ′ j ) is exactly equal to w(v j ) · d(q i , v j ). Hence, q i covers v j if and only if p ′ j is below the line y = λ. On the other hand, p ′ j is below the line y = λ if and only if p i is to the right of p j , i.e., rank ′ (l + (w i )) > rank ′ (l − (v j )). The lemma thus follows. ⊓ ⊔ Consider a thorn vertex u j with j ≥ i. Recall that u j defines a line l − (u j ) in L P with slope −w(u j ). Similarly as above, q i covers u j if and only if rank ′ (l + (w i )) > rank ′ (l − (u j )).
Based on the above observations, we use the following algorithm to find all backbone and thorn vertices of P that can be covered by the centers on the twigs to their left sides. Let i ′ be the smallest index such that v i ′ has a twig w i ′ . The algorithm maintains an index t. Initially, t = i ′ . For each i incrementally from i ′ to m, we do the following. If v i has a twig-vertex w i , then we reset t to i if rank ′ (l + (w i )) > rank ′ (l + (w t )). The reason we do so is that if rank ′ (l + (w i )) > rank ′ (l + (w t )), then for any j ≥ i such that v j (resp., u j ) is covered by the center q t on the twig e(w t , v t ), v j (resp., u j ) is also covered by the center q i on the twig e(w i , v i ), and thus it is sufficient to maintain the twig e(w i , v i ). Next, if rank ′ (l + (w t )) > rank ′ (l − (v i )), then we mark v i as "covered". If u i exits and rank ′ (l + (w t )) > rank ′ (l − (u i )), then we mark u i as "covered".
The above algorithm runs in O(m) time and marks all vertices v j (reps., u j ) such that there exists a twig e(w i , v i ) with i ≤ j whose center q i covers v j (reps., u j ). In a symmetric way by scanning the vertices from v m to v 1 , we can mark in O(m) time all vertices v j (reps., u j ) such that there exits a twig e(w i , v i ) with i ≥ j whose center q i covers v j (reps., u j ). We omit the details. This marks all vertices that are covered by centers on twigs.
Let V be the set of backbone and thorn vertices of P that are not marked, which are vertices of P that need to be covered by placing centers on the backbone of P or outside P . If a thorn vertex u i is in V but its connected backbone vertex v i is not in V , this means that v i is covered by a center on a twig while u i is not covered by any such center. Observe that any center on the backbone of P or outside P that covers u i will cover v i as well. For convenience of discussion, we include such v i into V as well. Let v ′ 1 , v ′ 2 , . . . , v ′ t be the backbone vertices of V sorted from left to right (i.e., v ′ t is closer to the root of T ). Note that v ′ 1 may not be v 1 and v ′ t may not be v m . If v ′ i has a thorn vertex in V , then we use u ′ i to denote it. This finishes the cleanup procedure.
Next, we compute a data structure for P to maintain some information for faster feasibility tests.
First of all, we maintain the index a of the twig vertex w a such that rank ′ (l − (w a )) < rank ′ (l − (w i )) for any other twig vertex w i of P . The reason we keep a is the following. Observe that for any vertex v that is a descent vertex of v 1 in T (so v is in another substem that is a descent substem of P in the stem tree T c ), if v can be covered by the center q i on a twig e(v i , w i ) under any λ ∈ (λ 1 , λ 2 ), then v can also be covered by the center q a on the twig e(v a , w a ) under λ. Symmetrically, we maintain the index b of the twig vertex w b such that rank ′ (l + (w b )) > rank ′ (l + (w i )) for any other twig vertex w i . Similarly, this is because for any vertex v that is not in any substem of the subtree rooted at P in T c , if v can be covered by the center on the twig e(v i , w i ) under λ, then v can also be covered by the center on the twig e(v b , w b ) under λ. Both a and b can be computed in O(m) time.
For any two indices i and j with 1 ≤ i ≤ j ≤ t, we use V [i, j] to denote the set of all backbone vertices v l and thorn vertices u l with l ∈ [i, j].
For each index i ∈ [1, t], we maintain an integer ncen(i) and a vertex v(i) of V , which we define below. Roughly speaking, ncen(i) is the minimum number of centers that are needed to cover all vertices of V [i, t], minus one, and if we use ncen(i) centers to cover as many vertices of V [i, t] as possible from left to right, v(i) is the vertex that is not covered but "dominates" all other uncovered vertices under λ. Their detailed definitions are given below.
Let j i be the smallest index in [i, t] such that it is not possible to cover all vertices in V [i, j i ] by one center under λ. If such a index j i does not exist, we let j i = t + 1.
If j i = t + 1, then we define The reason we maintain such v(i) is as follows. Suppose during a feasibility test with λ, all vertices of V [1, i − 1] have been covered and we need to place a new center to cover those in V [i, t]. According to the greedy strategy of FTEST0, we want to place a center as close to the root γ as possible. There are two cases.
In the first case, w(v(i)) · d(v(i), v m ) < λ, and one can verify that if we place a center at the top vertex v m , it can cover all vertices of V [i, t] under λ. In this case, we do not place a center on the backbone of P but will use a center outside P to cover them (more precisely, this center is outside the subtree of T c rooted at substem P ). We maintain v(i) because any center outside P covering v(i) will cover all other vertices of V [i, t] as well.
In the second case, w(v(i)) · d(v(i), v m ) ≥ λ, and we need to place a center on the backbone of P . Again, according to the greedy strategy of FTEST0, we want to place this center close to v m as much as possible, and we use q * to denote such a center. The following lemma shows that q * is determined by v(i).
Proof. The proof is somewhat similar to that of Lemma 6. Let p be the point on π(v(i), v m ) of distance λ w(v(i)) from v(i). Note that since w(v(i)) · d(v(i), v m ) ≥ λ, such a point p must exist on π(v(i), v m ). By definition, p is the point on π(v(i), v m ) closest to v m that can cover v(i). If v(i) is a backbone vertex, then p is on the backbone of P . Otherwise, v(i) is a thorn vertex and w(v(i)) · d(v(i), v) ≤ λ 1 , where v is the backbone vertex that connects v(i). Since λ 1 < λ, we obtain w(v(i)) · d(v(i), v) < λ, and thus p must be on the backbone of P . Hence, in either case, p is on the backbone of P . Consider any vertex In the following, we show that v ′ is covered by p.
If v ′ is in the subtree rooted at p (i.e., π(v ′ , v m ) contains p), then since rank ′ (l + (v(i))) < rank ′ (l + (v ′ )), one can verify that v ′ is covered by p. Otherwise, assume to the contrary that p does not cover v ′ . Then, we would need to move p towards v ′ in order to cover v ′ . However, since p is the point on π(v(i), v m ) closest to v m that can cover v(i), p is also the point on π(v(i), v ′ ) closest to v ′ that can cover v(i). Hence, moving p towards v ′ will make p not cover v(i) any more, which implies that no point on the backbone of P can cover both v ′ and v(i). This contradicts with the fact that it is possible to place a center on the backbone of P to cover all vertices in V [i, t]. Therefore, p covers v ′ .
The above shows that p is the point on the backbone of P closest to v m that can cover all vertices of V [i, t]. Thus, p is q * , and the lemma follows.

⊓ ⊔
The above defines ncen(i) and v(i) for the case where j i = t + 1. If j i ≤ t, we define ncen(i) and v(i) recursively as ncen(i) = ncen(j i ) + 1 and v(i) = v(j i ). Note that i < j i , and thus this recursive definition is valid.
In the following, we present an algorithm to compute ncen(i) and v(i) for all i ∈ [1, t]. In fact, the above recursive definition implies a dynamic programming approach to scan the vertices v ′ i backward from t to 1. The details are given in the following lemma. Proof. For any i and j with 1 ≤ i ≤ j ≤ t, consider the following one-center problem: find a center to cover all backbone and thorn vertices of V [i, j]. As discussed in Section 2, each backbone or thorn vertex defines two upper half-planes such that the optimal objective value for the above one-center problem is equal to the y-coordinate of the lowest point in the common intersection of the at most 4(j − i + 1) half-planes defined by the backbone and thorn vertices of V [i, j]. As in Section 2, as preprocessing, we first compute the upper half-planes defined by all vertices of V and order them by the indices of their corresponding vertices in V , and then compute the 2D sublist LP query data structure of Lemma 2 in O(t log t) time. As in Section 2, the lowest point of the common intersection of the upper half-planes defined by vertices of V [i, j] can be computed by a 2D sublist LP query in O(log 2 t) time. We use α(i, j) to denote the optimal objective value of the above one-center problem for V [i, j]. With the above preprocessing, given i and j, α(i, j) can be computed in O(log 2 t) time.
We proceed to compute ncen(i) and v(i) for all i ∈ [1, t].
For each i from t downto 1, we do the following. We maintain the index j i . Initially when i = t, we set j i = t + 1, ncen(i) = 0, and v(i) = v ′ t . We process index i as follows. We first compute α(i, j i − 1) in O(log 2 t) time. Depending on whether α(i, j i − 1) ≤ λ, there are two cases.
It is not difficult to see that the above algorithm runs in O(t log 2 t) time, which is O(m log 2 m) time since t ≤ m.

⊓ ⊔
Since m ≤ r and r = log 2 n, we can compute the data structure for the substem P in O(r(log log n) 2 ) time. The total time for computing the data structure for all substems of S is O(n(log log n) 2 ). With these data structures, we show that a feasibility test can be done in O(n/r log 3 r) time.

The Faster Feasibility Test FTEST1
Given any λ ∈ (λ 1 , λ 2 ), the goal is to determine whether λ is feasible. We will work on the stem tree T c , where each node represents a stem of S. Refer to Algorithm 2 for the pseudocode of FTEST1.
Initially, we set sup(P ) = ∞ and dem(P ) = sup(P ) − 1 (so that dem(P ) is an infinitely large value but still smaller than sup(P )) for every stem P of T c . We perform a post-order traversal on T c and maintain a variable count, which is the number of centers that have been placed so far. Suppose we are processing a stem P . For each child stem P ′ of P , we reset sup(P ) = min{sup(P ), sup(P ′ )} and dem(P ) = min{dem(P ), dem(P ′ )}. After handling all children of P as above, we process P as follows.
First of all, we increase count by the number of twigs in P . Let V be the uncovered vertices of P as defined before, and v ′ 1 , v ′ 2 , . . . , v ′ t are backbone vertices of V . Note that t ≤ r. Recall that we have maintained two twig indices a and b for P . Depending on whether sup(P ) ≤ dem(P ), there are two main cases.
The case sup(P ) ≤ dem(P ). If sup(P ) ≤ dem(P ), then the uncovered vertices in the children of P can be covered by the center q that determines the value sup(P ) (i.e., q is in a child stem of P and d(q, v 1 ) = sup(P ), where v 1 is the lowest backbone vertex of P ). Note that we do not need to compute q and we use it only for the discussion. We do binary search on the list of V to find the largest index i ∈ [1, t] such that q can cover the vertices V [1, i]. If no such i exists in [1, t], then let i = 0. Such an index i can be found in O(log 2 r) time using the line-constrained 2D sublist LP queries of Lemma 2, as shown in the following lemma. Recall that in our preprocessing, each vertex of V defines two upper half-planes in R 2 , and we have built a 2D sublist LP query data structure on all upper half-planes defined by the vertices of V . Let q ′ be the point on the x-axis of R 2 with x-coordinate equal to −sup(P ). Let l be the vertical line through q ′ and let p be the lowest point on l that is in the common intersection of all upper half-planes defined by the vertices of V [1, i]. An observation is that q can cover all vertices of V [1, i] if and only if the y-coordinate of p is at most λ, which can be determined in O(log r) time by a line-constrained 2D sublist LP query.
If q can cover all vertices of V [1, i], then we continue the search on the indices larger than i; otherwise, we continue the search on the indices smaller than i. If q cannot cover the vertices of V [1, i] for i = 1, then we return i = 0. The total time is O(log 2 r).

⊓ ⊔
If i = t, then all vertices of V can be covered by q. In this case, we reset sup(P ) = min{sup(P )− where the latter value is the distance from v m to the center at the twig e(v b , w g ).
If i < t (this includes the case i = 0), then we increase i by one and reset count = count+ncen(i).
. Otherwise, we need to place an additional center on P to cover the uncovered vertices of P including v(i), and thus we increase count by one and reset sup( The case sup(P ) > dem(P ). In this case, we need to first deal with dem(P ), i.e., covering the vertices in the children stems of P that are not covered.
If dem(P ) ≥ d(v 1 , w a ) − λ/w(w a ), then the center at the twig e(v a , w a ) can cover the uncovered vertices in the children stems of P . In this case, we increase count by ncen(1). If w(v(1)) · d(v(1), v m ) < λ, then we postpone placing centers to the next stem and reset dem( . Otherwise, we increase count by one and reset If dem(P ) < d(v 1 , w a ) − λ/w(w a ), then we do binary search to find the largest index i ∈ [1, t] such that we can find a center q on the backbone of P to cover all vertices of V [1, i] with d(v 1 , q) ≤ dem(P ). If such an index i does not exit, then we let i = 0. The following lemma shows that such an index i can be found in O(log 3 r) time. Proof. Given any index i, we first show that we can determine in O(log 2 r) time the answer to the following question: whether there exists a center q on the backbone of P that can cover all vertices of V [1, i] with d(v 1 , q) ≤ dem(P )?
By a 2D sublist LP query on the upper half-planes defined by the vertices of V [1, i], we compute the lowest point p in the common intersection of these half-planes. If y(p) > λ, then the answer to the question is no. Otherwise, if x(p) ≤ dem(P ), then the answer to the question is yes. If x(p) > dem(P ), then let l be the vertical line whose x-coordinate is dem(P ). By a line-constrained 2D sublist LP query, we can compute the lowest point p ′ on l in the above common intersection of upper half-planes in O(log r) time. If y(p ′ ) ≤ λ, then the answer to the above question is yes; otherwise the answer is no. The total time to determine the answer to the question is O (log 2 r).
If the answer is yes, then we continue the search on indices larger than i; otherwise we continue on indices smaller than i. If the answer to the question is no for i = 1, then we return i = 0. The total running time is O(log 3 r).
If i = t (this includes the case i = 0), then we increment i by one and increase count by 1+ncen(i), where the additional one is for placing a center to cover dem(P ). If w(v(i))·d(v(i), v m ) < λ, then we reset dem(P ) = λ/w(v(i)) − d(v(i), v m ) and sup(P ) = d(w b , v m ) − λ/w(w b ). Otherwise, we increase count by one and reset sup( This finishes the processing of the stem P . After the stem P γ that contains the root γ is processed, if sup(P γ ) > dem(P γ ), then we place a center at the root γ to cover the uncovered vertices and increase count by one. The value λ is feasible if and only if count ≤ k (note that here k should be the original value from the input). Since we spend O(log 3 r) time on each stem of T c and T c has O(n/r) stems, FTEST1 runs in O(n/r · log 3 r) time.

Phase 2
In this phase, we will finally compute the optimal objective value λ * , using the faster feasibility test FTEST1. Recall that we have computed a range (λ 1 , λ 2 ] that contains λ * after Phase 1. We first form a stem-partition of T . While there is more than one leaf-stem, we do the following. Let S be the set of all leaf-stems. For each stem P ∈ S, we compute the set of lines as in Section 3.1, and let L be the set of the lines for all stems of S. With Lemma 3 and FTEST1, we compute the two vertices v 1 (L) and v 2 (L) of the arrangement A(L) as defined in Section 2. We update λ 1 = max{λ 1 , y(v 2 (L)} and λ 2 = min{λ 2 , y(v 1 (L)}. As discussed in Phase 1, each stem P of S does not have any active values (in the matrices defined by P ). Next, for each stem P of S, we perform the post-processing procedure as in Section 4.2, i.e., place centers on P , subtract their number from k, and replace P by attaching a twig or a thorn to its top vertex. Let T be the modified tree.
After the while loop, T is a single stem. Then, we apply above algorithm on the only stem T , and the obtained value λ 2 is λ * . The running time of Phase 2 is bounded by O(n log n), which is analyzed in the following theorem. First of all, as in [16], the number of iterations of the while loop is O(log n) because the number of leaf-stems is halved after each iteration. In each iteration, let n ′ denote the total number of backbone vertices of all leaf-stems in S. Hence, |L| = O(n ′ ). Thus, the call to Lemma 3 with FTEST1 takes O((n ′ + n/r · log 3 r) log n ′ ) time. The total time of the post-processing procedure for all leaf-stems of S is O(n ′ ). Since all leaf-stems of S will be removed in the iteration, the total sum of all such n ′ is O(n) in Phase 2. Therefore, the total time of the algorithm in Lemma 3 in Phase 2 is O(n log n + n/r · log 3 r log 2 n), which is O(n log n) since r = log 2 n. Also, the overall time for the post-processing procedure in Phase 2 is O(n). Therefore, the total time of Phase 2 is O(n log n). This proves the theorem.

The Discrete k-Center Problem
In this section, we extend our techniques to solve in O(n log n) time the discrete k-center problem on T where centers must be located at the vertices of T . In fact, the problem becomes easier due to the following observation.

Observation 1
The optimal objective value λ * is equal to w(v) · d(v, u) for two vertices u and v of T (i.e., a center is placed at u to cover v).
The previous O(n log 2 n) time algorithm in [26] relies on this observation. Megiddo et al. [26] first computed in O(n log 2 n) time a collection of O(n log n) sorted subsets that contain the intervertex distances d(u, v) for all pairs (u, v) of vertices of T . By multiplying the weight w(v) by the elements in the subsets corresponding to each vertex v, λ * is contained in these new sorted subsets. Then, λ * can be computed in O(n log 2 n) time by searching these sorted subsets, e.g., using MSEARCH. Frederickson and Johnson [17] later proposed an O(n log n)-time algorithm that computes a succinct representation of all intervertex distances of T by using sorted Cartesian matrices. With MSEARCH, their algorithm solves the unweighted case of the problem in O(n log n) time. However, their techniques may not be generalized to solving the weighted case because once we multiply the vertex weights by the elements of those Cartesian matrices, the new matrices are not sorted any more (i.e., we cannot guarantee that both columns and rows are sorted because different rows or columns are multiplied by weights of different vertices).
Our algorithm uses similar techniques as those for the previous non-direcrete k-center problem. In the following we briefly discuss it and mainly focus on pointing out the differences.
First of all, we need to modify the feasibility test algorithm FTEST0. The only difference is that when sup(u) ≤ dem(u) and dem(u) < d(u, v), instead of placing a center in the interior of the edge e(u, v), we place a center at u and update sup(v) = min{sup(v), d(u, v)} (i.e., use this to replace Line 11 in the pseudocode of Algorithm 1). The running time is still O(n). We use DFTEST0 to denote the new algorithm.

The Algorithm for Stems
The stem is defined slightly differently than before. Suppose we have a range (λ 1 , λ 2 ] that contains λ * . Each backbone vertex v i of a stem P still has at most one thorn and one twig. The thorn e(u i , v i ) is defined in the same way as before. However, a twig now consists of two edges e(v i , b i ) and e(b i , w i ) such that w(w i )·d(w i , v i ) ≥ λ 2 and w(w i )·d(w i , b i ) ≤ λ 1 , which means that we have to place a center at b i to cover w i under any λ ∈ (λ 1 , λ 2 ). We still call w i a twig vertex, and following the terminology in [16], we call b i a bud.
Next we give an algorithm to solve the k-center problem on a stem P of m backbone vertices. The algorithm is similar to that in Section 3.2 and uses MSEARCH, but we use a different way to form matrices based on Observation 1. (Note that we will not need a similar algorithm as that in Section 3.1.) Let λ * temporarily refer to the optimal objective value for the k-center problem on P in this subsection, and we assume λ * ∈ (λ 1 , λ 2 ]. Let v 1 , v 2 , . . . , v m be the backbone vertices of P . We again assume that all backbone vertices are in the x-axis such that v 1 is at the origin and v i has x-coordinate d(v 1 , v i ). As in Section 3.1, for each thorn vertex u i , we define two points u l i and u r i on the x-axis (whose weights are equal to w(u i )), and we do the same for each bud and each twig vertex. Let P be the set of all vertices on the x-axis. Hence, |P| ≤ 7m.
We sort all vertices of P from left to right, and let the sorted list be z 1 , z 2 , . . . , z t for t ≤ 7m. For any z i , we use x(z i ) to denote its x-coordinate. For each vertex z i , we define two sorted arrays A l i and A r i of lengths at most t as follows.

Solving the Problem in T
In the sequel, we solve the discrete k-center problem in T . First, we do the same preprocessing as in Section 4.1. Then, we have three phases as before. Let r = log 2 n.

Phase 0
We assume that T has more than 2n/r leaves since otherwise we could skip this phase. Phase 0 is the same as before except the following changes. First, we use DFTEST0 to replace FTEST0. Second, we form the matrix set M in the way discussed in Section 5.1. Third, for each leaf-stem P without active values, we modify the post-processing procedure as follows.
Let z be the top vertex of P . We run DFTEST0 on P with z as the root and λ = λ ′ as any value in (λ 1 , λ 2 ). As before, after z is processed, depending on whether sup(z) ≤ dem(z), there are two main cases.
The case sup(z) ≤ dem(z). If sup(z) ≤ dem(z), we define q and V (q) in the same way as before but V (q) should not include bud vertices. A difference is that q now is a vertex of P . Note that q = z because in this case we do not need to place a center at z.
Let w be the vertex that makes q as a center. Specifically, refer to the pseudocode in Algorithm 1, where we place a center q at vertex u at Line 10. Let w be the vertex that determines the value dem(u), i.e., dem(u) = λ ′ /w(w) − d(w, u). Note that w must be a descendent of u (= q). In this case, we replace P by a twig consisting of two edges e(z, q) and e(q, w) with lengths equal to d(z, q) and d(q, w), respectively. To find the vertex w, one way is to modify DFTEST0 so that the vertex that determines the value dem(v) for each vertex v of T is also maintained. Another way is that w is in fact the vertex of V (q) with the largest rank, which is proved in the following lemma (whose proof is similar to that of Lemma 6). Note that this is actually consistent with our way for creating twigs in the previous non-discrete case.
Lemma 16. w is the vertex of V (q) with the largest rank.
Proof. Let v be any vertex of V (q) \ {w}. Our goal is to show that rank(w) > rank(v). Note that q is either a backbone vertex or a bud.
We first discuss the case where q is a backbone vertex. We define V 1 (q) to be the set of vertices of V (q) in the subtree rooted at q and let V 2 (q) = V (q) \ V 1 (q). Depending on whether v is in V 1 (q) or V 2 (q), there are two subcases.
If v ∈ V 1 (q), assume to the contrary that rank(w) < rank(v). Recall that v defines a line l(v) and w defines a line l(w) in R 2 in the preprocessing (see Section 4.1). Refer to Fig. 7. Let p v and p w denote the intersections of the horizontal line y = λ ′ with l(v) and l(w), respectively. Since λ ′ ∈ (λ 1 , λ 2 ), by the definition of ranks, x(p w ) < x(p v ). Note that x(p v ) corresponds to a point q v in π(v, γ) in the sense that x(p v ) = d(γ, q v ), and q v is actually the point on π(v, γ) closest to γ that can cover v. Similarly, x(p w ) corresponds to a point q w in π(w, γ). Since x(p w ) < x(p v ), d(γ, q w ) < d(γ, q v ). One can verify that this contradicts with that w is the vertex that makes q as a center (i.e., w determines the value dem(u)), because both v and w are descendants of q.
If v ∈ V 2 (q), first note that v cannot be a twig vertex since otherwise q would need to be a bud in order to cover v. Depending on whether v is a backbone vertex or a thorn vertex, there are two subcases.  1. If v is a backbone vertex, then v is an ancestor of q. Let p v and p w be the intersections of the horizontal line y = λ ′ with l(v) and l w , respectively (e.g., see Fig. 8). Since w determines the center q and v is an ancestor of q, according to DFTEST0, it holds that w(w)·d(w, v) < λ ′ . Since q is an ancestor of w, v is also an ancestor of w. Therefore, the point p(v) (i.e., the intersection of l(v) with the x-axis) must be to the left of the vertical line through p w . Since l(v) is not positive, this implies that x(p v ) < x(p w ). Because λ ′ ∈ (λ 1 , λ 2 ), we obtain that rank(v) < rank(w). 2. If v is a thorn vertex, assume to the contrary that rank(w) < rank(v). Let v ′ be the backbone vertex that connects v. Since v ∈ V 2 (q) and q is a backbone vertex, v ′ must be an ancestor of q. Because rank(w) < rank(v), in the following we will prove w(v) · d(v, q) > λ ′ , which implies that q cannot cover v and thus incurs contradiction. By our preprocessing in Section 4.1, the vertex v ′ defines a point p(v ′ ) in the x-axis of R 2 (e.g., see Fig. 9). With a little abuse of notation, we use x(v ′ ) to denote the x-coordinate of p(v ′ ). We define p v and p w in the same way as before.
Since w determines q and v ′ is an ancestor of q, according to DFTEST0, it holds that w(w) · d(w, v ′ ) < λ ′ . This implies that x(v ′ ) < x(p w ). Since rank(w) < rank(v) and λ ′ ∈ (λ 1 , λ 2 ), x(p w ) < x(p v ). Thus, x(v ′ ) < x(p v ) and the y-coordinate of the intersection of the vertical line through p(v ′ ) and l(v) is larger than λ ′ . Note that the above y-coordinate is equal to The above proves that rank(w) > rank(v) for the case where q is a backbone vertex.
Next we discuss the case where q is a bud. Since w is a descendent of q, w must be a twig vertex on the same twig as q. Let v ′ be the backbone vertex that connects q. We say that v is above v ′ if π(z, v ′ ) either contains v (when v is a backbone vertex) or contains the backbone vertex that connects v (when v is a thorn vertex); otherwise, v is below v ′ . If v is above v ′ , then the analysis is similar to the above subcase v ∈ V 2 (q). We omit the details. In the following, we analyze the case where v is below v ′ . Although v may be either a backbone vertex or a thorn vertex, we prove rank(w) > rank(v) in a uniform way.
Assume to the contrary that rank(w) < rank(v). Again, refer to Fig. 9. We define the points in the figure in the same way as before except that v ′ is now the backbone vertex that connects q. Our goal is to show that w(v) · d(v, q) > λ ′ , which incurs contradiction since q covers v. To this The proof is similar to the above subcase where v is a thorn vertex, and we briefly discuss it below.
Since w determines q and v ′ is an ancestor of q, it holds that w(w) · d(w, v ′ ) < λ ′ . This implies that x(v ′ ) < x(p w ). Since rank(w) < rank(v) and λ ′ ∈ (λ 1 , λ 2 ), x(p w ) < x(p v ). Thus, x(v ′ ) < x(p v ) and the y-coordinate of the intersection of the vertical line through p(v ′ ) and l(v) is larger than λ ′ . Again, the above y-coordinate is equal to This proves the lemma.

⊓ ⊔
The above replaces P by attaching a twig e(z, q) ∪ e(q, w) to z. In addition, if z already has another twig with bud q ′ , then we discard the new twig if d(q, z) ≥ d(q ′ , z) and discard the old twig otherwise. This guarantees that z has at most one twig.
The case sup(z) > dem(z). If sup(z) > dem(z), then we define V in the same way as before but excluding the buds. Let u be the vertex of V with the largest rank. As before in Lemma 7, u dominates all other vertices of V and thus we replace P by a thorn e(u, z) whose length is equal to d(u, z). In addition, if z already has another thorn e(z, u ′ ), then as before (and for the same reason), we discard one of u and u ′ whose rank is smaller.
This finishes the post-processing procedure on P . The running time is still O(m). By similar analysis as in Lemma 9, Phase 0 still runs in O(n log n) time and we omit the details.

Phase 1
First of all, we still form a stem-tree T c as before and each node represents a substem of length at most r. Instead of using the line arrangement searching technique, we now resort to MSEARCH. Let S be the set of all substems. Let M be the set of matrices of all these substems formed in the way described in Section 5.1. We apply MSEARCH on M with stopping count c = 0 and using DFTEST0. Since M has O(n) arrays of lengths O(r), MSEARCH will produce O(log n) values for feasibility tests in O(n log r) time. The total feasibility test time is O(n log n). Since c = 0, after MSEARCH stops, we have an updated range (λ 1 , λ 2 ) and no matrix element of M is active. Let λ be an arbitrary value in (λ 1 , λ 2 ).
We will compute a data structure for each stem P of S so that the feasibility test can be made in sublinear time. We will show that after O(n log n) time preprocessing, each feasibility test can be done in O(n/r log 3 r) time. Let P be a substem with backbone vertices v 1 , v 2 , . . . , v m , with v m as the top vertex. The preprocessing algorithm works in a similar way as before.
The cleanup procedure. Again, we first perform a cleanup procedure to remove all vertices of P that can be covered by the centers at the buds of the twigs. Note that all buds and twig vertices can be automatically covered by the centers at buds. So we only need to find those backbone and thorn vertices that can be covered by buds. This is easier than before because the locations of the centers are now fixed at buds.
We use the following algorithm to find all backbone and thorn vertices that can be covered by buds to their left sides. Let i ′ be the smallest index such that v i ′ has a bud b i ′ . The algorithm maintains an index t. Initially, t = i ′ . For each i incrementally from i ′ to m, we do the following.
then we mark v i as "covered". If u i exits and w(u i ) · d(u i , b t ) ≤ λ, then we mark u i as "covered". Note that although u i is not an ancestor or a descendent of b t , we can still compute d( , and the latter two distances can be computed in O(1) time due to the preprocessing in Section 4.1.
The above algorithm runs in O(m) time. In a symmetric way by scanning P from right to left, we can also mark all backbone and thorn vertices that are covered by buds to their right sides. This finishes the cleanup procedure. Again, we define V in the same way as before, and let v ′ in the same way as before.
Computing the data structure. In the sequel, we compute a data structure for P . As before, we maintain an index a of a twig such that d( For each i ∈ [1, t], we will also compute an integer ncen(i) and a vertex v(i) of V , whose definitions are similar as before. In addition, we maintain another vertex q(i). The details are given below. Define j i similarly as before, i.e., it is the smallest index in [i, t] such that it is not possible to cover all vertices in V [i, j i ] by a center located at a vertex of P under λ. Again, if such an index does not exist in V [i, t], then let j i = t + 1.
If j i = t + 1, then we define ncen(i) = 0, and define v(i) as the vertex in V [i, t] with the largest rank. We should point out our definition on v(i) is consistent with before, which was based on rank ′ (l + (v)) for v ∈ V , because for any two vertex v and v ′ in V , rank(v) > rank(v ′ ) if and only if rank ′ (l + (v)) < rank ′ (l + (v ′ )). With the same analysis as before, v(i) dominates all other vertices of V [i, t]. We define q(i) as follows.
Therefore, q(i) refers to the index of the backbone vertex closest to v m that can cover v(i), and by the definition of v(i), q(i) can also cover all other vertices of V [i, t] (the proof is similar to Lemma 12 and we omit it).
To compute ncen(i), v(i), and q(i) for all i ∈ [1, t], observe that once v(i) is known, q(i) can be computed in additional O(log m) time by binary search on the backbone vertices of P . Therefore, we will focus on computing ncen(i) and v(i). We use a similar algorithm as that in Lemma 13. To this end, we need to solve the following subproblem: Given any two indices i ≤ j in [1, t], we want to compute the optimal objective value, denoted by α ′ (i, j), of the discrete one-center problem on the vertices of V [i, j]. This can be done in O(log 2 m) time by using the 2D sublist LP query data structure, as shown in the following lemma. Proof. As preprocessing, in O(t log t) time we build the 2D sublist LP query data structure on the upper half-planes defined by the vertices of V in the same way as before.
Given any indices i ≤ j in [1, t], by a 2D sublist LP query, we compute in O(log 2 t) time the lowest point p in the common intersection C of the upper half-planes defined by the vertices of V [i, j]. Let q be the point on the backbone of P corresponding to the x-coordinate of p (i.e., d(v 1 , q) = x(p)). Note that q is essentially the optimal center for the non-discrete one-center problem on the vertices of V [i, j]. But since we are considering the discrete case, the optimal center q ′ for the discrete problem can be found as follows. If q is located at a vertex of P , then q ′ = q and α ′ (i, j) is equal to the y-coordinate of p. Otherwise, let v and v ′ be the two backbone vertices of P immediately on the left and right sides of q, respectively. Then, q ′ is either v or v ′ , and this is because the boundary of C, which is the upper envelope of the bounding lines of the upper half-planes defined by the vertices of V [i, j], is convex. To compute α ′ (i, j), we do the following. Let l v be the line in R 2 whose x-coordinate is equal to d(v 1 , v). Defined l v ′ similarly. Let p v be the lowest point of l v in C. Define p v ′ similarly. Then, α ′ (i, j) is equal to the y-coordinate of the lower point of p v and p v ′ , and the center q ′ can also be determined correspondingly. Both v and v ′ can be found by binary search on the backbone vertices of V in O(log m) time. The point p v (resp., p v ′ ) can be found by a line-constrained 2D sublist LP query in O(log t) time.
Since t ≤ m, we can compute α ′ (i, j) in O(log 2 m) time.

⊓ ⊔
With the preceding lemma, we can use a similar algorithm as in Lemma 13 to compute ncen(i) and v(i) for all i ∈ Recall that m ≤ r. Hence, the preprocessing time for P is O(r log 2 r), which is O(r(log log n) 2 ) time since r = log 2 n. The total time for computing the data structure for all substems of S is O(n(log log n) 2 ). With these data structures, we show that a feasibility test can be done in O(n/r log 3 r) time.
compute the lowest point p ′ on l in the common intersection of the upper half-planes defined by the vertices of V [1, i]. The answer is yes if and only if the y-coordinate of p ′ is at most λ. Hence, the time to determine the answer to the above question is O(log 2 r). Therefore, the time for implementing Line 28 is O(log 3 r).
In addition, it is easy to see that the time of the binary search in Line 33 is O(log r). Therefore, processing P takes O(log 3 r) time, and the total time of DFTEST1 is O(n/r log 3 r), the same as before.

Phase 2
This phase is the similar as before with the following changes. First, we use DFTEST1 to replace FTEST1. Second, we use the new post-processing procedure. Third, instead of using the line arrangement searching technique, we use MSEARCH. Specifically, in the pseudocode of Algorithm 3, we replace Lines 19 and 20 (and also Lines 23 and 24 ) by the following. For each leaf-stem of S, we form the matrices for P in the way discussed in Section 5.1, and let M denote the set of matrices for all leaf-stems of S. Then, we call MSEARCH on M with stopping count c = 0 and DFTEST1.
The running time of all three phases is still O(n log n), as shown in Theorem 2.

Algorithm 2: The faster feasibility test algorithm FTEST1
Input: The stem-tree Tc, the original k from the input, and λ ∈ (λ1, λ2) Output: Determine whether λ is feasible 1 count ← 0; 2 for each stem P of the stem tree Tc do