Efficient Vertex-Label Distance Oracles for Planar Graphs This work was partially supported by Israel Science Foundation grants 794/13 and 592/17, and by the Israeli ministry of absorption. An extended abstract of this work was presented in the 13th Workshop on Approximation and Online Algorithms (WAOA 2015), held in Patras, Greece, 17-18 September 2015.

# Efficient Vertex-Label Distance Oracles for Planar Graphs ††thanks: This work was partially supported by Israel Science Foundation grants 794/13 and 592/17, and by the Israeli ministry of absorption.††thanks: An extended abstract of this work was presented in the 13th Workshop on Approximation and Online Algorithms (WAOA 2015), held in Patras, Greece, 17-18 September 2015.

Shay Mozes    Eyal E. Skop
###### Abstract

We consider distance queries in vertex-labeled planar graphs. For any fixed we show how to preprocess a directed planar graph with vertex labels and arc lengths into a data structure that answers queries of the following form. Given a vertex and a label return a -approximation of the distance from to its closest vertex with label . For a directed planar graph with vertices, such that the ratio of the largest to smallest arc length is bounded by , the preprocessing time is , the data structure size is , and the query time is . We also point out that a vertex label distance oracle for undirected planar graphs suggested in an earlier version of this paper is incorrect.

## 1 Introduction

Imagine you are driving your car and suddenly see you are about to run out of gas. What should you do? Obviously, you should find the closest gas station. This is the vertex-label distance query problem. Various software applications like Waze and Google Maps attempt to provide such a functionality. The idea is to preprocess the locations of service providers, such as gas stations, hospitals, pubs and metro stations in advance, so that when a user, whose location is not known a priori, asks for the distance to the closest service provider, the information can be retrieved as quickly as possible. A dual situation is, for example, when a taxi company wants to dispatch a taxi from the station closest to the location where the taxi is required. Clearly, this problem can be solved using a vertex-label distance oracle by transposing the original graph.

We study this problem from a theoretical point of view. We model the network as a planar graph with labeled vertices (e.g., a vertex labeled as a gas station). We study distance oracles for such graphs. A vertex-label distance oracle is a data structure that represents the input graph and can be queried for the distance between any vertex and the closest vertex with a desired label. We consider approximate distance oracles, which, for any given fixed parameter , return a distance estimate that is at least the true distance queried, and at most times the true distance (this is known as a -stretch). One would like an oracle with the following properties: queries should be answered quickly, the oracle should consume little space, and the construction of the oracle should take as little time as possible. We use the notation   to express the dependency of the space requirement and query time of a distance oracle on , the number of vertices in the graph.

#### Our results and approach

For directed planar graphs we give a ()-stretch   vertex-label distance oracle whose construction time is . Throughout the paper, is the ratio of the largest to smallest arc length. To the best of our knowledge, no non-trivial directed vertex-label distance oracles were proposed prior to the current work.

Consider a vertex-vertex distance oracle for a graph with label set . If the oracle works for general directed graphs then the vertex-label problem can be solved easily; add a distinct apex for each label , and connect every -labeled vertex to with a zero length arc. Finding the distance from a vertex to label is now equivalent to finding the distance between and . The main difficulty in applying this approach to oracle for directed planar graphs is that adding apices breaks planarity. In particular, it affects the separability of the graph. Thus, the reduction does not work with oracles that depend on planarity or on the existence of separators.

Our contribution is in realizing and showing that the internal workings of vertex-vertex distances oracles for planar graphs due to Thorup [23] can be extended to support vertex labels. Achieving this modification is non-trivial since introducing the apices needs to be done in a manner that guarantees correctness without compromising efficiency. Thorup’s oracles rely on the existence of fundamental cycle separators in planar graphs, a property that breaks when apices are added to the graph. We observe, however, that once the graph is separated, Thorup’s oracle does not depend on planarity. We therefore postpone the addition of the apices till a later stage in the construction of the distance oracle, when the graph has already been separated. We show that, nonetheless, approximate distances from any vertex to any label in the entire graph can be efficiently approximated.

An earlier version of this paper claimed a simplified and more efficient vertex label distance oracle for undirected planar graphs. This claim turns out to be incorrect, as we briefly explain in Section 7.

## 2 Related Work

We summarize related work on approximate distance oracles. For general graphs, no ()-stretch approximate vertex-vertex distance oracles with nearly-linear space consumption are likely to exist [20]. For any integer , Thorup and Zwick [24] presented a ()-stretch   distance oracle for undirected graphs whose construction time is . Wulff-Nilsen [26] achieved the same result with preprocessing of for a universal constant . Several more improvements of [24] have been obtained for unweighted or sparse graphs ([2], [3], [4]). The current state of the art is due to Chechik [6]. She presented a ()-stretch   distance oracle construction algorithm for undirected graphs with construction time.

In contrast, vertex-vertex oracles for planar graphs with stretch less then have been constructed. Thorup [23] gave a   ()-stretch distance oracle for directed planar graphs, and a ()-stretch   (simplified) distance oracle for undirected planar graphs.

Our result is based on Thorup’s directed oracle, which is described in section 4. Klein [14] independently gave a distance oracle for undirected planar graphs with the same bounds. Kawarabayashi, Klein and Sommer [12] have shown a   undirected ()-stretch distance oracle constructed in time, inspired by [23]. They give a trade-off of   oracle algorithms. Sommer et al. [13] have shown better tradeoffs for oracles for undirected planar graphs. For the case where , they achieve ()-stretch   oracle, where hides and factors.

The vertex-label distance query problem was introduced by Hermelin, Levy, Weimann and Yuster [11]. For any integer , they gave a ()-stretch   vertex-label distance oracle (expected space) for undirected general (i.e., non-planar) graphs. This is not efficient when the number of distinct labels is (since the trivial solution of storing all pairwise vertex-label distances is better in that case). They also presented a ()-stretch   oracle for undirected graphs. Chechik [5] improved the latter result. In the same paper she also presented a ()-stretch   (expected space) oracle for undirected graph.

For undirected planar graphs, Li, Ma and Ning [16], building on [14], constructed a ()-stretch vertex-labeled oracle with   bounds. Here, is the (hop) diameter of the graph, which can be . It is also shown in [16] how to avoid the factor when . The construction time of their oracle is .

Łącki, Oćwieja, Pilipczuk, Sankowski, and Zych [18] developed dynamic vertex-labeled distance oracles for undirected general and planar graphs, and used them to maintain approximate solutions for dynamic Steiner and subgraph TSP problems. They describe a generic scheme for converting certain distance oracles for undirected planar graphs into dynamic vertex-label distance oracle. Applying their scheme to one of the slower variants of Thorup’s distance oracles, they obtained a   ()-stretch undirected vertex-labeled distance oracle that also supports merging labels.

Another related work is by Abraham, Chechik, Krauthgamer and Wieder [1], who considered approximate nearest neighbor search in planar graph metrics. This is the special case of vertex-labeled distance oracle with only one label. For this easier problem they obtained a data structure whose size is nearly linear in the number of labeled vertices. However, they assume an exact vertex-vertex distance oracle is provided.

To the best of our knowledge, no non-trivial directed vertex-label distance oracles were proposed prior to the current work.

## 3 Preliminaries

In this paper we only deal with connected graphs. This is without loss of generality since each weakly connected component can be handled separately. For a graph , we denote by and the set of vertices and arcs of , respectively. Throughout the paper, all graphs are directed unless stated otherwise. We write to denote an arc from vertex to vertex . We use the term edges when dealing with undirected graphs, or when we wish to ignore the orientation of arcs in directed graphs.

Let be a function assigning lengths to the arcs. We assume that the lengths are normalized so that the smallest arc length is 1. The length of a path is the sum of lengths of its arcs. For , the distance between and in , denoted , is the length of a shortest -to- path in . We denote by the maximum length of an arc in . Thus . We assume there are no parallel arcs since it suffices to keep just the arc with minimum length within each set of parallel arcs.

A path or a cycle is simple if each vertex is the endpoint of at most two arcs of . The concatenation of two paths and , where the last vertex of is the first vertex of , is denoted . Two paths and intersect if . For a simple path and a vertex set with , we define , the reduction of to as a path whose vertices are . Consider the vertices of in the order in which they are visited by . For every two consecutive vertices of in this order, there is an arc in whose length is the length of the -to- subpath of .

Let be a set of labels. A vertex-labeled graph is a graph equipped with a function . We define to be the set of vertices with label . For a vertex-labeled and , we define to be the distance in from to the closest -labeled vertex.

A vertex-label distance oracle is a data structure that, for a specific vertex-labeled graph , given a vertex and a label , outputs (an approximation of) . We note that this problem is a generalization of the basic distance oracle problem in which each vertex is given a unique label. Constructing an -space vertex-label distance oracle is trivial, by precomputing and storing the distance between each vertex and each possible label. The goal is, therefore, to devise an oracle which requires space, while allowing fast queries.

We assume the reader is familiar with basic definitions and properties of planar graphs, such as the definitions of planar embeddings, and planar duality. Let be a planar embedded graph. Each vertex of is embedded to a point in the plane, and each arc is embedded as a curve in the plane between the images of its endpoints, such that the images of distinct arcs are internally disjoint. The faces of are the maximally connected regions of the plane after removing the image of the vertices and arcs of . Each face is identified with the set of arcs and vertices on its boundary. We denote by the planar dual of . The vertices of are the faces of , and the arcs of are in one-to-one correspondence with the arcs of . We can therefore refer to the same arc in both the primal and the dual . For a graph , we define the size of the graph as . An immediate consequence of Euler’s formula is that in a planar graph where each face of is of size at least 3 (i.e. there are no parallel edges and no self loops), . The number of faces is also . Therefore, for planar graph , .

An undirected cycle in a directed graph is a set of arcs in that, when regarded as undirected edges, form a cycle. Let be a directed planar embedded graph, and let be the infinite face of . Let be a simple undirected cycle in . The cycle partitions the plane into two regions. A face is enclosed by if it belongs to the part of the partition that does not contain the infinite face. A vertex is enclosed by if it is incident to a face enclosed by . It is strictly enclosed if, in addition, is not a vertex of . An arc is strictly enclosed by if both faces incident to are enclosed by . An arc is enclosed by if or if is strictly enclosed by . The interior of is the subgraph induced on by the edges enclosed by . The exterior of is the subgraph induced on by the edges not strictly enclosed by . Note that belongs to both the interior and exterior of . The strict interior and strict exterior of are, respectively, the interior and exterior of without the vertices and edges of .

The following is a specialized statement of the Jordan curve theorem for planar embedded graphs.

###### Proposition 1

Let be a planar graph. Let be an undirected simple cycle in . Any path in between a vertex in the interior of and a vertex in the exterior of contains a vertex of .

Let be a rooted spanning tree of an undirected graph . For , let denote the unique root-to- path in . We call a branch of . Let be two vertices such that . The fundamental cycle of (with respect to ) is the undirected cycle composed of , and . Note that a fundamental cycle might not be simple since and might have a common prefix. In general, a fundamental cycle can be decomposed into a simple prefix path and a simple cycle. We extend the notions of enclosure defined above for simple cycles to fundamental cycles. A face is enclosed by if is enclosed by the simple cycle portion of . The remaining definitions are as in the simple cycle case.

###### Proposition 2 ([22])

For any spanning tree of , the set of edges of not in form a spanning tree of .

For a spanning tree of , we use to denote the spanning tree of consisting of the edges not in .

An undirected fundamental cycle is a fundamental cycle separator if each of the interior and exterior of , consists of at most of the faces of .111The definitions in the literature differ in the choice of constant ( in our case) as well as in the quantity according to which the balance of the separation is defined (number of faces in our case). Lipton and Tarjan [17] show that, if is triangulated (every face is adjacent to at most 3 vertices) then for any spanning tree of , there is an edge not in whose fundamental cycle with respect to is a fundamental cycle separator. Goodrich [7] observed that such an edge can be found by looking for an edge-separator in the dual tree . Thorup [23] used a different construction that separates a graph into three balanced subgraphs. Our discussion of fundamental cycle separators differs from Thorup’s, and follows that of [15]. This leads to a simpler structure of the oracle, as we discuss in Section 4.

Let be a planar graph. For the discussion of separators we ignore the directions of arcs in and treat it as an undirected graph (the direction of arcs does not affect separation properties of the graph). The following basic and simple lemma was proved in [15].

###### Lemma 1

[15, Lemma 1] Let be a planar graph with face weights such that no face has weight more than the total weight. Let be a spanning tree of . Let be the spanning tree of the planar dual of consisting of the edges not in . Assume that has maximum degree 3. One can find in time an edge of such that the total face weight enclosed by the fundamental cycle of with respect to is at least the total weight and at most the total weight.

Let be a triangulated planar graph with spanning tree . Let be the spanning tree of consisting of the edges not in . Since is triangulated, the maximum degree of is 3. Let be the edge in Lemma 1, and let be its fundamental cycle with respect to . Separating with yields two subgraphs, the interior , and exterior of . These subgraphs inherit the embedding from . Thus, the cycle is the infinite face of , and the simple cycle portion of is a face of . See Figure 1 for an illustration.

One can obtain from subtrees that span and . The subgraph of enclosed by is a spanning tree of , and the subgraph of not strictly enclosed by is a spanning tree of . Similarly, Consider the two subtrees, and , obtained from by deleting the edge , and then adding back to both subtrees. The subtree that contains the dual vertex corresponding to the infinite face of is a spanning tree of . The other subtree, , is a spanning tree of .

We note that even though is triangulated, and are not. For example, the face of whose boundary is might not be a triangle. However, since the spanning trees and of are subtrees of , their maximum degree is 3. Hence, one can continue to apply Lemma 1 recursively even though and are not triangulated. We will describe such a decomposition in Section 4.

## 4 Thorup’s Approximate Distance Oracle [23]

In this section we outline the distance oracle of Thorup [23]. This material is not new, but is necessary for understanding our results. Our description is somewhat different from that of Thorup. It does not go into all the details of Thorup’s oracle. Rather, we focus on the aspects that our algorithm does not use as black boxes.

Thorup shows that the problem of constructing a distance oracle for a directed graph can be reduced to constructing a distance oracle for a restricted kind of graphs, defined in the following.

###### Definition 1

A set of arcs in a directed graph is an -layered spanning tree if it satisfies the following properties:

• Regarding the arcs of as edges, forms a rooted spanning tree of .

• Each branch of can be decomposed into no more than directed shortest paths in , each of length at most . These paths may be of opposing directions. I.e., they need not all be directed away from the root of .

A graph is called -layered if it has an -layered spanning tree. Thorup shows that any graph can be decomposed into -layered graphs of total linear size for any . The decomposition is such that any shortest path of length at most in G is represented in at least one of a constant number of -layered graphs in the decomposition (See subsection 5.1 for more details). Thus, a natural scaling technique can be used to answer distance queries in by answering distance queries in a few -layered graphs. The concept of -layered is important because fundamental cycles of an -layered spanning tree can be decomposed into a constant number of directed shortest paths. This property is crucial in the design of Thorup’s oracle.

###### Definition 2

A scale- distance oracle for a graph is a data structure that, when queried for , returns

 d(v,w)∈{[δH(v,w),δH(v,w)+ϵ′α]if δH(v,w)≤αotherwise

Thorup shows how to construct a distance oracle for any graph using scale- distance oracles for minors of at several scales. This is summarized in the following lemma (See subsection 5.1 for more details).

###### Lemma 2

([23, Sections 3.1,3.2,3.3]) Let be a graph. Suppose that, for any and any -layered minor of , one can construct, in time, a scale- distance oracle with space bound and query time (here, and are arbitrary functions that only depend on and , not on ). Then, one can construct, for any , a ()-stretch   distance oracle for in time.

Planar graphs are closed under taking minors. Thus, by Lemma 2, to show a distance oracle for planar graphs, one only needs to show how to construct scale- distance oracles for -layered planar graphs. We next describe Thorup’s construction of such oracles. In Section 4.1 we explain the recursive structure. In Section 4.2 we describe a non-efficient construction, and in Section 4.3 we describe how to make the construction efficient. We note again that all of these constructions are essentially due to Thorup.

### 4.1 The recursive decomposition

Let be a directed -layered planar graph with an -layered spanning tree . Thus, each branch in can be decomposed into at most 3 directed shortest paths. We assume that is triangulated. This is without loss of generality since one can triangulate with infinite length bidirected arcs. Clearly, this does not affect the shortest paths or the distances in . For the description of the recursive decomposition we ignore the directions of arcs of and treat it as an undirected graph. We stress that this is done only to define the decomposition. When describing the oracle we will, of course, take the directions of arcs into consideration.

The set of edges not in forms a spanning tree of , and, since is triangulated, the maximum degree of is at most 3. We decompose recursively using the fundamental cycle separator in Lemma 1 until each subgraph contains a constant number of faces of . The decomposition can be represented by a binary tree in the following manner. We refer to the vertices of as nodes to distinguish them from the vertices of . See Figure 2 for an illustration.

• Each node of is associated with a subgraph of . The subgraph associated with the root of is itself. The spanning tree of is and the spanning tree of is

• Each non-leaf node of is associated with the fundamental cycle separator found by invoking Lemma 1 on . The weight assignment to the faces of used in the invocation of Lemma 1 assigns weight to each face of that is also a face of the original graph (we call these faces original faces), and weight to all other faces of (these faces are called holes).

• Each non-leaf node has two children . The subgraph associated with the node is the exterior of in . The subgraph associated with the node is the interior of in .

In both and we replace each of the two branches comprising by their reduction to their vertices incident to at least one original face.

As explained in the text following Lemma 1, the spanning trees of and are subtrees of (with the branches of reduced as described above), and the spanning trees of and are subtrees of .

Since the number of original faces decreases by a constant factor at each level, the depth of is . We will bound the space required to store the decomposition tree , and all the subgraphs generated by the decomposition by . This is where reducing the branches of is crucial, because the sizes of the separators do not decrease along the recursion. We explain this issue in detail. Recall that the subgraphs created during the recursive decomposition have two type of faces; faces that are also original faces of , which we call original faces, and faces that are not faces on , which are called holes. The original faces are all triangles, and their number decreases by a constant factor at each recursive step. The holes are faces that may consist of more than 3 vertices, and their number increases by at most one at each recursive step. The problem with bounding the size of the subgraphs arises from vertices that are adjacent only to holes, because the number of such vertices does not necessarily decrease along the recursion. Note that such vertices are always vertices of the separator of some ancestor of in (possibly itself). For this reason we replace the branches of with their reductions to vertices incident to at least one original face. This has the effect of replacing every (possibly long) maximal path of edges that are only incident to holes with a single reduced edge (that is assigned the length of the path). This change reduces the size of the subgraph without changing the distances in the subgraph. After reducing these paths each vertex in the subgraph is incident to at least one original face. Therefore, the number of vertices in a subgraph is at most 3 times the number of original faces in the subgraph. Namely, for any , is within a constant multiplicative factor from the number of original faces in . Since each original face belongs to exactly one at each level of , the total size of all subgraphs in a single level of the recursion is . Thus the total size is .

### 4.2 A scale-(α,ϵ) distance oracle

The main idea in obtaining an approximate distance oracle is to store just a subset of the pairwise distances in the graph, from which all approximate distances can be computed efficiently. Fix some .

###### Definition 3 (ϵ-covering connections set)

Let be a graph. Let be a shortest path in of length at most . Let be a vertex of . A set is called an -covering connections set from to with connection lengths       if, for every , if , then there exists some s.t. .

Intuitively one should think of a connection length as the true distance . However, as we explain later on, to achieve efficient construction, is sometimes an approximation of . An -covering connections set from to with connections lengths       is defined symmetrically. If , then there exists some s.t. . We use the term -covering connections set (or just connections set) to refer to both the -to- (or -to-) connections as well as their corresponding connection lengths.

Thorup showed that, given any graph , shortest path in of length at most , and for every vertex there exists an -covering connections set of size . The utility of -covering connections sets is summarized in the following lemma ([23, Lemma 3.5]):

###### Lemma 3

Let be a shortest path of length at most in graph . Let be a shortest -to- path in of length at most which intersects . For any , let and be -covering connections sets from to and from to , respectively. Let be a graph with vertices , the vertices and arcs of the reduction of to the connections of and of , and with -to- and -to- arcs whose lengths are the corresponding connection lengths of and . Then

 δHuwQ(u,w)≤δH(u,w)+2ϵα (1)

A Lowest Common Ancestor (LCA) data structure for a tree is a data structure that, given any two nodes of , returns the node furthest from the root that is an ancestor of both and . Harel and Tarjan [9] (and many other subsequent simpler and practical results) show how to construct, in linear time, an LCA data structure of linear size and constant query time.

Let be vertices of . Let be leaves of such that and . Let be the LCA of and in . We denote by the set of six directed shortest paths in the decomposition of (recall that each branch in an -layered tree can be decomposed into at most 3 directed paths, and that is composed of two such branches). If , and are separated by , and so, by Proposition 1, every -to- path in must intersect some path of . Therefore, by Lemma 3, to be able to approximate , it suffices to keep, for every , connections and , where the connection lengths reflect distances in (not in ). To stress that the connection lengths are in , we call such connections global connections. If , then is a leaf of , so the size of is constant. All such distances (in G) between pairs of vertices in are stored explicitly by the oracle.

The distance oracle keeps the following items for every internal node and for every vertex :

1. global connections for all .

2. global connections for all .

These connections, over all and all paths in are called the connections of . In addition, the data structure stores:

1. A mapping of each vertex to some leaf node s.t. .

2. A lowest common ancestor data structure over .

3. -additive approximation of for all such that .

We next describe how a query is performed. Given a -to- distance query, let be the lowest common ancestor of and in . If , the query algorithm returns their length approximation (item 5 above) in time. Otherwise, the query algorithm computes, for each path the length of a shortest -to- path that intersects using the -covering sets and . By the construction of , the number of such paths is constant. If , one can compute the distance estimate within additive error (see Lemma 3) for each in time (see also [23, Lemma 3.6]). Thus, if , an additive distance approximation is produced in time.

We now bound the total space required for the oracle. Since the height of is , and since each original face belongs to exactly one subgraph at each level of , each original face belongs to for nodes of . For each of the shortest paths in of each such node , and each original face (of ) in , each of the 3 vertices of has a set of connections. This gives a total of connections in items 1,2. Items 3,4 require space. Since there are leaves, each with a subgraph of constant size, storing the additional length approximations in item 5 also requires space. Hence the total space required by the oracle is .

The simplifications in our presentation of Thorup’s oracle compared to the original description in [23] stem from the fact that all fundamental cycle separators used throughout our recursive decomposition are obtained via subtrees of a single spanning tree of . Since is assumed to be triangulated, and all its subtrees have maximum degree 3, so there is no need to retriangulate the subgraphs along the recursive decomposition. This leads to a significant simplification because it implies that all cycle separators used in our constructions consist of original arcs of . Therefore, by Proposition 1, it suffices to check connections only on the separator of the LCA of and in order to approximate the distance from to . In Thorup’s construction a cycle separator computed for some may consist of artificial edges introduced to triangulate . In this situation, even though separates from in , there may exist in -to- paths that do not intersect . Therefore, in order to approximate the distance from to one needs to check connections on all the separators of all the ancestors of the LCA of and . Thorup deals with this by defining the concept of the frame of . The use of frames leads to additional complications since one needs to make sure that the number of paths in each frame is constant. Our construction avoids the need for frames and its associated complications.

### 4.3 Efficient construction

We now mention some, but not all the details of Thorup’s -time construction algorithm. The computation of the connections and connection lengths is done top-down the decomposition tree . Thorup [23, Lemma 3.11, 3.12] describes a divide-and-conquer procedure that constructs the connections for all vertices in a graph , and a single shortest path . A symmetric procedure computes . We summarize the procedure in the following lemma.

Let be a graph. Let be a shortest path in . Let be a function s.t. for any subgraph of , and any vertex , where is the reduction of to , we can compute single source shortest paths from in the graph in time. It is easy to see that a standard implementation of Dijkstra’s algorithm with priority queue implies . If is planar, then by the algorithm of Henzinger et al. [10].

###### Lemma 4

[23, Lemmas 3.11,3.12] Let be a shortest path of length at most in a directed graph . Connections and for all vertices , where the connection lengths correspond to distances in , can be computed in total time.

Using Lemma 4 on (planar) for all internal and all takes total time (by a similar analysis to the one used to bound the space, see also Lemma 6), but does not generate global connections. Because the lemma is applied only to , the connection lengths are with respect to , not to . We call such connections local connections (of ). For the sake of later computations of global connections, the algorithm first computes local connections for all internal and all .

We next describe how to efficiently compute global connections. We discuss the connections of the form . Computing is similar. Recall that global connection lengths reflect distances in the entire graph, not just in . Applying Lemma 4 on for every would take quadratic time, which is too much. Instead, the computation is done top-down , augmenting with the local connection lengths of ancestors of in , which have already been computed, and represent distances outside . This is done as follows.

###### Lemma 5

Let and . Global connections for can be computed in time using just and local connections of all ancestors of .

###### Proof 1

Let be a path in . Let be the graph composed of:

• The vertices of .

• The arcs of .

• For each ancestor of (including itself), for each path , let be the vertices of that have (local) connections to or (local) connections from :

• The vertices and arcs of , the reduction of to vertices of .

• Arcs representing the (local) connection lengths of for connections from to ) and from to .

Since each vertex of has connections to each path in the separator of each of ’s ancestors, the size of is .

The algorithm applies Lemma 4 on to generate -covering connection sets from in . We prove below that for any path , and any and , . (The fact that is obvious.) Hence, the connections computed in are in fact global connections in , i.e., global connections.

Let , and . Consider a shortest -to- path . Let be the rootmost ancestor of such that intersects . I.e., is confined to . If then is confined to , and because there are arcs representing local connections lengths for , . Otherwise, is a strict ancestor of . Let be a path of intersected by . Consider the local connection lengths from to in and the local connection lengths from to . These connection lengths were calculated with respect to exact distances in . Since , and are all present in , it follows from Lemma 3 that . Since is confined to , , and so , as claimed.

To analyze the running time, first note that can be easily constructed in time by storing, when constructing the oracle, for each vertex of its connections on each of the separators in each of the subgraphs it belongs to. The lengths of the arcs of can be obtained within the same time bound since they are either stored as connection lengths, or correspond to distances between vertices on a shortest path comprising part of a separator. In the latter case a distance can be retrieved in constant time by storing, when constructing the oracle, for each vertex on a shortest path of a separator, its distance from the beginning of the path.

We next show that . That is, we show how to compute a shortest path tree in rooted at any vertex of in time. We first go through the vertices of in order. For each vertex we relax all the arcs . Let be the set of all reduced paths of separators of strict ancestors of . For each path (in any order), we go through the vertices of in order. For each vertex we relax all the arcs . The computation is correct by the construction of ; for any and any , every -to- path starts with a subpath of , followed by a subpath of at most one path , and then reaching . Hence, the relaxation order is correct.

has arcs and vertices because all ancestral separator paths are in reduced form. Hence, applying Lemma 4 to for each path of requires time. Since there are a constant number of shortest paths in , this is also the total runtime.

###### Lemma 6

Given an -layered graph (along with an -layered spanning tree), constructing a scale- distance oracle takes time.

###### Proof 2

Since a fundamental cycle separator can be found in linear time, constructing the decomposition tree takes time. Local connections are computed, for each and each path of , by applying Lemma 4 to using Dijkstra’s algorithm.222Since is planar, one may use [10] instead to achieve complexity. However this is not the bottleneck. This takes time. Global connections are computed by applying Lemma 5 to , which takes time by Lemma 5.

Hence, computing all connections for a single takes . Summing over all in the same depth results in time. Summing over all depths gives a total preprocessing time of .

Finally, computing length approximations for all pair of vertices where (item 5 in the description of the oracle) can also be done within the same time bound using a degenerate application of Lemma 5. For each leaf node and for each , let be the subgraph of consisting of just and . Define to be the singleton vertex , and consider to be the a trivial local connection from to with local connection length . Considering as a child of and applying Lemma 5 to yields a global connection from to in time. That is, the length of this connection is an approximation of . As there are such pairs over all leaves of , the total preprocessing time remains .

By Lemma 2 and Lemma 6, we obtain the following theorem:

###### Theorem 1

One can construct a ()-stretch   distance oracle in time.

## 5 Scale-(α,ϵ) Vertex-Label Distance Oracle

In this section we show how to adapt Thorup’s oracle (section 4) to the vertex-label case. Most of our description details how a scale- vertex-label distance oracle can be constructed efficiently. At the end of the section we explain why Thorup’s argument showing that scale- distance oracles can be used to construct a general distance oracle (Lemma 2) applies in the vertex-label case as well.

Thorup’s oracle supports one-to-one (vertex-vertex) distance queries, whereas here we need one-to-many distance queries. Given two vertices , Thorup’s oracle finds the LCA of and in , and uses its connections to produce the desired distance approximation. In a one-to-many query, we are given the query vertex , but there is no analogue for . We do not know which -labeled vertex in is closest to . The minimal distance approximation from to a -labeled vertex in can be computed in , using the vertex-vertex distance oracle data structure, as . Therefore, we assume, without loss of generality, that a shortest -to- path intersects some path of . More precisely, we assume that a shortest -to- path intersects the separator of the leafmost (i.e., furthest from the root) strict ancestor of in such that contains some -labeled vertex. The node takes the role of the LCA of and in the vertex-vertex query algorithm. In order to be able to use ’s connections in a distance query, one must make sure that ’s connections represent approximate distances to -labeled vertices in the entire graph, not just in .

We define a set of new (artificial) vertices, one per label. For every , let be the restriction of to labels present in . Let