ALL-PAIRS SHORTEST PATHS IN GEOMETRIC INTERSECTION GRAPHS

. We present a simple and general algorithm for the all-pairs shortest paths (APSP) problem in unweighted geometric intersection graphs. Speci(cid:28)cally we reduce the problem to the design of static data structures for o(cid:31)ine intersection detection. Consequently we can solve APSP in unweighted intersection graphs of n arbitrary disks in O (cid:0) n 2 log n (cid:1) time, axis-aligned line segments in O (cid:0) n 2 log log n (cid:1) time, arbitrary line segments in O (cid:16) n 7 / 3 log 1 / 3 n (cid:17) time, d -dimensional axis-aligned unit hypercubes in O (cid:0) n 2 log log n (cid:1) time for d = 3 and O (cid:0) n 2 log d − 3 n (cid:1) time for d ≥ 4 , and d -dimensional axis-aligned boxes in O (cid:0) n 2 log d − 1 . 5 n (cid:1) time for d ≥ 2 . We also reduce the single-source shortest paths (SSSP) problem in unweighted geometric intersection graphs to decremental intersection detection. Thus, we obtain an O ( n log n ) -time SSSP algorithm in unweighted intersection graphs of n axis-aligned line segments.


Introduction
As a motivating example, consider the following toy problem. Given a set S of n axisaligned line segments that represents a road network and two points p 1 and p 2 that lie on two segments of S, compute a path on S from p 1 to p 2 such that the number of turns is minimized. See   To solve this toy problem, we could build the intersection graph G of S, i.e., create a vertex for each segment of S and an unweighted, undirected edge between two vertices if their Journal of Computational Geometry jocg.org corresponding segments intersect. Then given two points p 1 and p 2 that lie on the segments s and t of S, a p 1 -to-p 2 minimum-turn path corresponds to an s-to-t shortest path in G. We could nd such a path with breadth-rst search (BFS) in G in O n 2 time. However, we observe in Section 4 an O (n log n)-time algorithm by applying data structures for dynamic orthogonal point location [25,7], which has not been noticed before. Our algorithm in fact solves the more general single-source shortest paths (SSSP) problem: given a source vertex, compute the shortest paths from it to all vertices.
Our main focus in this paper is a problem similar to SSSP, namely the all-pairs shortest path (APSP) problem, where we want to compute all pairwise shortest paths. We study APSP in unweighted geometric intersection graphs, dened similarly to the above paragraph. In general unweighted, undirected graphs the problem can be solved in O (n ω ) time (e.g., see [5,31]), where ω < 2.373 is the matrix multiplication exponent [32], but better results are possible for geometric intersection graphs.
Our main results are as follows.
• In arbitrary disk graphs, naturally motivated by applications in ad-hoc communication networks, we can solve APSP in O n 2 log n time. Following work by Cabello and Jej£i£ [8] on SSSP in unit-disk graphs, a previous paper by the authors [15] gave an O n 2 log log n log n -time algorithm therein, but the approach cannot be extended to arbitrary disk graphs. For arbitrary disk graphs, the dynamic Voronoi diagrams data structure of Kaplan et al. [28] can be employed to solve the problem in nearly O n 2 log 12 n time, 1 as explained in the next page.
• In axis-aligned line segments, we can solve APSP in O n 2 log log n time, which is better than running n times our O (n log n)-time SSSP algorithm that we mentioned earlier. No previous results for the problem have been reported, to the best of the authors's knowledge.
• When the line segments are not axis aligned but have arbitrary orientations instead, we can solve APSP in O n 7/3 log 1/3 n time. Our result is a little better than the O (n ω )-time solutions [5,31] for general unweighted, undirected graphs, at least with the current upper bound on ω < 2.373 [32,30]. Regardless, our algorithm has the advantage of being combinatorial.
• See Table 1 for further results in intersection graphs of axis-aligned boxes, unit hypercubes, and fat triangles of roughly equal size.
All these results stem from a simple and general technique, described in Section 3.
Specically we reduce APSP to static, oine intersection detection: given a query object, decide whether there is an input object that intersects it (and report one if the answer is yes). Our algorithm visits the vertices of the given graph in an order prescribed by a spanning  tree T and generates the shortest-path tree of each vertex s by using the shortest-path tree from its parent s in T as a guide. To do that quickly, we exploit the fact that distances from s are approximately known up to ±1 and also employ the right geometric data structures. Some form of this simple idea has appeared before for general graphs (e.g., see [4,10]), but it is somehow overlooked by previous researchers in the context of geometric APSP.
Our solution compares favorably with the two previous general methods for the problem.
• The rst general method runs an SSSP algorithm from every source independently by a reduction to dynamic data structuring problems, as observed by the ideas of Chan and Efrat [12]. Actually the reduction is much simplied in the unweighted, undirected setting. However dynamic data structures for geometric intersection or range searching usually are more complicated and have slower query times than their static counterparts, sometimes by multiple logarithmic factors. For example, the arbitrary disk case employs dynamic data structures for additively weighted nearest-neighbor search. Thus solving the problem that way takes nearly O n 2 log 12 n time [28], while our approach requires only O n 2 log n time.
• The second general method employs biclique covers [23,2] to sparsify the intersection graph and then applies an SSSP algorithm from each vertex. However, biclique covers are related to static, oine intersection searching (e.g., as noted in [9]), which is generally harder than intersection detection. For example, the sparsied intersection graph of d-dimensional boxes has O n log d n edges, leading to an O n 2 log d ntime algorithm, but our solution requires O n 2 log d−1.5 n time. For arbitrary disks, the complexity of the biclique covers is even worse (O n 3/2+ε [3]), leading to an O n 5/2+ε -time algorithm, which is much slower than our O n 2 log n solution.
To derive our result for intersection graphs of axis-aligned boxes, we describe in Section 5 a new O n √ log n -time algorithm for oine rectangle stabbing in two dimensions: preprocess n axis-aligned rectangles and n points, such that we can nd a rectangle (if any) that stabs each query point. That data structure may be of independent interest. Journal of Computational Geometry jocg.org 2 Preliminaries

Definitions and notations
Recall that an unweighted geometric intersection graph G is the intersection graph of a set S of geometric objects. That is, vertices correspond to objects and edges to pairwise intersections. We assume that these objects are of constant-description complexity, that G is represented implicitly by S (thus it can be stored with only linear space), and that G, without loss of generality, is connected.
Let S be a set of geometric objects, and let G be the unweighted geometric intersection graph it denes. For any s, t ∈ S we let π[s, t] denote an s-to-t shortest path in G and let dist[s,t] denote its length. We also refer to dist[s,t] as shortest-path distance or simply distance. By pred[s,t] we denote t's predecessor on π[s, t]. Also, we dene the shortest-path tree T (s) of s ∈ S to be a spanning tree of G rooted at s, such that for each t ∈ S the s-to-t shortest-path distance in T (s) corresponds to dist[s,t].

Model of computation
Throughout the paper, we use the standard (real) RAM model of computation. Specically, we have random access to an array of words, each storing a real number, a Θ (log n)-bit integer (where n is the input size), or a pointer to another word. Moreover, we can perform any standard arithmetic operation, such as addition, subtraction, multiplication, division, and comparison, that involves a constant number of words in constant time. We assume that we can compute square roots of real numbers exactly in constant time.
We can support custom operations in (δ log n)-bit words in O (1) time, where 0 < δ < 1 is a constant, after o(n) preprocessing time. To do so, we can perform the desired operation to each of the 2 δ log n = n δ = o(n) possible inputs and store the results in a lookup table (assuming that each operation can naively be performed in O log O(1) n time).

Reducing APSP to static, offline intersection detection
Here, we reduce APSP in unweighted, undirected geometric intersection graphs to static, oine intersection detection. We rst build an arbitrary spanning tree T 0 of G, root it at an arbitrary object s 0 ∈ S, and compute the shortest-path tree of s 0 . Then, we visit each object s of T 0 in a pre-order manner and compute its shortest-path tree by using that of s as a guide, where s is the parent of s in T 0 . See Algorithm 1 for the pseudocode.
It remains to describe how to compute the shortest-path tree from an object s ∈ S, given the shortest-path tree from its parent s in T 0 (Line 5 in Algorithm 1). We rst notice that from the triangle inequality and from dist[s, That is, we already have an ±1-additive approximation of the distances from s; see Figure 2. To compute the exact distances from s, we devise a BFS-like algorithm of n − 1 steps, where in the beginning of each step , we assume that we have properly processed each t ∈ S at distance at most − 1 from s. We call the rest Journal of Computational Geometry jocg.org Algorithm 1: GeoAPSP(S) 1 build the unweighted, undirected geometric intersection graph G of S 2 compute any spanning tree T 0 of G and root it at any s 0 ∈ S 3 compute T (s 0 ) 4 for each s ∈ S − {s 0 } following a pre-order traversal of T 0 do 5 compute T (s) by using T (s ) as a guide, where s is the parent of s in T 0 of the objects undiscovered and those at distance exactly − 1 from s frontier. However, contrary to the classical BFS, in each step we do not have to consider all undiscovered objects. Specically, the ±1-additive approximation of the distances from s implies that the only undiscovered objects that can be at distance from it are the ones at distance − 1, , or + 1 from s . We call these candidate objects. Thus, we need to nd for each candidate whether there is any frontier object that intersects it. This is an instance of the following problem: Subproblem 1. (Intersection Detection) Preprocess a set of input objects into a data structure, such that we can quickly decide if a given query object intersects any input object, and, if it does, report any such object.
The input (frontier objects) is static, and the queries (candidate objects) are oine, i.e., are all given in advance. The pseudocode is presented in Algorithm 2. (Computing shortest-path trees with ±1-additive approximation) Given a set S of n objects and the shortest-path tree of s ∈ S in the unweighted, undirected intersection graph of S, we can compute the shortest-path tree from an neighbor s ∈ S of s in O(SI (n, n)) time, where SI(n,m) is the time to construct a static, oine intersection detection data structure (Subproblem 1) for n objects and query it m times. We assume that SI(n 1 , m 1 ) + SI(n 2 , m 2 ) ≤ SI(n 1 + n 2 , m 1 + m 2 ).
Proof. As discussed above, the ±1 approximation of the distances from s implies that the candidate objects are the only undiscovered objects that need to be considered in each step. Thus, the correctness of our algorithm follows from that of classical BFS.
Journal of Computational Geometry jocg.org build a static, oine intersection detection data structure with input set F (frontier objects) and query set C (candidate objects) Let n (respectively m ) be the number of frontier (respectively candidate) objects in the step of our algorithm. An object is a frontier object exactly once and a candidate object at most thrice, i.e., n−1 =1 n ≤ n and n−1 =1 m ≤ 3n. Thus, the time to compute the shortest-path tree from s is O n−1 =1 SI(n , m ) = O (SI(n, n)). Theorem 2. (APSP in unweighted, undirected geometric intersection graphs) We can solve APSP in an unweighted geometric intersection graph of n objects in O n 2 + nSI (n, n) time, where SI(·,·) is as in Theorem 1. Proof. In Lines 13 of Algorithm 1, we can build G, nd a spanning tree T 0 , and compute the shortest-path tree from s 0 naively in O n 2 total time. By Theorem 1, each of the n − 1 iterations of Line 3 of Algorithm 1 takes O (SI (n, n)) time.

Applications
In this section, we use known results to provide static, oine intersection detection data structures for a family of geometric objects and then apply Theorem 2 to solve APSP in the corresponding intersection graphs. Let SI(·, ·) be as in Theorem 1.
Arbitrary disks. Given a set of n disks, we create an additively weighted Voronoi diagram and a point location data structure for the cells of that diagram. The sites are the disk centers, and the weight of each site is equal to the radius of the corresponding disk, i.e., Journal of Computational Geometry jocg.org the distance between a site p corresponding to a disk of radius r p and a point q is dened as d(p, q) = ||p − q|| − r p . To detect an intersection of a query disk with an input disk of radius r q that is centered at q, we can nd the input point p that minimizes d(p, q) and check whether d(p, q) ≤ r q . Employing the additively-weighted Voronoi diagram algorithm of Fortune [24] together with the point location data structure of Edelsbrunner et al. [19], we have SI(n,n) = O (n log n). See Figure 3. Theorem 3. We can solve APSP in an unweighted intersection graph of n arbitrary disks in O n 2 log n time.
Axis-aligned line segments. To construct a static, oine intersection data structure for n axis-aligned line segments we can without loss of generality consider only horizontal input segments and only vertical query segments. We build the vertical decomposition of the former and store it in a point location data structure. Then, given a vertical query segment, we perform a point location query with its endpoints. If they lie in the same cell, there is no intersection. Otherwise, we pick the cell that contains the bottom endpoint of the query segment and report the input segment that bounds its upper side. See Figure 4. Axis-aligned boxes in d dimensions. Oine rectangle intersection counting in n axisaligned rectangles in the plane is known to be reducible [21] to oine orthogonal range counting, for which Chan and P tra³cu [14, Corollary 2.3] have given an O n √ log n -time algorithm, assuming that the x-and y-coordinates of all the vertices of the rectangles have been presorted. Thus, we can decide for each query box whether it intersects any input box. In Section 5, we adapt the technique of Chan and P tra³cu to construct a data structure that can also report such an input box if it exists. Hence, after presorting the coordinates in O (n log n) time, we have that SI(n,n) = O n √ log n . For axis-aligned boxes in d ≥ 3 dimensions, we use standard range trees [20] with the above planar base case to obtain SI(n,n) = O n log d−1.5 n . Theorem 6. We can solve APSP in an unweighted intersection graph of n d-dimensional axis-aligned boxes in O n 2 log d−1.5 n time, for d ≥ 3.
Axis-aligned unit hypercubes in d dimensions. We can construct more ecient static, oine data structures when the n boxes are unit hypercubes. Specically, we rst build a uniform grid with unit side length and then solve the problem inside each grid cell separately. Each input or query unit hypercube participates in at most a constant (2 d ) number of grid cells, and inside each of them, it is eectively unbounded along d sides. We assume without loss of generality that each input box is of the form (−∞, a 1 ] × · · · × (−∞, a d ] and that each query box is of the form [b 1 , ∞) × · · · × [b d , ∞). Thus, the problem reduces to oine dominance detection: decide for each query point (b 1 , . . . , b d ) whether it is dominated by some input point (a 1 , . . . , a d ), and, if yes report one such input point.
Journal of Computational Geometry jocg.org For d = 3, the algorithm of Gupta et al. [26,Theorem 3.1] answers n oine dominance reporting queries in O ((n + K) log log U ) time, where n is the input size, and K is the total output size, assuming that all coordinates are integers bounded by U . Thus, n oine dominance detection queries can be answered in O (n log log U ) time. By presorting all coordinates in O (n log n) time and replacing each with its rank, we ensure that U = n. Hence, SI(n, n) = O (n log log n). For d ≥ 4, Afshani et al. [1, Remark in Section 5] (following Chan et al. [13]) has given a deterministic algorithm to answer n oine dominance reporting queries in O n log d−3 n + K time, where n is the input size, and K is the total output size. It can be checked that n oine dominance detection queries can be answered in O n log d−3 n time. Fat triangles. Given n fat triangles (i.e., triangles of bounded inradius-to-circumradius ratios) of roughly equal sizes, Katz [29, Theorem 4.1(i)] has shown how to construct an intersection reporting data structure of O n log 4 n preprocessing and O log 3 n + K log 2 n query time, where n is the input size, and K is the total output size (here K ≤ 1). Hence, SI(n,n) = O n log 4 n . Theorem 8. We can solve APSP in an unweighted intersection graph of n fat triangles of roughly equal sizes in O n 2 log 4 n time.

Reducing SSSP to decremental intersection detection
We now show how to reduce SSSP in unweighted, undirected geometric intersection graphs to decremental intersection detection. Our approach is again to use a BFS-like algorithm. See Algorithm 3 for the pseudocode. As in classical BFS, we want to nd every undiscovered object that shares an edge with a frontier object, but inspecting all edges incident to the latter ones would require quadratic total time. However, in geometric intersection graphs, an edge between two objects exists if and only if they intersect each other, so it suces to nd for each undiscovered object one, if any, frontier object that intersects it. To do so, we would like to solve the decremental version of Subproblem 1, i.e., the input undergoes only deletions.
An object is undiscovered only until we nd a frontier object that intersects it. Thus, we can employ a decremental intersection detection data structure for the undiscovered objects and query it in each step of the algorithm with the frontier objects. Whenever we detect an intersection, we properly set the distance and predecessor of the relevant undiscovered object and delete it from the data structure. Theorem 9. (SSSP in unweighted, undirected geometric intersection graphs) We can solve SSSP in an unweighted, undirected geometric intersection graph of n vertices in O(DI (n, n)) time, where DI(n,m) is the required time to construct a decremental intersection detection data structure of n objects and perform n deletions and m queries.
Journal of Computational Geometry jocg.org Proof. In unweighted, undirected geometric intersection graphs, there is an edge between two objects if and only if they intersect, so the correctness of our algorithm follows from that of BFS. The running time is dominated by the time required to construct, update, and query the decremental intersection detection data structure of the undiscovered objects. Initially, each object except the source is undiscovered, and once we delete it from the data structure, we never reinsert it. Thus, the total number of deletions is O(n). There are two cases for a query with a frontier object z. If an undiscovered object t that intersects z is returned, we delete t from the data structure and never reinsert it, so this case happens once for each t ∈ S. If nothing is returned, z does not perform any other queries in that step and, since z is a frontier point only once, this case also happens once ∀ z ∈ S. Thus, the total number of queries is O(n), implying that our algorithm takes O (DI (n, n)) time.
Application to axis-aligned line segments. In intersection graphs of axis-aligned line segments, we need a decremental intersection data structure for horizontal input segments and vertical query segments. Vertical input segments and horizontal query segments can be handled with a symmetrical structure. We can use the data structure of either Giyora and Kaplan [25,Theorem 5.3]  Consequently, the time bound in Theorem 10 can be improved to O n · log n log log n .

Static, offline rectangle intersection detection
We now show how to construct a data structure for the static, oine rectangle intersection detection problem: given a set of n input and query rectangles, nd for each query rectangle one, if any, input rectangle that intersects it. We assumed the existence of such a structure to obtain the APSP algorithm of Theorem 6 for unweighted, undirected graphs of d-dimensional boxes. As depicted in Figure 5, we can easily reduce that problem [20] to the following subproblems: (i) Axis-aligned line segment intersection detection: nding some input horizontal (respectively vertical) segment that intersects a query vertical (respectively horizontal) segment.
(ii) Orthogonal range detection: nding some input point inside a query rectangle.
(iii) Rectangle stabbing detection: nding some input rectangle that contains a query point. In Section 3.1, we showed how to answer n oine queries of type (i) in O (n log log U ) time, assuming that the coordinates of the vertices of the rectangles are integers bounded by U . Also, Babenko et al. [6] have already described how to adapt Chan and P tra³cu's technique [14] to answer n oine queries of type (ii) in O n √ log n time. Babenko et al. actually solved the range successor problem, which is equivalent to nding the lowest point in a 3-sided query rectangle unbounded from aboveit is easy to see that 4-sided Journal of Computational Geometry jocg.org orthogonal range detection reduces to this problem. We now describe how to adapt Chan and P tra³cu's technique to answer n oine queries of type (iii) in O n √ log n time. Chan et al. [13] noted a similar result but only for the case of pairwise disjoint rectangles. Theorem 11. (Rectangle Stabbing Detection) Given n input axis-aligned rectangles and n planar query points with presorted coordinates, we can report for each query point, an input rectangle, if any, that contains it in O n √ log n time. Proof. We use words of w = δ log n bits, where 0 < δ < 1 is a constant. Also, we assume, without loss of generality, that all y-coordinates are pairwise distinct.
Special case: all x-coordinates are small integers bounded by s. We employ a divideand-conquer scheme that resembles a binary interval tree in the x-axis and bit-packing techniques. The input of our algorithm is the list of the x-coordinates of the vertices of the input rectangles and of the query points, presorted by y. Thus, it can be packed with O ((n log s)/w) words. The output is represented as the list of the minimum and maximum x-coordinates of a rectangle, if any, that contains each query point in bottom-to-top order. Hence, it can also be packed with O ((n log s)/w) words.
Let R be the set of input rectangles and Q that of query points. First, we nd the vertical line x = m that divides the x-universe into two halves of length s/2. Let R m be the subset of rectangles that intersect that line. The union of R m is a y-monotone polygon or multiple such polygons, and we can nd it by computing the left/right envelope of the vertical line segments of the input rectangles. Eppstein and Muthukrishnan [22] have shown how to do that in O (|R m |) time, assuming that the coordinates have been pre-sorted in x and y. In our case, the latter has already been done, and to obtain the former we employ counting sort in O (|R m | + s) time. Then, we solve the problem for R m and Q with a bottom-to-top scan, using O ((n log s)/w) additional word operations.
Next, let R (respectively R r ) be the subset of rectangles completely to the left (respectively right) of x = m and Q (respectively Q r ) the subset of query points to the left (respectively right) of y = m. We recursively solve the subproblem for R and Q and the subproblem for R r and Q r . The input to either subproblem can be formed by a linear scan using O ((n log s)/w) word operations, and the output can be merged by another linear scan using O ((n log s)/w) word operations.
Excluding the cost of computing the unions of the R m 's, the total running time is O (n log 2 s)/w + s log s since there are O (log s) levels of recursion. Each rectangle lies in exactly one subset R m over the entire recursion tree, so the total cost of computing the unions of the R m 's is O(n).
One remaining issue is that the output only records the x-coordinates of the reported rectangles. To retrieve the y-coordinates, we rst partition the original set of input rectangles into O s 2 classes with common minimum and maximum x-coordinates. For each query point, we have identied one class which contains an answer. For each class χ, we can gather its input rectangles R χ and query points Q χ , both pre-sorted by y, and answer these queries. This is a 1-dimensional problem in y (nding an input interval containing each query point), which is a special case of the above-mentioned envelope problem and can be Journal of Computational Geometry jocg.org solved in O (|R χ | + |Q χ |) time, thus the total time over all classes χ is linear. We conclude that the special case case can be solved in O n + (n log 2 s)/w time, assuming that n ≥ s 2 .
General case. We again use a divide-and-conquer approach, but this time in a degree-ssegment-tree manner. We use s − 1 vertical lines to divide the plane into s slabs each with O(n/s) rectangle vertices and query points. Each rectangle can be divided into at most three parts, where the left (respectively right) part is contained in one of the s slabs, and the middle part has x-coordinates aligned with the dividing vertical lines. For all middle parts, we can round the x-coordinates of the query points to align with the dividing lines and apply the algorithm for the above special case in O(n + (n log 2 s)/w) time. For the left and right parts, if n ≥ s 2 , we recursively solve the subproblems inside the s slabs. We can combine the answers in linear time.
Each rectangle and each query point participates in O(log s n) recursive calls. The total time is thus O((n + (n log 2 s)/w) · (log n/ log s)), which becomes O(n(log n)/ √ w) by setting log s = √ w and assuming that n ≥ 2 Ω( √ w) . Since w = δ log n, where 0 < δ < 1 is a constant, we can perform each of the above word operations in constant time with table lookup, after an initial precomputation in o(n) time (see Section 2.2). We can also handle the base case, n = s 2 , in linear total time, again with table lookup. Theorem 12. (Static, oine rectangle intersection detection) Given n input and n query axis-aligned rectangles with presorted coordinates, we can report an input rectangle for each query rectangle (if it exists) that intersects it in O n √ log n time.

Conclusion
The obvious open problems are to improve the logarithmic factors in our near-quadratic APSP algorithms, and to obtain a near-quadratic-time APSP algorithm for intersection graphs of arbitrary line segments.
A problem similar to APSP is computing the diameter of a graph, dened as the longest shortest-path distance of any two vertices. It is worth investigating whether we can compute the diameter faster than solving APSP for some of the unweighted geometric intersection graphs considered in this paper.