11institutetext:
Department of Computer Science
Utah State University, Logan, UT 84322, USA
11email: [email protected], [email protected]
A Linear-Time Algorithm for Radius-Optimally Augmenting Paths in a Metric Space††thanks: A preliminary version of this paper will appear in the Proceedings of the 16th Algorithms and Data Structures Symposium (WADS 2019).
Christopher Johnson
Haitao Wang
Abstract
Let P be a path graph of n vertices embedded in a metric space. We consider the problem of adding a new edge to P to minimize the radius of the resulting graph. Previously, a similar problem for minimizing the diameter of the graph was solved in O(nlogn) time. To the best of our knowledge, the problem of minimizing the radius has not been studied before. In this paper, we present an O(n) time algorithm for the problem, which is optimal.
1 Introduction
In this paper, we consider the problem of augmenting a path graph embedded in a metric space by adding a new edge so that the radius of the new graph is minimized.
Let P be a path graph of n vertices, v1,v2,…,vn, ordered from one end to the other. Let e(vi,vi+1) denote the edge connecting two vertices vi and vi+1 for i∈[1,n−1].
Let V be the set of all vertices of P. We assume that P is embedded in a metric space, i.e., (V,∣⋅∣) is a metric space and ∣vivj∣ is the distance of any two vertices vi and vj of V.
Specifically, the following properties hold: (1) the triangle inequality:
∣vivk∣+∣vkvj∣≥∣vivj∣; (2) ∣vivj∣=∣vjvi∣≥0; (3) ∣vivj∣=0 iff i=j.
For each edge e(vi,vi+1) of P, its length is equal to
∣vivi+1∣.
Suppose we add a new edge e connecting two vertices vi and vj of P, and let P∪{e} denote the resulting graph. Note that a point of P can be either a vertex of P or in the interior of an edge.
A point c on P∪{e} is called a center if it minimizes
the largest shortest path length from c to all vertices of P, and
the largest shortest path length from the center to all vertices is called the radius.
Our problem is to add a new edge e to connect two vertices of P such that the radius of P∪{e} is minimized. We refer to the problem as the radius-optimally augmenting path
problem, or ROAP for short.
To the best of our knowledge, the problem has not been studied before.
In this paper, we present an O(n) time algorithm. We assume that the distance ∣vivj∣ can be obtained in O(1) time for any two vertices vi and vj of P.
As a by-product of our techniques, we
present an algorithm that can compute the radius and the center of
P∪{e} in O(logn) time for any given new edge e, after O(n) time
preprocessing.
1.1 Related Work
A similar problem for minimizing the diameter of the augmenting graph was studied before. Große et
al. [10] first gave an O(nlog3n) time algorithm, and later Wang [17] solved the problem in O(nlogn) time.
Some variations of the diameter problem have also been considered in the literature.
If the path P is in the Euclidean space Rd for a constant d, then Große et
al. [10] gave an O(n+1/ϵ3) time
algorithm that can find a (1+ϵ)-approximate solution for
the diameter problem, for any ϵ>0. If P is in the Euclidean plane R2,
De Carufel et al. [6] gave a linear time algorithm for
adding a new edge to P to minimize the continuous diameter
(i.e., the diameter is defined with respect to all points of P, not only vertices).
For a geometric tree T of n vertices embedded in the Euclidean plane, De Carufel et al. [7] gave an O(nlogn) time algorithm for
adding a new edge to T to minimize the continuous diameter. For the discrete diameter problem where T is embedded in a metric space, Große et al. [11] first proposed an O(n2logn) time algorithm and later Bilò [4] solved the problem in O(nlogn) time.
Oh and Ahn [15] studied the problem on a general tree (i.e., the tree is not embedded in a metric space) and gave O(n2log3n) time algorithms for both the discrete and continuous versions of the diameter problem, and later Bilò [4] gave an improved algorithm of O(n2) time for the discrete case, which is optimal.
The more general problem of adding k edges to a graph G so that the diameter of the resulting graph is minimized has also been considered before. The problem is NP-hard [16] and some other variants are even W[2]-hard [8, 9]. Approximation algorithms have been proposed [5, 8, 14].
The upper and lower bounds on the diameters
of the augmented graphs were also studied, e.g., [1, 13].
Bae et al. [2] considered the problem of adding k shortcuts to a circle in the plane to minimize the diameter of the resulting graph.
Like the diameter, the radius is a critical metric of network performance, which
measures the worst-case cost between a “center” and all other nodes. Therefore, our problem of
augmenting graphs to minimize the radius potentially has many applications.
As an example, suppose there is a highway that connects several cities and we want to build a facility along the highway to provide certain service for all these cities. In order to reduce the transportation time, we plan to build a new highway connecting two cities such that the radius (i.e., the maximum distance from the cities to the facility located at the center) is as small as possible.
1.2 Our Approach
Note that in general the radius of P∪{e}
is not equal to the diameter divided by two. For example, suppose
e connects v1 and vn (i.e., P∪{e} is a cycle).
Assume that the edges of the cycle have the same length and n is
even. Suppose the total length of the cycle is 1. Then, the diameter of the
cycle is 1/2 while the radius is (1−1/n)/2, very close to the diameter.
One straightforward way to solve the problem ROAP is to try all edges
e connecting vi and vj for all i,j∈[1,n], which would
take Ω(n2) time. We instead use the following approach. Suppose an optimal edge e connecting two vertices vi∗ and vj∗. Depending on the locations of the center c∗ and its two farthest vertices in P∪{e}, there are several possible configurations for the optimal solution (e.g., see Fig. 1).
For each such configuration, we compute the best solution for it in
linear time, such that if there is an optimal solution conforming with the configuration, our solution is also optimal. The efficiency of our approach relies on many observations and certain monotonicity properties, which help us avoid the brute-force method. In fact, our algorithm, which involves several kinds of linear scans, is relatively simple. The challenge, however, is on discovering and proving these observations and properties. To this end, our main tool is the triangle inequality of the metric space.
Outline.
The remaining paper is organized as follows.
In Section 2, we introduce some notation.
In Section 3, we present our linear time algorithm for ROAP.
In Section 4, we discuss our O(logn) time query algorithm for computing the radius and the center of P∪{e}.
2 Preliminaries
Denote by e(vi,vj) the edge connecting two vertices
vi and vj for any i,j∈[1,n]. The length of
e(vi,vj) is ∣vivj∣.
This implies that for any two points p and q on e(vi,vj), the length of the portion of e(vi,vj) between p and q is ∣pq∣.
Later we will use this property directly without further explanations.
For any two points p and q on P, we use P(p,q) to denote the
subpath of P between p and q.
Unless otherwise stated, we assume i≤j for each index pair
(i,j) discussed in the paper. For any pair (i,j), we use G(i,j) to
denote the new graph P∪{e(vi,vj)} and use C(i,j) to denote the cycle
P(vi,vj)∪e(vi,vj).
Note that if j≤i+1, then G(i,j)=P and C(i,j)=P(vi,vj).
For any graph G, we use dG(p,q) to denote the length of the shortest
path between two points p and q in G, and we also call
dG(p,q) the distance between p and q in G. In our
paper, G is usually a subgraph of G(i,j), e.g., P or C(i,j).
For example, dP(p,q) denotes the length of P(p,q).
We perform a linear time preprocessing so that dP(vi,vj) can be computed in O(1) time for any pair of (i,j). Recall that ∣vivj∣>0 unless i=j, and thus, dP(vi,vj)>0 unless i=j.
A center of G(i,j) is defined as a point (which can be either a vertex or in the interior of an edge) that minimizes the maximum distance from it to all vertices in G(i,j)111The concept of center is defined with respect to the graph instead of to the metric space., and the maximum distance is called the radius of G(i,j). Hence, the problem ROAP is to find a pair of
indices (i,j) such that the radius of G(i,j) is
minimized.
For convenience, we assume that P from v1 to vn is oriented
from left to right, so that we can talk about the relative positions of
the points of P (i.e., a point p is to the left of another point
q on P if p is closer to v1 than q is).
Similarly, each edge e(vi,vj) with i<j from vi to vj
is oriented from left to right.
3 Our Algorithm for ROAP
In this section, we present our algorithm for solving the problem ROAP. Let (i∗,j∗) be an
optimal solution with i∗≤j∗ and c∗ be a center of G(i∗,j∗). Let r∗
denote the radius of G(i∗,j∗). We begin with the following observation.
Observation 1
In G(i∗,j∗), there are two vertices va∗ and vb∗ such that the following are true.
-
dG(i∗,j∗)(c∗,va∗)=dG(i∗,j∗)(c∗,vb∗)=r∗.
2. 2.
There is a shortest path from c∗ to va∗, denoted by πa∗, and a shortest path from c∗ to vb∗, denoted by πb∗, such that c∗ is at the middle of πa∗∪πb∗ (i.e., the concatenation of the two paths).
Proof
If this were not true, then we could slightly move c∗ so that the maximum distance from the new position of c∗ to all vertices in G(i∗,j∗) becomes smaller than r∗, which contradicts with the definition of r∗. ∎
Let a∗ and b∗ be the indices of the two vertices va∗ and vb∗, and π∗ be the union of the two paths πa∗ and πb∗ stated in Observation 1. Without loss of generality, we assume a∗<b∗.
Depending on the locations of c∗, a∗, b∗, as well as whether
e(vi∗,vj∗)∈π∗, there are several possible
configurations. For each configuration, we will give a linear time
algorithm to compute a candidate solution, i.e., a pair (i,j) (along with a radius r and a center c), so that if there is an optimal solution conforming with the configuration then (i,j) is also an optimal solution with c as the center and r=r∗. On the other hand, each such solution is feasible in the sense that the distances from c to all vertices in G(i,j) is at most r. There are a constant number of configurations. Since we do not know which configuration has an optimal solution, we will compute a candidate solution for each configuration, and finally, among all candidate solutions we return the one with the smallest radius. The running time of the algorithm is O(n).
For example, one
configuration is that a∗=1 and c∗ is on P(v1,vi∗). In
this case, r∗ is equal to dP(v1,c∗) and also equal to
dP(c∗,vi∗) plus the distance from vi∗ to its
farthest vertex vk for all k∈[i∗,n], i.e., maxk∈[i∗,n]dG(i∗,j∗)(vi∗,vk).
In other words, r∗ is equal to half of
dP(v1,vi∗)+maxk∈[i∗,n]dG(i∗,j∗)(vi∗,vk).
Further, it can be verified that j∗ must be the index j that
minimizes the value maxk∈[i∗,n]dG(i∗,j)(vi∗,vk) among all j∈[i∗,n]. Therefore, r∗ is equal to half of
dP(v1,vi∗)+minj∈[i∗,n]maxk∈[i∗,n]dG(i∗,j)(vi∗,vk). Also, since c∗∈P(v1,vi∗),
dP(v1,vi∗)≥maxk∈[i∗,n]dG(i∗,j∗)(vi∗,vk).
Correspondingly, we can compute a candidate solution as follows.
For any i∈[1,n], define λi=minj∈[i,n]maxk∈[i,n]dG(i,j)(vi,vk), and let j(i) denote the index j∈[i,n] that
achieves λi. Suppose λi and j(i) for all i∈[1,n] are known. Then, in O(n) time we can find the index i that
minimizes the value dP(v1,vi)+λi among all i∈[1,n]
with dP(v1,vi)≥λi. We return the pair (i,j(i)) (with radius r=(dP(v1,vi)+λi)/2 and center c as the point on P(v1,vi) such that dP(v1,c)=r) as the
candidate solution for the configuration.
It is not difficult to see that if the configuration has an optimal
solution, then (i,j(i)) is an optimal solution with the center at c and r∗=r.
Further, by our definition of λi, the distance from c to every vertex in G(i,j(i)) is at most r, and thus our candidate solution is feasible.
According to the above discussion, we need to compute λi and
j(i) for all i∈[1,n], which is done in the following lemma, with proof in Section 3.1.
Lemma 1
There is an algorithm that can compute λi and j(i) in O(n) time for all i∈[1,n].
3.1 The Algorithm for Lemma 1
The success of our approach hinges on several monotonicity properties
that we shall prove.
Consider any i∈[1,n].
For any j∈[i,n], define α(i,j)=maxk∈[i,n]dG(i,j)(vi,vk), β(i,j)=maxk∈[i,j]dG(i,j)(vi,vk), and γ(i,j)=maxk∈[j+1,n]dG(i,j)(vi,vk) if j<n and γ(i,j)=0 otherwise. Clearly, α(i,j)=max{β(i,j),γ(i,j)} and λi=minj∈[i,n]α(i,j).
Note that for any k∈[i,j], the shortest path from vi to vk in G(i,j) must be in the cycle C(i,j). Hence, β(i,j)=maxk∈[i,j]dC(i,j)(vi,vk). Also, it is not difficult to see that γ(i,j)=dG(i,j)(vi,vn). For dG(i,j)(vi,vn), there are two paths from vi to vn in G(i,j): P(vi,vn) and e(vi,vj)∪P(vj,vn). The length of the latter path is ∣vivj∣+dP(vj,vn). Due to the triangle inequality in the metric space, it holds that ∣vivj∣≤dP(vi,vj). Hence,
γ(i,j)=∣vivj∣+dP(vj,vn).
Our first monotonicity property is given in the following
lemma, which is due to the triangle inequality.
Lemma 2
γ(i,j)≥γ(i,j+1)* for all j∈[i,n−1].*
Proof
Since γ(i,j)=∣vivj∣+dP(vj,vn) and
γ(i,j+1)=∣vivj+1∣+dP(vj+1,vn), we have
γ(i,j)−γ(i,j+1)=∣vivj∣+dP(vj,vj+1)−∣vivj+1∣=∣vivj∣+∣vjvj+1∣−∣vivj+1∣≥0. The last inequality
is due to the triangle inequality. ∎
Let I(i,j) be the index k in [i,j] such that
β(i,j)=dC(i,j)(vi,vk) (if there more than
one such k, then we let I(i,j) refer to the smallest one). In our algorithm given later, we will need to compute β(i,j) for some pairs (i,j).
For each k∈[i,j], observe that
dC(i,j)(vi,vk)=min{dP(vi,vk),∣vivj∣+dP(vk,vj)}.
Hence, if I(i,j) is known, then β(i,j) can be computed in constant time due to our preprocessing in Section 2.
In order to determine I(i,j), we introduce a new notation.
Define I′(i,j) to be the smallest index k∈[i,j] such that dP(vi,vk)≥∣vivj∣+dP(vk,vj). Note that such k must exist since dP(vi,vj)≥∣vivj∣.
Observation 2
I(i,j)* is either I′(i,j) or I′(i,j)−1.*
Proof
Let h=I′(i,j). We first assume that h>i. By the definition of I′(i,j), dP(vi,vh)≥∣vivj∣+dP(vj,vh) and dP(vi,vh−1)<∣vivj∣+dP(vj,vh−1). Thus, dC(i,j)(vi,vh)=∣vivj∣+dP(vj,vh) and dC(i,j)(vi,vh−1)=dP(vi,vh−1).
Consider any k∈[i,j].
If k>h, then dC(i,j)(vi,vh)=∣vivj∣+dP(vj,vh)≥∣vivj∣+dP(vj,vk)≥dC(i,j)(vi,vk).
If k<h−1, then dC(i,j)(vi,vh−1)=dP(vi,vh−1)>dP(vi,vk)≥dC(i,j)(vi,vk). Note that dP(vi,vh−1)>dP(vi,vk) holds because dP(vi,vh−1)=dP(vi,vk)+dP(vk,vh−1) and dP(vk,vh−1)>0. Therefore, one of h and h−1 must be I(i,j).
If h=i, since dP(vi,vh)=0, by the definition of h, it must be the case that i=j. Thus, I(i,j)=i=h.
∎
Observation 2 tells that if we know I′(i,j), then β(i,j) is equal to the minimum of dC(i,j)(vi,vI′(i,j)) and dC(i,j)(vi,vI′(i,j)−1), which can be computed in constant time. Hence, to compute β(i,j), it is sufficient to determine I′(i,j). To efficiently compute I′(i,j) during our algorithm, the following monotonicity properties on I′(i,j) will be quite helpful.
Lemma 3
-
I′(i,j)≤I′(i,j+1)* for all j∈[i,n−1].*
2. 2.
I′(i,j)≤I′(i+1,j)* for all i∈[1,j−1].*
Proof
Recall that dC(i,j)(vi,vk)=min{dP(vi,vk),∣vivj∣+dP(vj,vk)} for each k∈[i,j]. If we
consider k as an integral variable changing from i to j,
then dP(vi,vk) is monotonically increasing and
∣vivj∣+dP(vj,vk) is monotonically decreasing (e.g., see Fig. 2). Hence, in
general dC(i,j)(vi,vk) is a unimodal function of k∈[i,n], i.e., first
increases and then decreases.
Therefore, we have an easy observation:
If dP(vi,vh)≥∣vivj∣+dP(vh,vj) for some h∈[i,j], then I′(i,j)≤h.
For the first part of the lemma, let h=I′(i,j+1). If h=j+1, then it is obviously true that I′(i,j)≤h. Otherwise, h∈[i,j]. By definition, dP(vi,vh)≥∣vivj+1∣+dP(vj+1,vh).
Observe that ∣vivj+1∣+dP(vj+1,vh)≥∣vivj∣+dP(vj,vh) due to
the triangle inequality. Hence, dP(vi,vh)≥∣vivj∣+dP(vj,vh). By the above observation, I′(i,j)≤h.
For the second part of the lemma, let h=I′(i+1,j), and thus dP(vi+1,vh)≥∣vi+1vj∣+dP(vj,vh). Note that dP(vi,vh)−dP(vi+1,vh)=dP(vi,vi+1)=∣vivi+1∣. By the triangle inequality, we have ∣vivj∣+dP(vj,vh)−(∣vi+1vj∣+dP(vj,vh))=∣vivj∣−∣vi+1vj∣≤∣vivi+1∣. Hence, we can derive
dP(vi,vh)=dP(vi+1,vh)+∣vivi+1∣≥(∣vi+1vj∣+dP(vj,vh))+∣vivi+1∣≥∣vivj∣+dP(vj,vh). By the above observation, I′(i,j)≤h.
∎
The following lemma characterizes a monotonicity property of the β values.
Lemma 4
β(i,j)≤β(i,j+1)* for all j∈[i,n−1].*
Proof
Let h=I(i,j). Hence, β(i,j)=dC(i,j)(vi,vh)=min{dP(vi,vh),∣vivj∣+dP(vj,vh)}.
By the triangle inequality, we have ∣vivj∣+dP(vj,vh)≤∣vivj+1∣+dP(vj+1,vh).
Since β(i,j+1)=maxk∈[i,j+1]min{dP(vi,vk),∣vivj+1∣+dP(vj+1,vk)}, we obtain
[TABLE]
∎
Consider any i∈[1,n].
Recall that j(i) is the index j that minimizes the value α(i,j)
for all j∈[i,n], and α(i,j)=max{β(i,j),γ(i,j)}. If we consider
α(i,j), β(i,j), and γ(i,j) as functions of
j∈[i,n], then by Lemmas 2 and 4,
α(i,j) is a unimodal function (first decreases and then increases; e.g., see Fig. 3).
In order to compute j(i) and thus λi during our algorithm,
we define j′(i) to be the smallest index j∈[i,n]
such that γ(i,j)≤β(i,j). Note that such j must exist because γ(i,n)≤β(i,n).
We have the following observation.
Observation 3
j(i)* is either j′(i)−1 or j′(i).*
Proof
By the definition of j′(i), α(i,j′(i))=β(i,j′(i)) and
α(i,j′(i)−1)=γ(i,j′(i)−1).
Consider any k∈[i,n].
If k>j′(i), then α(i,j′(i))=β(i,j′(i))≤β(i,k)≤α(i,k). If k<j′(i)−1, then
α(i,j′(i)−1)=γ(i,j′(i)−1)≤γ(i,k)≤α(i,k).
Therefore, α(i,j) is minimized at either j=j′(i)−1 or j=j′(i).
∎
Our last monotonicity is given in the following lemma, which will help us to determine j′(i).
Lemma 5
j′(i)≤j′(i+1)* for all i∈[n−1].*
Proof
If j′(i)≤i+1, then the lemma is trivially true as j′(i+1)≥i+1. Otherwise, let
h=j′(i)≥i+2. According to the definition of j′(i),
γ(i,h−1)>β(i,h−1). In the following, we prove that
γ(i+1,h−1)>β(i+1,h−1), which would imply that
j′(i+1)≥h=j′(i). To this end, since γ(i,h−1)>β(i,h−1), it is sufficient to prove the following
[TABLE]
Since γ(i,h−1)=∣vivh−1∣+dP(vh−1,vn) and
γ(i+1,h−1)=∣vi+1vh−1∣+dP(vh−1,vn), the above
inequality is equivalent to the following
[TABLE]
Let k=I(i+1,h−1). By definition, we have
β(i+1,h−1)=dC(i+1,h−1)(vi+1,vk)=min{dP(vi+1,vk),∣vi+1vh−1∣+dP(vh−1,vk)}.
Since k∈[i+1,h−1], observe that β(i,h−1)≥min{dP(vi,vk),∣vivh−1∣+dP(vh−1,vk)}.
Further, by the triangle inequality, we have
∣vi+1vh−1∣+dP(vi,vk)=∣vi+1vh−1∣+dP(vi,vi+1)+dP(vi+1,vk)≥∣vivh−1∣+dP(vi+1,vk). Hence, we can derive
[TABLE]
which proves Equation (1).∎
Based on the above several monotonicity properties, we present our linear time algorithm for computing λi and j(i) for all i∈[1,n], as follows.
Recall that we have done preprocessing so that dP(vi,vj) can be computed in O(1) time for any pair (i,j).
Starting with i=1 and j=1, we increment j from 1 to n. For each j, we maintain the four values γ(i,j−1), γ(i,j), β(i,j−1), and β(i,j). So α(i,j−1) and α(i,j) can be obtained in O(1) time. Since γ(i,j)=∣vivj∣+dP(vj,vn), γ(i,j) can be computed in O(1) time, and the same applies to γ(i,j−1). We will explain how to compute the β values later. During the increasing of j, if the first time we find γ(i,j)≤β(i,j), then j′(i)=j. By Observation 3, λi=min{α(i,j−1),α(i,j)}.
Then, we increase i by one (for differentiation, we use i+1 to denote the increased i). By Lemma 5, to determine j′(i+1), we only need to start j from j=j′(i). Following the similar procedure as above, we increase j and maintain γ(i+1,j−1), γ(i+1,j), β(i+1,j−1), and β(i+1,j). Initially when j=j′(i), γ(i+1,j−1) and γ(i+1,j) can be computed in O(1) time as discussed before; for β(i+1,j−1) and β(i+1,j), we will show later that they can be computed in O(1) amortized time.
In this way, the total time for computing λi and j(i) for all i∈[1,n] is O(n).
It remains to describe how to compute the values β(i,j).
As discussed before, by Observation 2, it is sufficient to determine I′(i,j), after which β(i,j) can be computed in O(1) time.
Our algorithm relies on the monotonicity properties of Lemma 3. Initially, when i=j=1, we let k=1. As j increases, we also increase k. We can compute both dP(vi,vk) and ∣vivj∣+dP(vk,vj) in constant time for each triple (i,k,j). During the increasing of k, if we find dP(vi,vk)≥∣vivj∣+dP(vk,vj) for the first time, then I′(i,j) is k.
After j is increased, we need to compute β(i,j+1), i.e., determine I′(i,j+1) (for differentiation, we use j+1 to refer to the increased j). To this end, by Lemma 3, we have k start from I′(i,j), which is the exactly current value of k. Similarly, when i is increased and we need to determine I′(i+1,j), we also have k start from I′(i,j), i.e., the current value of k. Therefore, in the entire algorithm, the index k continuously increases from 1 to n.
In summary, in the overall algorithm i and j simultaneously increase from 1 to n with i≤j. Hence, the number of β(i,j) values computed in the entire algorithm is at most 2n. Further, the procedure for computing all β values increases k from 1 to n. Thus, the total time for computing all β values in the algorithm is O(n), and the amortized time for computing each β value is O(1).
This proves Lemma 1.
3.2 The Configurations and Our Algorithm
In this section, we present our algorithm for computing an optimal solution. As discussed before, we will consider all possible configurations for the optimal solution and compute a candidate solution for each such configuration.
Recall the definitions of c∗, a∗, b∗, r∗, and π∗ in the beginning of Section 3.
We already discussed one configuration above, i.e., c∗ is on P(v1,vi∗). With the help of Lemma 1, we gave a linear time algorithm for it.
Another configuration, which is symmetric, is that c∗ is on P(vj∗,vn). Correspondingly, we can use an analogous algorithm (e.g., reverse the indices of P and then apply the same algorithm) to compute a candidate solution in linear time. We omit the details. For the reference purpose, we consider the above two configurations as Case 0.
It remains to consider the configuration c∗∈C(i∗,j∗)∖{vi∗,vj∗}. Here, c∗ is in the interior of either e(vi∗,vj∗) or P(vi∗,vj∗).
It is not difficult to see that va∗ is either v1 or a vertex in P(vi∗,vj∗), i.e., a∗=1 or a∗∈[i∗,j∗].
Similarly, b∗=n or b∗∈[i∗,j∗]. Depending on whether a∗=1, b∗=n, or both a∗ and b∗ are in [i∗,j∗], there are three main cases.
3.2.1 Case 1. a∗=1.
In this case, depending on whether b∗=n or b∗∈[i∗,j∗], there are two cases.
3.2.2 Case 1.1. b∗=n.
In this case, if π∗ does not contain e(i∗,j∗), then π∗ is the entire path P. Correspondingly, we keep a candidate solution with dP(v1,vn)/2 as the radius.
In the following, we focus on the case where π∗ contains e(i∗,j∗). As c∗∈C(vi∗,vj∗)∖{vi∗,vj∗} and c∗∈π∗, c∗ must be in the interior of e(vi∗,vj∗) (e.g., see Fig. 4).
We make an assumption on j∗ that no index j>j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗), since otherwise we could instead consider (i∗,j) as (i∗,j∗).
We also assume that none of the previously discussed configurations has an optimal solution since otherwise our previously obtained candidate solutions already have an optimal one.
With these assumptions, we have the following lemma, which is a key observation for our algorithm.
Lemma 6
Let k∗ be the smallest index such that dP(vi∗,vk∗)>dP(v1,vi∗). Such an index k∗ must exist in [i∗,j∗]. Further, j∗ is the largest index j∈[k∗,n] such that dP(vk∗,vj)≤dP(vj,vn).
Proof
Assume to the contrary that such an index k∗ as stated in the lemma doest not exist in [i∗,j∗]. Then, dP(vi∗,vj)≤dP(v1,vi∗) for all j∈[i∗,j∗]. Depending on whether j∗=n, there are two cases.
If j∗=n, then let c be a point on e(vi∗,vj∗) arbitrarily close to c∗ and to the left of c∗. Since c∗ is in the interior of e(vi∗,vj∗), such a point c must exist on e(vi∗,vj∗).
Note that ∣c∗vi∗∣ is the length of the sub-edge of e(vi∗,vj∗) from c∗ to vi∗. Similarly, ∣cvi∗∣ the length of the sub-edge of e(vi∗,vj∗) from c to vi∗.
Since ∣cvi∗∣<∣c∗vi∗∣ and ∣c∗vi∗∣+dP(vi∗,v1)=r∗, ∣cvi∗∣+dP(vi∗,v1)<r∗. On the other hand, for each j∈[i∗,j∗], since dP(vi∗,vj)≤dP(v1,vi∗), we also have ∣cvi∗∣+dP(vi∗,vj)<r∗. Because j∗=n, the above implies that the distance from c to all vertices in G(i∗,j∗) is strictly smaller than r∗, which contradicts with the definition of r∗.
If j∗<n, then consider the graph G(i∗,j∗+1) (which is P∪{e(vi∗,vj∗+1)}). Let c be a point on e(vi∗,vj∗+1)∪e(vj∗+1,vj∗) whose distance along e(vi∗,vj∗+1)∪e(vj∗+1,vj∗) from vi∗ is ∣c∗vi∗∣. Note that such a point c must exist since ∣vi∗vj∗+1∣+∣vj∗+1vj∗∣≥∣vi∗vj∗∣ due to the triangle inequality. The point c is either on e(vi∗,vj∗+1)∖{vj∗+1} or on e(vj∗,vj∗+1). We analyze the two cases below.
If c is on e(vi∗,vj∗+1)∖{vj∗+1} (e.g., see Fig. 6), then we claim that the distances from c to all vertices in G(i∗,j∗+1) are no more than r∗. Indeed, for each j∈[1,i∗], by the definition of c, dG(i∗,j∗+1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,v1)=∣c∗vi∗∣+dP(vi∗,v1)=r∗. For each j∈[i∗,j∗], since dP(vi∗,vj)≤dP(vi∗,v1), we have dG(i∗,j∗+1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,v1)=r∗.
For each j∈[j∗+1,n], by the triangle inequality, we can derive
[TABLE]
The above proves the claim, which implies that (i∗,j∗+1) is also an optimal solution with the same configuration as (i∗,j∗). But this contradicts with our previous assumption on j∗: no index j>j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗).
If c is on e(vj∗,vj∗+1) (e.g., see Fig. 6), then let c′=vj∗+1. We claim that the distances from c′ to all vertices in G(i∗,j∗+1) are at most r∗. We prove the claim below.
On the one hand, for any j∈[1,j∗], by the definition of c′, we have
[TABLE]
Note that because c∈e(vj∗,vj∗+1), ∣cvj∗+1∣ is the length of the sub-edge of e(vj∗,vj∗+1) from c to vj∗+1.
On the other hand, for any j∈[j∗+1,n], by the definition of c′, we have
[TABLE]
The above proves the claim. The claim implies that the graph G(i∗,j∗+1) has a center in P(vj∗+1,vn), which is a configuration of Case 0. But this contradicts with our assumption that none of the previously discussed configurations has an optimal solution.
The above proves the index k∗ must exit in [i∗,j∗].
In the following, we prove that j∗ is the largest index j∈[k∗,n] with dP(vk∗,vj)≤dP(vj,vn). The proof techniques are somewhat similar. Note that there must exist an index j∈[k∗,n] such that dP(vk∗,vj)≤dP(vj,vn) (e.g., j=k∗).
If j∗=n, then the statement is obviously true. In the following we assume that j∗<n.
Assume to the contrary that j∗ is not the largest such index. Then, it must be true that dP(vk∗,vj∗+1)≤dP(vj∗+1,vn). Consider the graph G(i∗,j∗+1). As above, let c be a point on e(vi∗,vj∗+1)∪e(vj∗+1,vj∗) whose distance along e(vi∗,vj∗+1)∪e(vj∗+1,vj∗) from vi∗ is ∣c∗vi∗∣.
If c is on e(vi∗,vj∗+1)∖{vj∗+1}, then we claim that the distances from c to all vertices in G(i∗,j∗+1) are no more than r∗. For each j∈[1,k∗−1], by the same analysis as above, dG(i∗,j∗+1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,v1)=r∗.
For each j∈[k∗,n], dG(i∗,j∗+1)(c,vj)≤∣cvj∗+1∣+dP(vj∗+1,vj)≤∣cvj∗+1∣+dP(vj∗+1,vn).
By Equation (2), we can show that ∣cvj∗+1∣+dP(vj∗+1,vn)≤r∗. The claim is thus proved. The claim implies that (i∗,j∗+1) is also an optimal solution with the same configuration as (i∗,j∗). But this contradicts with our assumption on j∗.
If c is on e(vj∗,vj∗+1), then let c′=vj∗+1. By the same analysis as above, we can show that the distances from c′ to all vertices in G(i∗,j∗+1) are no more than r∗. Since c′∈P(vj∗+1,vn), the claim implies that there is an optimal solution conforming with the configuration of Case 0. This again incurs contradiction.∎
Based on Lemma 6, our algorithm for this case works as follows.
For each index i∈[1,n], define k(i) as the smallest index k∈[i,n] such that dP(vi,vk)>dP(v1,vi) (let k(i)=n+1 if no such index exists), and if k(i)≤n, define j(i)222This notation was used before for a different meaning. Because we have many cases to consider, to save notation, we will repeatedly use the same notation as long as the context is clear. as the largest index j∈[k(i),n] such that dP(vk(i),vj)≤dP(vj,vn) (let j(i)=n+1 if k(i)=n+1).
The following observation is self-evident.
Observation 4
For each i∈[1,n−1], k(i)≤k(i+1) and j(i)≤j(i+1).
By the above observation, we can easily compute k(i) and j(i) for
all i∈[1,n] in O(n) time by a linear scan on P. We omit the
details.
For each i, if j(i)≤n, let
r(i)=(dP(v1,vi)+∣vivj(i)∣+dP(vj(i),vn))/2, and if
dP(v1,vi)<r(i) and dP(vj(i),vn)<r(i) (implies that the
center is in the interior of e(vi,vj(i))), then we keep
(i,j(i)) as a candidate solution with r(i) as the radius (and the center is a point c in e(vi,vj(i)) with dP(v1,vi)+∣vic∣=r(i)). Note
that due to our definitions of k(i) and j(i), the
solution is feasible, i.e., the distances
from c to all vertices in the graph G(i,j(i)) are no more than r(i).
The above computes at most n candidate solutions, and among them, we keep the one with the smallest r(i) value as our candidate solution for this configuration. Based on our discussions, if this
configuration has an optimal solution, then our solution is also optimal.
The running time of the algorithm is O(n).
3.2.3 Case 1.2: b∗∈[i∗,j∗].
Note that π∗ either contains e(i∗,j∗) or does not
contain any interior point of the edge.
Depending on whether π∗ contains e(i∗,j∗), there are two cases.
3.2.4 Case 1.2.1: π∗ contains e(i∗,j∗).
Recall that c∗ is in the interior of either e(vi∗,vj∗) or P(vi∗,vj∗). We discuss the two cases below.
3.2.5 Case 1.2.1.1: c∗∈e(i∗,j∗), e.g., see Fig. 7.
Our algorithm for this case is somewhat similar to that for Case 1.1.
We make an assumption on j∗ that no index j<j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗) since otherwise we could instead consider (i∗,j) as (i∗,j∗). We also assume that none of the previously discussed configurations has an optimal solution. We have the following lemma.
Lemma 7
-
Let k∗ be the smallest index such that dP(vi∗,vk∗)>dP(v1,vi∗). Such an index k∗ must exist in [i∗,j∗].
2. 2.
b∗=k∗.
3. 3.
j∗* is the smallest index j∈[k∗,n] such that dP(vk∗,vj)>dP(vj,vn).*
Proof
We first prove that k∗ exists. Assume to the contrary that this is not true. Then, dP(vi∗,vj)≤dP(v1,vi∗) for all j∈[i∗,j∗].
Let c be a point of e(i∗,j∗) to the left of c∗ and arbitrarily close to c∗. We show that the distances from c to all vertices in G(i∗,j∗) are all smaller than r∗, incurring contradiction.
Because none of the previously discussed configurations has an optimal solution, vn is not a farthest point of c∗, i.e., ∣c∗vj∗∣+dP(vj∗,vn)<r∗ (since otherwise Case 1.1 would happen). By the definition of c, ∣cvj∗∣+dP(vj∗,vn)<r∗.
Hence, for each j∈[j∗,n], dG(i∗,j∗)(c,vj)≤∣cvj∗∣+dP(vj∗,vj)≤∣cvj∗∣+dP(vj∗,vn)<r∗. On the other hand, for each j∈[1,j∗], dG(i∗,j∗)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,v1)<∣c∗vi∗∣+dP(vi∗,v1)=r∗.
This proves that k∗ must exist.
For the second part of the lemma,
notice that the configuration tells that the shortest path from c∗ to vb∗ in G(i∗,j∗) is the union of the sub-edge of e(i∗,j∗) from c∗ to j∗ and P(vb∗,vj∗). Hence, dG(i∗,j∗)(c∗,vb∗)=∣c∗vj∗∣+dP(vj∗,vb∗)≤∣c∗vi∗∣+dP(vi∗,vb∗).
Note that ∣c∗vj∗∣+dP(vj∗,vb∗)=∣c∗vi∗∣+dP(vi∗,vb∗) is not possible. Indeed, if this were true, then since ∣c∗vj∗∣+dP(vj∗,vn)<r∗, if we move c∗ slightly on e(vi∗,vj∗) towards vi∗, then the distances from c∗ to all vertices in G(i∗,j∗) would be all smaller than r∗, incurring contradiction. Therefore, ∣c∗vj∗∣+dP(vj∗,vb∗)<∣c∗vi∗∣+dP(vi∗,vb∗).
Since ∣c∗vj∗∣+dP(vj∗,vb∗)=∣c∗vi∗∣+dP(vi∗,v1)=r∗, we obtain dP(vi∗,v1)<dP(vi∗,vb∗).
The definition of k∗ implies that k∗≤b∗.
On the other hand, assume to the contrary that k∗<b∗.
Then, ∣c∗vj∗∣+dP(vj∗,vk∗)>∣c∗vj∗∣+dP(vj∗,vb∗)=dG(i∗,j∗)(c∗,vb∗)=r∗.
Further, since dP(vi∗,vk∗)>dP(v1,vi∗), ∣c∗vi∗∣+dP(vi∗,vk∗)>∣c∗vi∗∣+dP(vi∗,v1)=r∗.
Consequently, dG(i∗,j∗)(c∗,vk∗)=min{∣c∗vj∗∣+dP(vj∗,vk∗),∣c∗vi∗∣+dP(vi∗,vk∗)}>r∗, a contradiction. This proves that k∗=b∗.
We proceed to prove the third part of the lemma. Since ∣c∗vj∗∣+dP(vj∗,vn)<r∗ and ∣c∗vj∗∣+dP(vj∗,vk∗)=r∗, we have dP(vk∗,vj∗)>dP(vj∗,vn).
Assume to the contrary the statement is not true. Then, it must hold that dP(vk∗,vj∗−1)>dP(vj∗−1,vn).
Let c be a point on e(vi∗,vj∗−1)∪e(vj∗−1,vj∗) whose distance along e(vi∗,vj∗−1)∪e(vj∗−1,vj∗) from vi∗ is ∣c∗vi∗∣. Such a point c must exist since ∣vi∗vj∗−1∣+∣vj∗−1vj∗∣≥∣vi∗vj∗∣. Depending on whether c is on e(vi∗,vj∗−1)∖{vj∗−1} or on e(vj∗−1,vj∗), there are two cases. The proof is similar to that for Lemma 6. So we briefly discuss it.
If c is on e(vi∗,vj∗−1)∖{vj∗−1}, e.g., see Fig. 9, then we claim that the distances from c to all vertices in G(i∗,j∗−1) are at most r∗. Indeed, for each j∈[1,k∗−1], dG(i∗,j∗−1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)=∣c∗vi∗∣+dP(vi∗,vj)≤∣c∗vi∗∣+dP(vi∗,v1)=r∗.
For each j∈[k∗,n], since dP(vk∗,vj∗−1)>dP(vj∗−1,vn), dG(i∗,j∗−1)(c,vj)≤∣cvj∗−1∣+dP(vj∗−1,vj)≤∣cvj∗−1∣+dP(vj∗−1,vk∗). In a similar way as Equation (2), we can show that ∣cvj∗−1∣+dP(vj∗−1,vk∗)≤∣c∗vj∗∣+dP(vj∗,vk∗)=r∗. The claim thus follows.
Hence, (i∗,j∗−1) is also an optimal solution with the same configuration as (i∗,j∗). But this contradicts with our assumption on j∗: no index j<j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗).
If c is on e(vj∗,vj∗−1), e.g., see Fig. 9, then let c′=vj∗−1. We claim that the distances from c′ to all vertices in G(i∗,j∗−1) are at most r∗.
On the one hand, for any j∈[1,k∗−1], dG(i∗,j∗−1)(c′,vj)≤∣c′vi∗∣+dP(vi∗,vj)≤∣c′vi∗∣+dP(vi∗,v1)≤∣cc′∣+∣c′vi∗∣+dP(vi∗,v1)=r∗. On the other hand, for any j∈[k∗,n], since dP(vk∗,vj∗−1)>dP(vj∗−1,vn), dG(i∗,j∗−1)(c,vj)≤dP(c′,vj)≤dP(c′,vk∗)≤dP(vj∗,vk∗)≤∣c∗vj∗∣+dP(vj∗,vk∗)=r∗. This proves the claim.
The claim implies that G(i∗,j∗−1) is also an optimal solution with a center at vj∗−1∈P(vj∗−1,vn). But this is a configuration in Case 0, which contracts with our assumption that none of the previously discussed configurations has an optimal solution. ∎
Based on Lemma 7, our algorithm for this case works as follows.
For each index i∈[1,n], define k(i) as the smallest k∈[i,n] such
that dP(vi,vk)>dP(v1,vi) (let k(i)=n+1 if no such index exists),
and if k(i)≤n, define j(i) as the smallest
index j∈[k(i),n] such that dP(vk(i),vj)>dP(vj,vn) (let
j(i)=n+1 if no such index exists or if k(i)=n+1). It is not
difficult to see that for each i∈[1,n−1], k(i)≤k(i+1) and
j(i)≤j(i+1).
The indices k(i) and j(i) can be computed in O(n) time by a linear scan on P.
We omit the details.
For each i, if j(i)≤n, then let
r(i)=(dP(v1,vi)+∣vivj(i)∣+dP(vj(i),vk(i)))/2, and if
dP(v1,vi)<r(i) and dP(vj(i),vk(i))<r(i) (this implies that
the center is in the interior of e(vi,vj(i))), then we have a
candidate solution (i,j(i)) with r(i) as the radius. By
our definitions of k(i) and j(i), the solution is feasible.
Finally, among the at most n candidate solutions, we
keep the one with the smallest r(i) as our solution for this
configuration. The running time of the algorithm is O(n).
3.2.6 Case 1.2.1.2: c∗∈P(i∗,j∗).
Since π∗ contains e(vi∗,vj∗), c∗ must be to the right of vb∗
(e.g., see the bottom example in Fig. 1).
Further, dP(v1,vc∗)=dP(v1,vi∗)+∣vi∗vj∗∣+dP(c∗,vj∗)=r∗.
We make an assumption on j∗ that no index j<j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗). We also assume that none of the previously discussed configurations has an optimal solution. The following lemma is literally the same as Lemma 7, although the proof is different.
Lemma 8
-
Let k∗ be the smallest index such that dP(vi∗,vk∗)>dP(v1,vi∗). Such an index k∗ must exist in [i∗,j∗].
2. 2.
b∗=k∗.
3. 3.
j∗* is the smallest index j∈[k∗,n] such that dP(vk∗,vj)>dP(vj,vn).*
Proof
We first prove that k∗ exists in [i∗,j∗]. Define j′ to be the largest index in [i∗,j∗] such that vj′ is to the left of or at c∗. Since j′≤j∗, it is sufficient to prove that such an index k∗ as stated in the lemma must exist in [i∗,j′]. Assume to the contrary that this is
not true. Then, dP(vi∗,vj)≤dP(v1,vi∗) for all
j∈[i∗,j′]. Let c be a point of P(i∗,j∗) to the right
of c∗ and arbitrarily close to c∗. As c∗ is in the interior of P(i∗,j∗), such a point c must exist. In the following, we
claim that the distances from c to all vertices in G(i∗,j∗) are smaller than
r∗, incurring contradiction.
Note that P(c∗,vn) is a shortest path from c∗ to vn in G(i∗,j∗). Hence, dP(c∗,vn)≤r∗. By the definition of c, for each j∈[j′+1,n], dG(i∗,j∗)(c,vj)≤dP(c,vj)≤dP(c,vn)<dP(c∗,vn)≤r∗. On
the other hand, for each j∈[1,j′], dG(i∗,j∗)(c,vj)≤dP(c,vj∗)+∣vj∗vi∗∣+dP(vi∗,vj)≤dP(c,vj∗)+∣vj∗vi∗∣+dP(vi∗,v1)<dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,v1)=r∗.
The above claim is thus proved.
For the second part of the lemma, the proof is similar to that in Lemma 7.
Recall that
dG(i∗,j∗)(c∗,vb∗)=dP(c∗,vb∗)=r∗≤dP(c∗,vj∗)+∣vi∗vj∗∣+dP(vi∗,vb∗).
Note that r∗=dP(c∗,vj∗)+∣vi∗vj∗∣+dP(vi∗,vb∗) is not possible. Indeed, if this were true, then if we move c∗ slightly on P(vi∗,vj∗) towards vj∗, the distances from c∗ to all vertices in G(i∗,j∗) would be all smaller than r∗, incurring contradiction. Therefore, dP(c∗,vb∗)<dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,vb∗).
Since dP(vb∗,c∗)=dP(v1,vi∗)+∣vi∗vj∗∣+dP(vj∗,c∗)=r∗, we obtain dP(v1,vi∗)+∣vi∗vj∗∣+dP(vj∗,c∗)<dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,vb∗), and thus dP(v1,vi∗)<dP(vi∗,vb∗).
The definition of k∗ implies that k∗≤b∗.
On the other hand, assume to the contrary that k∗<b∗.
Then, dP(c∗,vk∗)>dP(c∗,vb∗)=dG(i∗,j∗)(c∗,vb∗)=r∗.
Further, since dP(vi∗,vk∗)>dP(v1,vi∗), we have dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,vk∗)>dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,v1)=r∗. Thus, we obtain dG(i∗,j∗)(c∗,vk∗)=min{dP(c∗,vk∗),dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,vk∗)}>r∗, a contradiction. This proves k∗=b∗.
We proceed to prove the third part of the lemma.
We first prove that c∗ must be in the interior of e(vj∗−1,vj∗).
Assume to the contrary that this is not true. Then, since c∗ is not at vj∗, c∗ is in
P(vk∗,vj∗−1).
We claim that the distances from c∗ to
all vertices in G(i∗,j∗−1) are at most r∗.
Indeed, for each j∈[k∗,n], dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vj)≤dP(c∗,vk∗)=r∗. For each j∈[1,k∗−1],
dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vj∗−1)+∣vj∗−1vi∗∣+dP(vi∗,vj)≤dP(c∗,vj∗−1)+∣vj∗−1vi∗∣+dP(vi∗,v1)≤dP(c∗,vj∗−1)+dP(vj∗−1,vj∗)+∣vj∗vi∗∣+dP(vi∗,v1)=r∗.
The last inequality is due to the triangle inequality. This proves the claim.
The claim implies that (i∗,j∗−1) is also an optimal solution with center at c∗. If c∗ is at vj∗−1∈P(vj∗−1,vn), then this is a configuration of Case 0, which contradicts with our assumption that none of the previously discussed configurations has an optimal solution. Otherwise, the optimal solution (i∗,j∗−1) has the same configuration as (i∗,j∗), which contradicts with our assumption on j∗: no index j<j∗ exists such that (i∗,j) is also an optimal solution with the same configuration as (i∗,j∗).
The above proves that c∗ is in the interior of e(vj∗−1,vj∗).
We claim that dP(vk∗,vj∗)>dP(vj∗,vn). Indeed, since c∗ is in the interior of e(vj∗−1,vj∗), we have dP(vk∗,vj∗)>dP(vk∗,c∗)=r∗≥dP(c∗,vn)>dP(vj∗,vn).
For the third part of the lemma, assume to the contrary the statement is not true.
Then, due to the above claim, it must hold that dP(vk∗,vj∗−1)>dP(vj∗−1,vn).
Depending on whether ∣vi∗vj∗−1∣<∣c∗vj∗∣+∣vi∗vj∗∣, there are two cases.
If ∣vi∗vj∗−1∣<∣c∗vj∗∣+∣vi∗vj∗∣,
then let c=vj∗−1. In
the following, we show that the distances from c to all vertices
in G(i∗,j∗−1) are smaller than r∗, which would incur contradiction.
Indeed, since c∗ is in the interior of e(vj∗−1,vj∗), c is strictly to the
left of c∗. Thus, for each j∈[k∗,j∗−1], dG(i∗,j∗−1)(c,vj)≤dP(vj,c)≤dP(vk∗,c)<dP(vk∗,c∗)=r∗. For each j∈[j∗,n], since dP(vk∗,vj∗−1)>dP(vj∗−1,vn), dG(i∗,j∗−1)(c,vj)≤dP(c,vj)≤dP(c,vn)=dP(vj∗−1,vn)<dP(vk∗,vj∗−1)=dP(vk∗,c)<r∗.
For each j∈[1,k∗−1], since
∣vi∗vj∗−1∣<∣c∗vj∗∣+∣vi∗vj∗∣, dG(i∗,j∗−1)(c,vj)≤∣vj∗−1vi∗∣+dP(vi∗,vj)≤∣vj∗−1vi∗∣+dP(vi∗,v1)<∣c∗vj∗∣+∣vj∗vi∗∣+dP(vi∗,v1)=r∗.
The claim thus follows.
If ∣vi∗vj∗−1∣≥∣c∗vj∗∣+∣vi∗vj∗∣, then
let c be the point on e(vi∗,vj∗−1) such that
∣cvi∗∣=∣c∗vj∗∣+∣vj∗vi∗∣, e.g., see Fig. 10. We claim that the
distances from c to all vertices in G(i∗,j∗−1) are at most r∗.
Indeed, for each j∈[1,k∗−1], dG(i∗,j∗−1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,v1)=∣c∗vj∗∣+∣vj∗vi∗∣+dP(vi∗,v1)=r∗.
For each j∈[k∗,j∗−1],
[TABLE]
For each j∈[j∗,n], since dP(vk∗,vj∗−1)≥dP(vj∗−1,vn), dG(i∗,j∗−1)(c,vj)≤∣cvj∗−1∣+dP(vj∗−1,vj)≤∣cvj∗−1∣+dP(vj∗−1,vn)≤∣cvj∗−1∣+dP(vj∗−1,vk∗)≤r∗ (this last inequality was already proved above).
The claim thus follows.
The claim implies that (i∗,j∗−1) is also an optimal solution with center c at e(vi∗,vj∗). Since ∣cvi∗∣>0, c cannot be at vi∗.
If c is at vj∗−1∈P(vj∗−1,vn), then this is a configuration of Case 0. Otherwise, the optimal solution (i∗,j∗−1) has the same configuration as Case 1.2.1.1 (e.g., the one in Fig. 7). In either case, this contradicts with our assumption that none of the previously discussed configurations has an optimal solution.
This proves the third part of the lemma and thus the entire lemma.
∎
Based on Lemma 8, our algorithm for this case works as follows.
For each index i∈[1,n], define k(i) and j(i) in the same way
as in the above Case 1.2.1.1. We also compute them in O(n) time.
For each i, if j(i)≤n, then let
r(i)=(dP(v1,vi)+∣vivj(i)∣+dP(vj(i),vk(i)))/2, and if
dP(v1,vi)+∣vivj(i)∣<r(i) (implies that the center is on
P(vk(i),vj(i))), then we have a candidate solution (i,j(i)) with
r(i) as the radius. Finally, among the at most n candidate
solutions, we keep the one with the smallest radius as our solution
for this case. The total running time of the algorithm is O(n).
3.2.7 Case 1.2.2: π∗ does not contain e(i∗,j∗).
In this case, the shortest path from c∗ to v1 in G(i∗,j∗) is
P(v1,c∗) and the shortest path from c∗ to vb∗ is
P(c∗,vb∗). Since c∗ is in the middle of π∗, π∗ is P(v1,vb∗) (e.g., see Fig. 11). Further, it is not difficult to see
that for any j∈[b∗+1,n], the shortest path from c∗ to vj in G(i∗,j∗)
is P(c∗,vi∗)∪e(vi∗,vj∗)∪P(vj∗,vj). Also
note that b∗<j∗, since otherwise (i.e., b∗=j∗, which is
smaller than n as b∗=n)
dG(i∗,j∗)(c∗,vn)=dG(i∗,j∗)(c∗,vb∗)+dP(vb∗,vn)>dG(i∗,j∗)(c∗,vb∗)=r∗,
a contradiction.
We make an assumption on j∗ that no index j<j∗ exists such that
(i∗,j) is also an optimal solution with the same configuration as
(i∗,j∗). We also assume that none of the previously discussed
configurations has an optimal solution.
We begin with the following observation.
Observation 5
For any i∈[1,n], the value ∣vivj∣+dP(vj,vn) is monotonically decreasing as j increases from i to n.
Proof
Indeed, ∣vivj∣+dP(vj,vn)−(∣vivj+1∣+dP(vj+1,vn))=∣vivj∣+∣vivj+1∣−∣vivj+1∣,
which is nonnegative by the triangle inequality. ∎
Our algorithm is based on the following lemma.
Lemma 9
-
Let k∗ be the largest index in [i∗,j∗]
such that dP(v1,vi∗)<∣vi∗vj∗∣+dP(vj∗,vk∗).
Such an index k∗ must exist.
2. 2.
b∗=k∗.
3. 3.
j∗* must be the smallest index j∈[i∗,n] such that dP(v1,vi∗)≥∣vi∗vj∣+dP(vj,vn).*
4. 4.
dP(v1,vi∗)<dP(vi∗,vn).
Proof
For the first part of the lemma, it is sufficient to prove the following:
k∗ is the largest index in [j′,j∗]
such that dP(v1,vi∗)<∣vi∗vj∗∣+dP(vj∗,vk∗), where j′ is the index of the first vertex to the right of or at c∗. Note that as c∗ is in the interior of P(vi∗,vj∗), j′≤j∗.
Assume to the contrary that such an index k∗ does not exist in [j′,j∗]. Then, dP(v1,vi∗)≥∣vi∗vj∗∣+dP(vj∗,vj) for all j∈[j′,j∗].
Let c be a point on P(vi∗,vj∗) arbitrarily close to c∗ and to the left of c∗. Such a point c must exist as c∗ is in the interior of P(vi∗,vj∗).
We claim that the distances from c to all vertices in G(i∗,j∗) are all smaller than r∗, which would incur contradiction. Indeed, for any j∈[1,j′−1], dG(i∗,j∗)(c,vj)≤dP(c,vj)≤dP(c,v1)<dP(c∗,v1)=r∗. For any j∈[j′,j∗], dG(i∗,j∗)(c,vj)≤dP(c,vi∗)+∣vi∗vj∗∣+dP(vj∗,vj)≤dP(c,vi∗)+dP(v1,vi∗)=dP(c,v1)<dP(c∗,v1)=r∗.
For any j∈[j∗+1,n], dG(i∗,j∗)(c,vj)≤dP(c,vi∗)+∣vi∗vj∗∣+dP(vj∗,vn)<dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vn).
Note that since vb∗ is a farthest point of c∗, the shortest path from c∗ to vn must contain the new edge e(vi∗,vj∗) and thus its length is dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vn), which is at most r∗. Therefore, we obtain that dG(i∗,j∗)(c,vj)<r∗ for each j∈[j∗+1,n].
The above claim is thus proved.
For the second part of the lemma, since the shortest path from c∗ to vb∗ is P(c∗,vb∗), it holds that r∗=dP(c∗,vb∗)≤dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vb∗). Note that r∗=dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vb∗) is not possible. Indeed, it this were true, then if we move c∗ slightly towards vi∗, the distances from c∗ to all vertices in G(i∗,j∗) would be all smaller than r∗, incurring contradiction. Hence, r∗<dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vb∗). Further, since r∗=dP(c∗,v1)=dP(c∗,vi∗)+dP(vi∗,v1), we obtain that dP(vi∗,v1)<∣vi∗vj∗∣+dP(vj∗,vb∗). The definition of k∗ implies that k∗≥b∗.
Assume to the contrary that k∗>b∗. Then, dG(i∗,j∗)(c∗,vk∗)=min{dP(c∗,vk∗),dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vk∗)}.
On the one hand, since k∗>b∗, dP(c∗,vk∗)>dP(c∗,vb∗)=r∗. On the other hand, since dP(vi∗,v1)<∣vi∗vj∗∣+dP(vj∗,vk∗), we obtain that dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vk∗)>dP(c∗,vi∗)+dP(vi∗,v1)=dP(c∗,v1)=r∗. Hence, we derive dG(i∗,j∗)(c∗,k∗)>r∗, a contradiction.
We proceed to prove the third statement of the lemma.
Since dG(i∗,j∗)(c∗,vn)=dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vn)≤r∗=dP(c∗,v1)=dP(c∗,vi∗)+dP(vi∗,v1), ∣vi∗vj∗∣+dP(vj∗,vn)≤dP(vi∗,v1) holds.
Assume to the contrary that the third statement of the lemma is not true. Then, by Observation 5, dP(v1,vi∗)≥∣vi∗vj∗−1∣+dP(vj∗−1,vn).
Recall that b∗<j∗, and thus k∗=b∗≤j∗−1.
We claim that the distances from c∗ to all vertices in G(i∗,j∗−1) are no more than r∗.
Indeed, for each j∈[1,k∗], dG(i∗,j∗−1)(c∗,vj)=dP(c∗,vj)≤dP(c∗,v1)=r∗.
If k∗<j∗−1, then for each j∈[k∗+1,j∗−1], dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c∗,vi∗)+∣vi∗vj∗∣+∣vj∗vj∗−1∣+dP(vj∗−1,vj)=dP(c∗,vi∗)+∣vi∗vj∗∣+dP(vj∗,vj), which is the shortest path length from c∗ to vj in G(i∗,j∗) and thus is at most r∗.
For each j∈[j∗,n], because dP(v1,vi∗)≥∣vi∗vj∗−1∣+dP(vj∗−1,vn), dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c∗,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vn)≤dP(c∗,vi∗)+dP(vi∗,v1)=r∗.
The claim is thus proved.
The claim implies that (i∗,j∗−1) is also an optimal solution with the same configuration as (i∗,j∗). But this contradicts with our assumption on j∗: no index j<j∗ exists such that
(i∗,j) is also an optimal solution with the same configuration as
(i∗,j∗).
For the fourth part of the lemma, since c∗ is strictly to the right of vi∗, dP(vi∗,vn)≥dP(vi∗,vb∗)>dP(c∗,vb∗)=r∗=dP(c∗,v1)>dP(vi∗,v1).
∎
Based on Lemma 9, our algorithm works as follows.
Let i1 be the largest index i in [1,n] such that dP(v1,vi)<dP(vi,vn).
Let i2 be the smallest index i in [1,n] such that dP(v1,vi)≥∣vivn∣.
By Lemma 9 and Observation 5, if i2≤i1333Note that i2≤i1+1 always holds because dP(v1,vi1+1)≥dP(vi1+1,vn)≥∣vi1+1vn∣., we only need to consider the indices in [i2,i1] as the candidates for i∗. For each i∈[i2,i1], define j(i) as the smallest index j∈[i,n] such that dP(v1,vi)≥∣vivj∣+dP(vj,vn)444The index j must exist because dP(v1,vi)≥∣vivn∣ due to the definition of i2., and
define k(i) as the largest k∈[i,j(i)] such that dP(v1,vi)<∣vivj(i)∣+dP(vj(i),vk) (for convenience let k(i)=0 if no such index k exists).
The monotonicity properties of j(i) and k(i) in the following lemma will lead to an efficient algorithm to compute them.
Lemma 10
For any i∈[i2,i1−1], j(i+1)≤j(i) and k(i+1)≤k(i).
Proof
To prove that j(i+1)≤j(i),
it is sufficient to show that for any j∈[i+1,n], if dP(v1,vi)≥∣vivj∣+dP(vj,vn), then dP(v1,vi+1)≥∣vi+1vj∣+dP(vj,vn). Indeed, by the triangle inequality,
[TABLE]
To prove k(i+1)≤k(i), since [i+1,j(i+1)]⊆[i,j(i)], it is sufficient to show that for any k∈[i+1,j(i+1)], if dP(v1,vi+1)<∣vi+1vj(i+1)∣+dP(vj(i+1),vk), then dP(v1,vi)<∣vivj(i)∣+dP(vj(i),vk). Indeed, due to the triangle inequality, we have
[TABLE]
The lemma thus follows.
∎
Our algorithm for this configuration works as follows.
We first compute the two indices i1 and i2. If i2>i1, then we do not keep any solution for this case. Otherwise, by the monotonicity properties of j(i) and k(i) in Lemma 10, we can compute j(i) and k(i) for all i∈[i2,i1] in O(n) time by a linear scan on P. The details are omitted.
Then, for each i∈[i2,i1], if k(i)=0 and dP(v1,vi)<dP(vi,vk(i)) (this makes sure that the center is in P(vi,vk(i))), then we have a candidate solution (i,j(i)) with radius r(i)=dP(v1,vk(i))/2. By our definition of j(i) and k(i), the solution is feasible. Finally, among all the at most n candidate solutions, we keep the one with the smallest radius as our solution for this case. The algorithm runs in O(n) time.
3.2.8 Case 2: b∗=n.
This case is symmetric to Case 1 (a∗=1), so we omit the details.
3.2.9 Case 3: Both a∗ and b∗ are in [i∗,j∗].
Observe that since a∗=1 and b∗=n,
a∗ cannot be i∗ and b∗ cannot be j∗. Hence, both a∗ and b∗ are in [i∗+1,j∗−1].
As in Case 1, depending on whether c∗ is in e(i∗,j∗) or P(vi∗,vj∗), there are two subcases.
3.2.10 Case 3.1. c∗∈e(i∗,j∗).
More precisely, c∗ is in the interior of e(i∗,j∗), which implies that e(i∗,j∗) is in π∗. It is not difficult to see that b∗=a∗+1 (e.g., see Fig. 12). We make an assumption on [i∗,j∗] that there is no smaller interval [i,j]⊂[i∗,j∗] such that (i,j) is also an optimal solution with the same configuration as (i∗,j∗) (since otherwise we could instead consider (i,j) as (i∗,j∗)).
We also assume that none of the previously discussed cases happens. This implies that neither v1 nor vn is a farthest vertex of c∗ in G(i∗,j∗). To see this, suppose to the contrary that v1 is also a farthest vertex. Then, if we consider v1 and vb∗ as two farthest vertices stated in Observation 1, then the configuration becomes Case 1.2.1.1 (shown in the bottom example for Fig. 1), which incurs contradiction. Similarly, vn is not a farthest vertex as well.
Since neither v1 nor vn is a farthest vertex of c∗, it can be verified that dP(v1,vi∗)<dP(vi∗,va∗) and dP(vj∗,vn)<dP(vb∗,vj∗).
Lemma 11
i∗* is the largest index i∈[1,a∗] such that dP(v1,vi)<dP(vi,va∗).
j∗ is the smallest index j∈[b∗,n] such that dP(vj,vn)<dP(vb∗,vj).*
Proof
We only prove the first part of the lemma, as the proof for the second part is analogous.
Assume to the contrary that this is not true. Then, due to dP(v1,vi∗)<dP(vi∗,va∗), it must hold that
dP(v1,vi∗+1)<dP(vi∗+1,va∗).
Let c be a point on e(vi∗,vi∗+1)∪e(vi∗+1,vj∗)
with distance ∣c∗vj∗∣ from vj∗ (e.g., see Fig. 14). Such a point c must exist
since ∣vi∗vi∗+1∣+∣vi∗+1vj∗∣≥∣vi∗vj∗∣. Depending on whether c∈e(vi∗+1,vj∗),
there are two cases.
If c∈e(vi∗+1,vj∗) (e.g., see Fig. 14), then we claim that the distances from
c to all vertices in G(i∗+1,j∗) are at most
r∗. Indeed, for each j∈[b∗,j∗], dG(i∗+1,j∗)(c,vj)≤∣cvj∗∣+dP(vj∗,vj)≤∣cvj∗∣+dP(vj∗,vb∗)=∣c∗vj∗∣+dP(vj∗,vb∗)=r∗.
For each j∈[j∗+1,n], dG(i∗+1,j∗)(c,vj)≤∣cvj∗∣+dP(vj∗,vj)≤∣cvj∗∣+dP(vj∗,vn)<∣cvj∗∣+dP(vj∗,vb∗)=∣c∗vj∗∣+dP(vj∗,vb∗)=r∗.
For each j∈[i∗+1,a∗], dG(i∗+1,j∗)(c,vj)≤∣cvi∗+1∣+dP(vi∗+1,vj)≤∣cvi∗+1∣+dP(vi∗+1,va∗). In a similar way as
Equation (2), we can show that
∣cvi∗+1∣+dP(vi∗+1,va∗)≤∣c∗vi∗∣+dP(vi∗,va∗)=r∗. For each j∈[1,i∗],
due to dP(v1,vi∗+1)<dP(vi∗+1,va∗),
dG(i∗+1,j∗)(c,vj)≤∣cvi∗+1∣+dP(vi∗+1,vj)≤∣cvi∗+1∣+dP(vi∗+1,v1)<∣cvi∗+1∣+dP(vi∗+1,va∗)≤r∗.
The claim is thus proved. However, the claim implies that
(i∗+1,j∗) is also an optimal solution with the same
configuration as (i∗,j∗). As [i∗+1,j∗]⊂[i∗,j∗], we obtain
contradiction with our assumption on [i∗,j∗]: there is no smaller interval [i,j]⊂[i∗,j∗] such that (i,j) is also an optimal solution with the same configuration as (i∗,j∗).
If c∈e(vi∗+1,vj∗) (e.g., see Fig. 14), then c is on
e(vi∗,vi∗+1)∖{vi∗+1}. Let c′=vi∗+1.
We claim that the distances from c′ to all
vertices in G(i∗+1,j∗) are strictly smaller than r∗,
which incurs contradiction. Indeed, for each j∈[b∗,n],
dG(i∗+1,j∗)(c′,vj)≤∣c′vj∗∣+dP(vj,vj∗)≤∣c′vj∗∣+dP(vb∗,vj∗)<∣cc′∣+∣c′vi∗+1∣+∣vi∗+1vj∗∣+dP(vj∗,vb∗)=r∗.
Since ∣c∗vi∗∣+dP(vi∗,vi∗+1)+dP(vi∗+1,va∗)=r∗,
we obtain that dP(c′,va∗)<r∗.
Hence, for each j∈[1,a∗], since dP(v1,vi∗+1)<dP(vi∗+1,va∗), we obtain dG(i∗+1,j∗)(c′,vj)≤dP(c′,va∗)<r∗.
∎
Based on Lemma 11, our algorithm works as follows.
For each interval [k,k+1] with k∈[2,n−2] (since a∗>1 and b∗<n, we do not need to consider the case where k=1 or k+1=n), define i(k) as the largest index i∈[1,k] such that dP(v1,vi)<dP(vi,vk), and define j(k) as the smallest index j∈[k+1,n] such that dP(vj,vn)<dP(vk+1,vj). It can be verified that
for any k∈[2,n−3], i(k)≤i(k+1) and j(k)≤j(k+1).
Thus, we can easily compute i(k) and j(k) for all k∈[2,n−2] in O(n) time. Then, for each k∈[2,n−2], let r(i)=(dP(vi(k),vk)+∣vi(k)vj(k)∣+dP(vk+1,vj(k)))/2, and if r(i)>dP(vi(k),vk) and r(i)>dP(vk+1,vj(k)) (this makes sure that the center is on the edge e(vi(k),vj(k))), then we have a candidate solution (i(k),j(k+1)) with r(i) as the radius. By the definitions of i(k) and j(k+1), the solution is feasible. Finally, among the at most n candidate solutions, we keep the one with the smallest radius as our solution for this case. The total time of the algorithm is O(n).
3.2.11 Case 3.2. c∗∈P(vi∗,vj∗).
More precisely, c∗ is in the interior of P(vi∗,vj∗).
We first have the following observation.
Lemma 12
π∗* must contain e(vi∗,vj∗); b∗=a∗+1;
va∗ and vb∗ are on the same side of c∗ (e.g., see Fig. 15).*
Proof
Assume to the contrary π∗ does not contain e(vi∗,vj∗). Then, c∗ is between va∗ and vb∗, and π∗=P(va∗,vb∗), e.g., see Fig. 16. Recall that a∗>1, b∗<n, and both a∗ and b∗ are in [i∗+1,j∗−1]. Since dP(c∗,va∗)=dP(c∗,vb∗)=r∗, one can verify that the distance from c∗ to v1 (or vn) in G(i∗,j∗) must be larger than r∗, which incurs contradiction.
Since π∗ contains e(vi∗,vj∗), va∗ and vb∗ must be on the same side of c∗, in which case va∗ and vb∗ must be two adjacent vertices, i.e., b∗=a∗+1.
∎
In the following, we only discuss the case where c∗ is to the right
of va∗ and vb∗ (e.g., see Fig. 15), and the algorithm for the other case
is symmetric. We make an assumption on [i∗,j∗] that there is no smaller interval [i,j]⊂[i∗,j∗] such that (i,j) is also an optimal solution with the same configuration as (i∗,j∗).
We again assume that none of the previously discussed cases happens.
The following lemma is literally the same as Lemma 11 although the proof
is different.
Lemma 13
i∗* is the largest index i∈[1,a∗] such that dP(v1,vi)<dP(vi,va∗).
j∗ is the smallest index j∈[b∗,n] such that dP(vj,vn)<dP(vj,vb∗).*
Proof
Unlike Lemma 11, the proofs here for the two parts of the
lemma are different.
We begin with the first statement for i∗.
Since v1 is not a farthest vertex of c∗ in G(i∗,j∗), we claim that dP(v1,vi∗)<dP(vi∗,va∗).
Indeed, since c∗ is to the right of b∗ and π∗ contains e(vi∗,vj∗), dG(i∗,j∗)(c∗,va∗)=dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,va∗)=r∗ and dG(i∗,j∗)(c∗,v1)=dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,v1). Since v1 is not a farthest point of c∗, dG(i∗,j∗)(c∗,v1)<r∗=dG(i∗,j∗)(c∗,va∗), which leads to dP(v1,vi∗)<dP(vi∗,va∗).
Assume to the contrary that i∗ is not the largest such index as stated in the lemma. Then, we must have dP(v1,vi∗+1)<dP(vi∗+1,va∗). We claim that the distances from c∗ to all vertices in G(i∗+1,j∗) are at most r∗. This can be proved by the similar argument as that for Lemma 11, so we omit the details. The claim implies that (i∗+1,j∗) is also an optimal solution with the same configuration as (i∗,j∗). Since [i∗+1,j∗]⊂[i∗,j∗], this contradicts with our assumption on [i∗,j∗].
We proceed to prove the second statement of the lemma for j∗.
Since vn is not a farthest vertex of c∗ in G(i∗,j∗), we claim that dP(vj∗,vn)<dP(vj∗,vb∗). Indeed, since c∗ is to the right of vb∗ and π∗ contains e(vi∗,vj∗), dG(i∗,j∗)(c∗,vn)=dP(c∗,vn). Because vn is not a farthest point of c∗ in G(i∗,j∗), dG(i∗,j∗)(c∗,vn)<r∗. Thus, dP(c∗,vn)<r∗.
Since vj∗∈P(c∗,vn), dP(vj∗,vn)≤dP(c∗,vn)<r∗=dP(c∗,vb∗)≤dP(vj∗,vb∗).
Next, we show that c∗ must be in the interior of e(vj∗−1,vj∗). Assume to the contrary this is not true. Then, since c∗=vj∗, c∗ is in P(vb∗,,vj∗−1) (e.g., see Fig. 17).
We claim that the distances from c∗ to all vertices in G(i∗,j∗−1) are at most r∗. Indeed, for each vertex vj to the right of c∗, dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vj)≤dP(c∗,vn)<r∗. For each vertex vj to the left of c∗ but to the right of vb∗, dG(i∗,j∗−1)(c∗,vj)≤dP(c∗,vj)≤dP(c∗,vb∗)=r∗. For each j∈[1,a∗], since dP(v1,vi∗)<dP(vi∗,va∗) (which was proved above), we have
[TABLE]
This proves the claim. The claim implies that (i∗,j∗−1) is also an optimal solution with the same configuration as (i∗,j∗). Since [i∗,j∗−1]⊂[i∗,j∗], this contradicts with our assumption on [i∗,j∗].
We proceed to show that j∗ is the smallest such index as stated in the lemma. Assume to the contrary that this is not true. Then, since dP(vj∗,vn)<dP(vj∗,vb∗), which is proved above, dP(vj∗−1,vn)<dP(vj∗−1,vb∗) must hold.
For a cycle C(i,j), let ∣C(i,j)∣ denote its total length.
Let r=(∣C(i∗,j∗−1)∣−∣va∗vb∗∣)/2. Note that r∗=(∣C(i∗,j∗)∣−∣va∗vb∗∣)/2. Due to the triangle inequality, we have ∣C(i∗,j∗−1)∣≤∣C(i∗,j∗)∣. Hence, r≤r∗. Let c be the point on C(i∗,j∗−1)∖e(va∗,vb∗) whose distances from va∗ and vb∗ are both equal to r (e.g., see Fig. 18). Note that c may be in P(vi∗,va∗), e(vi∗,vj∗−1)∖{vi∗,vj∗−1}, or P(vb∗,vj∗−1). In the following, we show that none of the three cases can happen.
If c∈P(vi∗,va∗), then let c′=vi∗ and we claim that the distances from c′ to all vertices in G(i∗,j∗−1) are smaller than r∗, which would incur contradiction. Indeed, since dP(c∗,vj∗)+∣vj∗vi∗∣+dP(vi∗,va∗)=r∗ and dP(c∗,vj∗)>0 (because c∗=vj∗), we have r=dP(c,va∗)≤dP(vi∗,va∗)<r∗. Hence, for each j∈[i∗,a∗], dG(i∗,j∗−1)(c′,vj)≤dP(c′,vj)≤dP(c′,va∗)<r∗. Since dP(v1,vi∗)<dP(vi∗,va∗), for each j∈[1,i∗], dG(i∗,j∗−1)(c′,vj)≤dP(c′,vj)≤dP(c′,v1)<dP(c′,va∗)<r∗.
For each j∈[b∗,j∗−1], dG(i∗,j∗−1)(c′,vj)≤∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vb∗)=r<r∗. Since dP(vj∗−1,vb∗)>dP(vj∗−1,vn), for each j∈[j∗,n], dG(i∗,j∗−1)(c′,vj)≤∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vj)≤dP(c,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vn)<dP(c,vi∗)+∣vi∗vj∗−1∣+dP(vj∗−1,vb∗)=r<r∗. The above claim is thus proved.
If c∈e(vi∗,vj∗−1)∖{vi∗,vj∗−1} (e.g., see Fig. 18), then we claim that the distances from c to all vertices in G(i∗,j∗−1) are at most r∗. Indeed, for each j∈[1,a∗], dG(i∗,j∗−1)(c,vj)≤∣cvi∗∣+dP(vi∗,vj)≤∣cvi∗∣+dP(vi∗,va∗)=r≤r∗. Similarly, for each j∈[b∗,n], dG(i∗,j∗−1)(c,vj)≤∣cvj∗−1∣+dP(vj∗−1,vj)≤∣cvj∗−1∣+dP(vj∗−1,vb∗)=r≤r∗. The claim thus follows. The claim implies that (i∗,j∗−1) is an optimal solution conforming with the configuration of Case 3.1 (i.e., the one shown in Fig. 12), which contradicts with our assumption that none of the previously discussed cases happens.
If c∈P(vb∗,vj∗−1), then let c′=vj∗−1. We claim that the distances from c′ to all vertices in G(i∗,j∗−1) are smaller than r∗, which would incur contradiction. Indeed, as c∗ is in the interior of e(j∗−1,j∗), r=dP(vb∗,c)≤dP(vb∗,c′)<dP(vb∗,c∗)=r∗. For each j∈[1,a∗], dG(i∗,j∗−1)(c′,vj)≤∣vj∗−1vi∗∣+dP(vi∗,vj)≤dP(c,vj∗−1)+∣vj∗−1vi∗∣+dP(vi∗,vj)≤dP(c,vj∗−1)+∣vj∗−1vi∗∣+dP(vi∗,va∗)=r<r∗.
For each j∈[b∗,n], since dP(vj∗−1,vn)<dP(vj∗−1,vb∗), dG(i∗,j∗−1)(c′,vj)≤dP(c′,vj)≤dP(c′,vb∗)<dP(c∗,vb∗)=r∗. The claim thus follows.
∎
Based on Lemma 13, our algorithm for this configuration works as follows.
We define i(k) and j(k) for each k∈[2,n−2] in the same way as those for Case 3.1, and their values have already been computed in Case 3.1. Then, for each k∈[2,n−2], let r(i)=(dP(vk,vi(k))+∣vi(k)vj(k)∣+dP(j(k),vk+1))/2, and if r(i)<dP(vk+1,vj(k)) (this makes sure that the center is on P(vk+1,vj(k)), then we keep (i(k),j(k)) as a candidate solution with r(i) as the radius. The definitions of i(k) and j(k) guarantee that it is a feasible solution. Finally, among the at most n candidate solutions, we keep the one with the smallest radius as the solution for this configuration. The total time of the algorithm is O(n).
Remark.
The above gives the algorithm for Case 3.2 when c∗ is to the right of vb∗. If c∗ is to the left of va∗, then we also use the above same values i(k), j(k), and r(i). We keep the candidate solution only if r(i)<dP(vi(k),vk) (this makes sure that the center is on P(vi(k),vk). In fact, the can unify our algorithms for Case 3.1 and Case 3.2 to obtain an algorithm for Case 3, as follows. We compute the same values i(k), j(k), and r(i) as before. Then, for each k∈[2,n−2], we keep (i(k),j(k)) as a candidate solution with r(i) as the radius. Finally, among all at most n candidate solutions, we keep the one with the smallest radius for Case 3.
Summary.
The above provides a linear time algorithm for computing a candidate solution (i,j) (along with a radius r and a corresponding center c) for each configuration so that if there is an optimal solution that has the same configuration then (i,j) is also an optimal solution with c as the center and r=r∗. On the other hand, each such solution is feasible in the sense that the distances from c to all vertices in G(i,j) are at most r. Given an input instance, since we do not know which configuration has an optimal solution, we use the above algorithm to compute a constant number of candidate solutions, and among them, we return the one with the smallest radius. The correctness follows our discussions above. The running time of the algorithm is O(n).
Theorem 3.1
The ROAP problem is solvable in linear time.
4 The Query Algorithm
As a by-product of our techniques, we present an O(logn) time algorithm to compute the radius and a center of the graph G(i,j)=P∪e(vi,vj) for any query pair of indices (i,j), after O(n) time preprocessing. The result may be interesting in its own right.
We perform the linear time preprocessing as in Section 2 so that dP(vi,vj) can be computed in O(1) time for any (i,j).
In addition, we need to perform preprocessing to answer the following range-maxima queries. Given any pair (i,j), find the interval [k,k+1] such that the length ∣vkvk+1∣ is the largest among all k∈[i,j−1]. The query can be answered in O(logn) time by using a binary search tree T as follows. T has n−1 leaves that correspond to the intervals [k,k+1] for k=1,2,…,n−1 respectively. The root of T stores the interval [k,k+1] with the largest ∣vkvk+1∣ for all k∈[1,n−1]. The left subtree of T is built with respect to k=1,2,…,⌊n/2⌋ recursively, and the right subtree is built with respect to k=⌊n/2⌋+1,…,n−1 recursively. T can be built in O(n) time in a bottom-up fashion. With T, each range-maxima query can be answered in O(logn) time in a standard way (e.g., like queries in segment or interval trees).
Remark.
Another more efficient but rather complicated method is to use range maxima data structure [3, 12], and each query can be answered in O(1) time and the preprocessing time is still O(n). However, since O(logn) time query is sufficient for our purpose, the above binary tree method, which is quite simple, is preferable.
The above is our preprocessing algorithm, which runs in O(n) time.
In the sequel, we present our query algorithm. Let (i,j) be a query with i≤j. Let G=G(i,j). Denote by c a center of G and r the radius. Note that Observation 1 is still applicable (replacing i∗, j∗, c∗, r∗ by i, j, c, r, respectively). Let a and b respectively be a∗ and b∗ stated in Observation 1, and let π be the union of the two paths πa and πb corresponding to πa∗ and πb∗ in Observation 1.
Without loss of generality, we assume that a≤b.
Our query algorithm works as follows. Depending on a, b, and π, there are several possible configurations as discussed in Section 3. For each configuration, we will compute in O(logn) time a candidate solution (i.e., a radius and a center) such that if that configuration happens then the candidate solution is an optimal solution. On the other hand, each solution is feasible in the sense that the distances from the candidate center to all vertices in G(i,j) is no more than the candidate radius. After the candidate solutions for all (a constant number of) configurations are computed, we return the solution with the smallest radius. The details are given below.
If c is on P(v1,vi), then dP(v1,vi)≥α(i,j) and r=(dP(v1,vi)+α(i,j))/2. Correspondingly, for this configuration, our algorithm works as follows.
We first compute dP(v1,vi) and α(i,j). For dP(v1,vi), it can be easily computed in O(1) time. For α(i,j), recall that α(i,j)=max{β(i,j),γ(i,j)}, β(i,j)=maxk∈[i,j]dC(i,j)(vi,vk), and γ(i,j)=∣vivj∣+dP(vj,vn). Clearly, γ(i,j) can be obtained in O(1) time. For β(i,j), we can compute it in O(logn) time by binary search. Indeed, let q be the point on C(i,j) such that dC(i,j)(vi,q)=(dP(vi,vj)+∣vivj∣)/2, i.e., half of the total length of the cycle C(i,j). Since ∣vivj∣≤dP(vi,vj), q must be on P(vi,vj). Note that q can be found in O(logn) time. Then, it can be verified the following is true. If q is at a vertex of P, then β(i,j)=(dP(vi,vj)+∣vivj∣)/2. Otherwise, suppose q is in the interior of the edge e(vk,vk+1) for some k∈[i,j−1] (k can be determined in the above binary search procedure for computing q); then β(i,j)=max{dP(vi,vk),∣vivj∣+dP(vk+1,vj)}, which can be computed in O(1) time.
After dP(v1,vi) and α(i,j) are computed, if dP(v1,vi)≥α(i,j), then we report r=(dP(v1,vi)+α(i,j))/2 and the point on P(v1,vi) whose distance from v1 is equal to r as the center c. Note that c can be found by binary search in O(logn) time. This finishes our algorithm for the case where c is on P(v1,vi). The algorithm runs in O(logn) time.
If c is on P(vj,vn), then we use a symmetric algorithm and we omit the details.
It remains to consider the configuration where c∈C(i,j)∖{vi,vj}. In the following, we consider the cases corresponding to those in Section 3. As in Section 3, whenever we discuss a configuration, we assume that none of the previously discussed configurations has an optimal solution.
4.0.1 Case 1: a=1.
In this case, depending on whether b=n or b∈[i,j], there are two subcases.
4.0.2 Case 1.1: b=n.
If π does not contain e(i,j), then π is the entire path P. Correspondingly, the radius of our candidate solution is P(v1,vn)/2 and the center can be computed by binary search in O(logn) time.
If π contains e(i,j), since c∈C(i,j)∖{vi,vj} and c∈π, c must be in the interior of e(i,j). Thus, r=(dP(v1,vi)+∣vivj∣+dP(vj,n))/2 and c is the point on e(i,j) such that dP(v1,vi)+∣vic∣=r.
In addition, it must hold that dG(c,vk)≤r for all k∈[i+1,j−1]. Hence, if i′ is the largest index such that dP(vi,vi′)≤dP(v1,vi) and if j′ is the smallest index such that dP(vj,vj′)≤dP(vj,vn), then it must hold that j′≤i′+1.
Correspondingly, our algorithm works as follows. We compute r′=(dP(v1,vi)+∣vivj∣+dP(vj,n))/2. We also compute the two indices i′ and j′ as defined above, which can be done in O(logn) time. If r′>dP(v1,vi), r′>dP(vj,vn), and j′≤i′+1, then we keep r′ as a candidate radius and c′ as the candidate center, where c′ is the point on e(i,j) with dP(v1,vi)+∣vic′∣=r′.
One can verify that our solution is feasible.
4.0.3 Case 1.2: b∈[i,j].
Depending on whether π contains e(vi,vj), there are two cases.
4.0.4 Case 1.2.1: e(vi,vj)∈π.
Depending on whether c is on e(vi,vj), there are further two subcases.
4.0.5 Case 1.2.1.1: c∈e(vi,vj) (e.g., similar to Fig. 7).
More precisely, c is in the interior of
e(vi,vj).
Define i′ as the smallest index such that dP(v1,vi)<dP(vi,vi′). Since v1 and vb are two farthest vertices of c and vb∈P(vi,vj), it can be verified that b=i′ (e.g., by a similar argument as for Lemma 7(2)) and dP(vi′,vj)≥dP(vj,vn).
Further, r=(dP(v1,vi)+∣vivj∣+dP(vi′,vj))/2.
Correspondingly, our algorithm works as follows. We first compute i′
by binary search in O(logn) time. If such an index i′ does
not exist or if i′≥j, then we stop the algorithm.
Otherwise, we compute r′=(dP(v1,vi)+∣vivj∣+dP(vi′,vj))/2.
If dP(v1,vi)<r′ and dP(vi′,vj)<r′ (this makes sure that the
center is in the interior of e(vi,vj)) and
dP(vi′,vj)≥dP(vj,vn), then we keep r′ as a candidate
radius for this case (the center can be computed on e(vi,vj) accordingly).
One can verify that our solution is feasible.
4.0.6 Case 1.2.1.2: c∈e(vi,vj).
In this case, c is in P(vb,vj)∖{vj} (e.g., similar to the bottom example in Fig. 1). Also, r=(dP(v1,vi)+∣vivj∣+dP(vj,vb))/2 and dP(vj,vn)≤dP(v1,vi)+∣vivj∣.
Define the index i′ in the same way as in the above Case 1.2.1.1. Then, we also have b=i′ (by a similar argument as for Lemma 8(2)).
Correspondingly, our algorithm works as follows. We first check whether dP(vj,vn)≤dP(v1,vi)+∣vivj∣ is true. If not, then we stop our algorithm. Otherwise, we compute the
index i′ as defined in the above Case 1.2.1.1.
If such an index i′ does not exist or if i′≥j, then we stop the algorithm.
Otherwise, we compute r′=(dP(v1,vi)+∣vivj∣+dP(vj,vi′))/2.
If dP(vi′,vj)>r′, then we keep r′ as a
candidate radius (the candidate center can be computed accordingly on P(vi′,vj)).
One can verify that our solution is feasible.
4.0.7 Case 1.2.2: e(vi,vj)∈π.
In this case, c∈P(vi,vb), π=P(v1,c)∪P(c,vb) (similar to Fig. 11), and
r=dP(v1,vb)/2.
Let i′ be largest index in [i,j] such that dP(v1,vi)<∣vivj∣+dP(vi′,vj). One can verify that b=i′ (by a similar argument as for Lemma 9(2)).
Since vb is a farthest vertex and dG(c,vb)=dP(c,vb),
for any k∈[b+1,n], dG(c,vk)=dP(c,vi)+∣vivj∣+dP(vj,vk).
In particular, we have
dG(c,vn)=dP(c,vi)+∣vivj∣+dP(vj,vn).
Since v1 is a farthest vertex and
dG(c,v1)=dP(c,v1)=dP(c,vi)+dP(vi,v1),
we can obtain dP(v1,vi)≥∣vivj∣+dP(vj,vn).
Correspondingly, our algorithm works as follows. We first check whether dP(v1,vi)≥∣vivj∣+dP(vj,vn). If not, we stop the algorithm. Otherwise, we compute the index i′, which can be done in O(logn) time by binary search. If no such index exists, then we stop the algorithm. Otherwise, we compute r′=dP(v1,vi′)/2. If r′>dP(v1,vi), then we keep r′ as a candidate radius (the center can be determined correspondingly on P(vi,vi′)).
One can verify that our solution is feasible.
4.0.8 Case 2: b=n.
This case is symmetric to the above Case 1 and we omit the details.
4.0.9 Case 3: a,b∈[i,j].
Depending on whether c∈e(vi,vj), there are two cases.
4.0.10 Case 3.1: c∈e(vi,vj).
In this case, as argued in Section 3, b=a+1 (similar to the example in Fig. 12). Let ∣C(i,j)∣ denote the total length of the cycle C(i,j). We have r=(dP(vi,va)+∣vivj∣+dP(vb,vj))/2=(∣C(i,j)∣−dP(va,vb))/2.
Let i′ be the smallest index such that dP(v1,vi)≤dP(vi,vi′) and
let j′ be the largest index such that dP(vj′,vj)≥dP(vj,vn).
Let i′′ be the smallest index such that ∣vjvi∣+dP(vi,vi′′)+dP(vi′′,vi′′+1)/2>∣C(i,j)∣/2 (intuitively, if p is the point on C(i,j) whose distance from vj is ∣C(i,j)∣/2, then if we traverse C(i,j) from vj in counterclockwise order, after we pass p, the mid point of dP(vi′′,vi′′+1) will be encountered first among the mid points of P(vk,vk+1) for all k∈[i,j−1]; e.g., see Fig. 19).
Symmetrically, let j′′ be the largest index such that ∣vivj∣+dP(vj,vj′′−1)+dP(vj′′−1,vj′′)/2>∣C(i,j)∣/2.
Let a′=max{i′,i′′} and b′=min{j′,j′′}.
We have the following lemma.
Lemma 14
a′≤a<b≤b′.
a is the index k∈[a′,b′−1] such that dP(vk,vk+1) is the largest.
Proof
Clearly, dG(c,v1)=∣cvi∣+dP(vi,v1) and dG(c,va)=∣cvi∣+dP(vi,va). Since dG(c,v1)≤dG(c,va)=r, dP(v1,vi)≤dP(vi,va). The definition of i′ implies that a≥i′. By a similar argument we can show b≤j′.
On the other hand, since c is in the interior of e(vi,vj), ∣vivj∣>∣cvi∣ and
∣cvi∣+dP(vi,va)=r=(∣C(i,j)∣−dP(va,va+1))/2. Hence,
∣cvi∣+dP(vi,va)+dP(va,va+1)/2=∣C(i,j)∣/2. Also, since ∣vivj∣>∣cvi∣, we obtain
∣vjvi∣+dP(vi,va)+dP(va,va+1)>∣C(i,j)∣/2.
According to the definition of i′′, we have a≥i′′. By a similar argument we can show b≤j′′.
The above proves that a′≤a<b≤b′.
For the second statement of the lemma,
assume to the contrary that dP(va,va+1)<dP(vk,vk+1) for some k=a and k∈[a′,b′−1].
Then, let c′ be the point on C(i,j) whose distance from the mid point of P(vk,vk+1) is ∣C(i,j)∣/2. Let r′=(∣C(i,j)∣−dP(vk,vk+1))/2, which is smaller than r due to dP(va,va+1)<dP(vk,vk+1). Since k∈[a′,b′−1], one can verify that c′ is in the interior of e(vi,vj), ∣c′vi∣+dP(vi,v1)≤r′, and ∣c′vj∣+dP(vj,vn)≤r′. Therefore, the distances from c′ to all vertices in G(i,j) are smaller than r, which contradicts with that r is the radius of G(i,j). ∎
Correspondingly, our algorithm works as follows. We first compute a′ and b′, which can be done by binary search in O(logn) time. If one of a′ and b′ does not exist, or a′≥b′, then we stop the algorithm. Otherwise, we compute the index k∈[a′,b′−1] such that dP(vk,vk+1) is the largest, which can be done in O(logn) time by our range-maxima data structure using the query range (a′,b′). Then, we compute r′=(∣C(i,j)∣−dP(vk,vk+1))/2 as the radius for our candidate solution (the center can be determined on e(vi,vj) accordingly).
One can verify that our solution is feasible.
4.0.11 Case 3.2: c∈e(vi,vj).
In this case, c is in the interior of P(vi,vj). Similar to the argument in Section 3, b=a+1, and c is either to the right of vb or to the left of va. We only discuss the former case since the latter case is similar. In this case (similar to the example in Fig. 15), for each k∈[1,a], the shortest path from c to vk in G contains e(vi,vj). For each each k∈[b,n], the shortest path from c to vk is P(c,vk). Since va is a farthest vertex, we have dP(v1,vi)≤dP(vi,va) and dP(vj,vn)≤∣vjvi∣+dP(vi,va).
Let i′ be the smallest index such that dP(v1,vi)≤dP(vi,vi′).
Let i′′ be the smallest index such that dP(vj,vn)≤∣vjvi∣+dP(vi,vi′′).
Let b′ be the largest index such that dP(vj,vb′)+dP(vb′,vb′−1)/2>∣C(i,j)∣/2.
Let a′=max{i′,i′′}. We have the following lemma.
Lemma 15
a′≤a<b≤b′.
a is the index k∈[a′,b′−1] such that dP(vk,vk+1) is the largest.
Proof
Since dP(v1,vi)≤dP(vi,va) and dP(vj,vn)≤∣vivj∣+dP(vi,va),
we obtain that a≥i′ and a≥i′′, and thus a≥a′.
On the other hand, since c is in P(vb,vj)∖{vj}, dP(vj,vb)>dP(c,vb)=r=(∣C(i,j)∣−dP(vb,vb−1))/2. Hence,
dP(vj,vb)+dP(vb,vb−1)/2>∣C(i,j)∣/2.
Therefore, b≤b′.
The above proves that a′≤a<b≤b′.
For the second statement of the lemma, assume to the contrary that dP(va,va+1)<dP(vk,vk+1) for some k=a and k∈[a′,b′−1].
Then, let c′ be the point in C(i,j) whose distance from the mid point of P(vk,vk+1) is ∣C(i,j)∣/2. Let r′=(∣C(i,j)∣−dP(vk,vk+1))/2, which is smaller than r due to dP(va,va+1)<dP(vk,vk+1).
Since k∈[a′,b′−1], one can verify that c′ is in
P(vk+1,vj)∖{vj} and dP(v1,vi)+∣vivj∣+dP(vj,c)≤r′ and dP(c′,vn)≤r′. Therefore, the distances from c′ to all vertices in G(i,j) are
smaller than r, which incurs contradiction. ∎
Correspondingly, our algorithm works as follows. We first compute a′
and b′ in O(logn) time by binary search. If one of a′ and b′ does not exist, or a′≥b′, then
we stop the algorithm. Otherwise, we compute the index k∈[a′,b′−1] such that dP(vk,vk+1) is the largest, which can be
done in O(logn) time by using a range-maxima query as in Case 3.1. Finally, we compute r′=(∣C(i,j)∣−dP(vk,vk+1))/2 as the radius for our candidate solution (the center can be determined on P(vk+1,vj) accordingly).
One can verify that our solution is feasible.
Summary.
The above gives our algorithms for all
possible configurations. For each configuration, we compute a candidate solution (a radius r′ and a center c′) in O(logn) time, such that if the configuration has an optimal solution then our solution is also optimal. On the other hand, each candidate solution is feasible in the sense that the distances from c′ to all vertices in G(i,j) are at most r′. Among all (a constant number of) candidate solutions, we return the one with the smallest radius. The running time is O(logn).
Theorem 4.1
After O(n) time preprocessing, given any query index pair
(i,j), we can compute the radius and the center of the augmented
graph P∪{e(vi,vj)} in O(logn) time.