Journal of Computational Geometry
jocg.org
COMPUTING THE MAXIMUM DETOUR OF A PLANE GEOMETRIC GRAPH IN SUBQUADRATIC TIME ∗ Christian Wulff-Nilsen
†
Abstract. Let G be a plane graph where each edge is a line segment. We consider the problem of computing the maximum detour of G, defined as the maximum over all pairs of distinct points p and q of G of the ratio between the distance between p and q in G and the Euclidean distance kpqk. The fastest known algorithm for this problem has Θ(n2 ) running time where n is the number of vertices. We show how to obtain O(n3/2 log3 n) expected running time. We also show that if G has bounded treewidth, its maximum detour can be computed in O(n log3 n) expected time.
1 Introdu tion Let G be a geometric graph, i.e., a graph drawn in the plane where each edge e is a line segment and the length of e is equal to the Euclidean distance between its endpoints. The stretch factor (or dilation) of G is the maximum over all pairs of distinct vertices u and v of the ratio between the distance between u and v in G and the Euclidean distance kuvk between u and v. A spanner is a network with small stretch factor. Finding spanners that keep other cost measures low, such as size, weight, degree, and diameter, is an important problem that has received a great deal of attention in recent years. Such networks are not only of theoretical interest but have also found practical applications in areas such as VLSI design, distributed computing, and robotics. For more on spanners, see [8, 15, 18]. Narasimhan and Smid [14] considered the interesting dual problem of computing the stretch factor of a given geometric graph. They showed how to approximate the stretch √ factor in O(n log n) time for paths, trees, and cycles, and in O(n n) time for arbitrary planar geometric graphs, where n is the number of vertices. A related problem is that of computing the so called maximum detour of a geometric graph. Maximum detour is defined like stretch factor except that the maximum is taken over all pairs of distinct points of the graph, i.e., interior points of edges as well as the vertices. We only need to consider the problem for plane geometric graphs since otherwise, the maximum detour is undefined (or infinite). Applications include on-line search strategies [10] and comparing Fr´echet and Hausdorff distances of curves [2]. The problem was first considered in [7], where an O(n log n) time algorithm for approximating the maximum detour of a path was given. ∗ †
Research partially supported by NSERC and MRI. School of Computer Science, Carleton University,
[email protected] JoCG 1(1), 101–122, 2010
101
Journal of Computational Geometry
jocg.org
Exact algorithms that compute the stretch factor and maximum detour of paths, trees, and cycles in 2D and 3D were given in [1, 11]. In two dimensions, these algorithms run in O(n log n) expected time for paths and in O(n log2 n) expected time for trees and cycles. Using parametric search techniques, worst-case O(n polylog n) time bounds can be obtained. Algorithms with O(n polylog n) worst-case running time that compute the stretch factor of paths, trees, and cycles in (Rd , L1 ) and arbitrary weighted fixed orientation metrics in the plane were presented in [20]. For geometric graphs of bounded treewidth, it has been shown how to compute the stretch factor in O(n polylog n) time [4]. The stretch factor of an arbitrary plane geometric graph can be computed in Θ(n2 ) time by applying the all-pairs shortest paths algorithm in [9]. This bound also holds for the problem of computing the maximum detour of a plane geometric graph [1]. As mentioned in [1, 11, 14], it is open whether subquadratic time algorithms exist. In this paper, we show how to compute the maximum detour of a plane geometric graph in O(n3/2 log3 n) expected time, thereby solving the open problem of whether a subquadratic time algorithm exists for this problem. We also show that if the graph has bounded treewidth, its maximum detour can be computed in O(n log3 n) expected time. To obtain our results, we make use of a geometric property from [7] that allows us to restrict our attention to pairs of points on the same face of the graph. As in the all-pairs shortest paths algorithm of Frederickson [9], we also rely heavily on separator properties of planar graphs, obtained from the classical separator theorem of Lipton and Tarjan [12]. The organization of the paper is as follows. In Section 2, we give various definitions and introduce some notation. In Section 3, we make use of the separator theorem to apply divide-and-conquer to the input graph. We define colourings of points of a face of the graph in Section 4, show some properties of these colourings and how to efficiently compute them. In Section 5, we show how the colourings give an efficient way of computing the maximum detour between points on a face of the graph and this in turn gives an efficient divide-andconquer algorithm for computing the maximum detour of the entire graph. In Section 6, we remove the restriction that faces have to be simple and in Section 7, we describe in detail how our algorithm handles recursive calls. We consider graphs of bounded treewidth in Section 8. Finally, we make some concluding remarks in Section 9.
2 De nitions and Notation Let G = (V, E) be a plane graph where each edge is a line segment and let MG be the set of points of G (vertices as well as interior points of edges). Given two points p, q ∈ MG , we define dG (p, q) as the length of a shortest path in G between p and q, where the length of a path is measured as the sum of the Euclidean lengths of the (parts of) edges on this path. If there is no such path, we define dG (p, q) = ∞. If p 6= q then the detour δG (p, q) between p and q (in G) is defined as the ratio dG (p, q)/kpqk. The maximum detour δG of G is the maximum of this ratio over all pairs of distinct points of MG . Where appropriate, we will regard a plane graph as the set of points belonging to the graph. So for instance, if G and H are plane graphs then G ∩ H is the set of points belonging to both G and H. If well-defined, we will regard the resulting point set as a JoCG 1(1), 101–122, 2010
102
Journal of Computational Geometry
jocg.org
graph. For a graph G, we let |G| denote its size, i.e. the number of vertices plus the number of edges in G. Given two subsets M1 and M2 of the set MG of points of G, we define δG (M1 , M2 ) =
max
p∈M1 ,q∈M2 ,p6=q
δG (p, q)
If p ∈ MG and M ⊆ MG , we write δG (p, M ) = δG (M, p) instead of δG ({p}, M ) and we write δG (M ) as a shorthand for δG (M, M ). We extend these definitions to subgraphs, edges, and vertices by regarding them as sets of points. Given paths P = p1 → p2 → . . . → pr and Q = q1 → q2 → . . . → qs , where pr = q1 , we let P Q denote the combined path p1 → p2 → . . . → pr−1 → (pr = q1 ) → q2 → . . . → qs . For a vertex v, we let v → P denote the path v → p1 → p2 → . . . → pr .
3 Divide and Conquer In all the following, let G = (V, E) be an n-vertex plane graph in which edges are line segments. We seek to compute δG in O(n3/2 log3 n) expected time. We will assume that G is connected since otherwise, the problem is trivial. To compute δG , we apply the divide-and-conquer paradigm. Our strategy is in some ways similar to that of Cabello and Knauer [4] for computing the stretch factor and sum of all pairwise distances between vertices in a geometric graph of bounded treewidth. Their algorithm applies divide-and-conquer after separating the graph using a constant-size separator (we use this separator when we consider graphs of bounded treewidth in Section 8). To merge the two recursively computed solutions, they make use of data structures for √ orthogonal range searching in bounded dimension. In our algorithm, we apply a O( n)size separator theorem for planar graphs (see below) and in the merge step, we use face colourings (Section 4) instead of range searching to speed up computations. In this section, we separate G into two smaller graphs, GA and GB , of roughly the same size. We recursively compute δG (GA ) and δG (GB ) and in Section 5, we describe an algorithm for efficiently obtaining the maximum detour δG (GA , GB ). To separate our problem, we use the separator theorem of Lipton and Tarjan [12]. This gives us, in O(n) time, a partition of V into three sets, A, B, and C, such that the following three properties hold: 1. no edge joins a vertex in A with a vertex in B, 2. neither A nor B contains more than n/2 vertices, and √ √ n vertices. 3. C contains no more than 2√2 1−
2/3
We refer to vertices of C as portals. We must have C 6= ∅ since otherwise, one of the sets A and B would be empty by property 1, implying that |A| = n or |B| = n, contradicting property 2. In the following, let k ≥ 1 denote the number of portals and let p1 , . . . , pk denote the portals. JoCG 1(1), 101–122, 2010
103
Journal of Computational Geometry
jocg.org
Having found this partition, we compute and store shortest path lengths from each portal to each vertex of V . Using Dijkstra’s single source shortest path (SSSP) algorithm with, say, binary heaps, this can be done in O(n log n) time for each portal, giving a total running time of O(n3/2 log n). Let GA be the subgraph of G induced by A ∪ C and let GB be the subgraph of G induced by B ∪ C. We construct GA and GB and recursively compute δG (GA ) and δG (GB ). Clearly, δG = max{δG (GA ), δG (GB ), δG (GA , GB )}. We say that two points p, q ∈ MG are co-visible (w.r.t. MG ) if line segment pq contains no points of MG in its interior. In [7], it is shown that the maximum detour of a simple path is achieved by a pair of co-visible points. The following lemma generalizes this result, showing that it also holds for G. We omit the proof as it is virtually identical to that in [7]. Lemma 1. The maximum detour δG is achieved by a pair of co-visible points. This result allows us to consider only detours between pairs of points of the same face of G. In all the following, let f be a face of G, let fA = f ∩ GA , and let fB = f ∩ GB . We will show how to compute δG (fA , fB ) in O(|f |k log2 n) expected time. From this it will follow that δG (GA , GB ) can be found in O(n3/2 log2 n) expected time. We will assume that f is an internal face of G. The external face is dealt with in a similar way. We also assume that fA and fB do not share any edges since any edge e shared by them must have portals as both endpoints and the detours from points in e to all points in G will be considered in the two recursive calls that compute δG (GA ) and δG (GB ). Hence, we may disregard e when computing δG (fA , fB ). Note that fA and fB may be disconnected sets. We assume for now that f is simple.
4 Colouring Points In this section, we define colourings of points of face f . As we shall see in Section 5, these colourings will prove helpful when computing δG (fA , fB ). More specifically, we define colourings such that there is a one-to-one correspondence between colours and portals. For each point a in fA , we partition fB into colour intervals which are maximal intervals of points having the same colour. For the interval I of fB with colour associated with a portal p, there are shortest paths from a to the points in I all of which go through p. We will show how this information allows us to compute the maximum detour between points of fA and points of intervals of the same colour in fB by carefully partitioning these intervals into a small set of so called canonical intervals and applying an efficient algorithm for points in fA and their associated canonical intervals. Taking the maximum detour computed for all colours, we get δG (GA , GB ) within the desired time bound. To find the colour intervals, we first show how an ordering of the portals (Section 4.3) induces an ordering of the colour intervals (Section 4.4). To find this ordering, we make use JoCG 1(1), 101–122, 2010
104
Journal of Computational Geometry
jocg.org
of an efficient sorting algorithm (Section 4.5). When the ordering is given, we show how to compute the interval endpoints (Section 4.6), thereby obtaining an implicit representation of colour intervals.
4.1 Ordering fa e points Let us start by ordering points on face f . This face is defined by a simple cycle v1 → v2 → . . . → vnf → v1 such that the interior of f is to the left as we walk in the direction specified by the vertices. For a point p ∈ f , we let df (p) denote the Euclidean length of the path from v1 to p that visits vertices in the order specified above. We define an order