A Simple Algorithm for Multiple-Source Shortest Paths in Planar Digraphs

by   Debarati Das, et al.
Københavns Uni
ETH Zurich

Given an n-vertex planar embedded digraph G with non-negative edge weights and a face f of G, Klein presented a data structure with O(nlog n) space and preprocessing time which can answer any query (u,v) for the shortest path distance in G from u to v or from v to u in O(log n) time, provided u is on f. This data structure is a key tool in a number of state-of-the-art algorithms and data structures for planar graphs. Klein's data structure relies on dynamic trees and the persistence technique as well as a highly non-trivial interaction between primal shortest path trees and their duals. The construction of our data structure follows a completely different and in our opinion very simple divide-and-conquer approach that solely relies on Single-Source Shortest Path computations and contractions in the primal graph. Our space and preprocessing time bound is O(nlog |f|) and query time is O(log |f|) which is an improvement over Klein's data structure when f has small size.



There are no comments yet.


page 1

page 2

page 3

page 4


A Divide-and-Conquer Algorithm for Two-Point L_1 Shortest Path Queries in Polygonal Domains

Let P be a polygonal domain of h holes and n vertices. We study the prob...

Near-Optimal Distance Oracles for Vertex-Labeled Planar Graphs

Given an undirected n-vertex planar graph G=(V,E,ω) with non-negative ed...

Improved Distance Sensitivity Oracles with Subcubic Preprocessing Time

We consider the problem of building Distance Sensitivity Oracles (DSOs)....

Optimal Approximate Distance Oracle for Planar Graphs

A (1+ϵ)-approximate distance oracle of an edge-weighted graph is a data ...

Succinct Permutation Graphs

We present a succinct, i.e., asymptotically space-optimal, data structur...

Enumeration of Far-Apart Pairs by Decreasing Distance for Faster Hyperbolicity Computation

Hyperbolicity is a graph parameter which indicates how much the shortest...

Interval Query Problem on Cube-free Median Graphs

In this paper, we introduce the interval query problem on cube-free medi...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

In the Planar Multiple-Source Shortest Paths (MSSP) problem, an embedded digraph is given along with a distinguished face , and the goal is to compute a data structure answering distance queries between any vertex pair where either or belong to . Data structures for this problem are measured by the preprocessing time required to construct the data structure, the space required to store the data structure, and the query time required to answer a query.


MSSP data structures are a crucial building block for the All-Pairs Shortest Paths (APSP) problem in planar graphs where the data structure needs to be able to return the (approximate or exact) distance between any two vertices in the graph. Such data structures are often called distance oracles if the query time is subpolynomial in . Broadly, there are three different APSP data structure problems that currently rely on MSSP algorithms:

  • Exact Distance Oracles: In a recent series of breakthroughs, [cohen2017fast, GMWW18, charalampopoulos2019almost, LP20] showed that it is possible to obtain an APSP data structure that requires only space and query time where both [charalampopoulos2019almost] and the state-of-the-art result in [LP20] employs MSSP as a building block in their construction.

  • Approximate Distance Oracles: Thorup [thorup2004compact] presented a data structure that returns

    -approximate distance estimates using preprocessing time and space

    111We use -notation to suppress logarithmic factors in . To state the bounds in a clean fashion, we assume that the ratio of smallest to largest edge weight in the graph is polynomially bounded in . and query time . Since, his construction time was sped-up by polylogarithmic factors via improvements to the state-of-the-art MSSP data structure [Klein05].

  • Exact (Dynamic) APSP: A classic algorithm by Fakcharoenphol and Rao [fakcharoenphol2006planar] gives a data structure that uses space and preprocessing time, and takes query time to answer queries exactly. A variant of this algorithm further gives a data structure that processes edge weight changes to the graph in time while still allowing for query time . Again, while [fakcharoenphol2006planar] did not directly employ an MSSP data structure, Klein [Klein05] showed that incorporating MSSP leads to a speed-up in the logarithmic factors.

We point out that various improvements were made during the last years over these seminal results when considering different trade-offs [fredslund2020truly, long2021planar] or by improving logarithmic or doubly-logarithmic factors [mozes2010shortest, gawrychowski2018improved, mozes2018faster], however, the fundamental sub-problem of MSSP is present in almost all of these articles. We emphasize that beyond the run-time improvements achieved by MSSP data structure, an additional benefit is a more modular and re-usable design that makes it simpler to understand and implement APSP algorithms.

Another key application of MSSP is the computation of a dense distance graph. An often employed strategy for a planar graph problem is to decompose the embedded planar input graph into smaller graphs using vertex separators in order to either obtain a recursive decomposition or a flat so called -division of . For each subgraph obtained, let denote its set of boundary vertices (vertices incident to edges not in ). The dense distance graph of is the complete graph on where each edge is assigned a weight equal to the shortest path distance from to in . Since the recursive or flat decomposition can be done in such a way that is on a constant number of faces of , MSSP can then be applied to each such face to efficiently obtain the dense distance graph of . There are numerous applications of dense distance graphs, not only for shortest path problems but also for problems related to cuts and flows [BorradaileKMNW17, Borradaile15GomoryHu, ItalianoFlow11].

Previous Work.

The MSSP problem was first considered implicitly by Fakcharoenphol and Rao [fakcharoenphol2006planar] who gave a data structure that requires preprocessing time and space and query time . Since, the problem has been systematically studied by Klein [Klein05] who obtained a data structure with preprocessing time and space and query time . Klein’s seminal result was later proven to be tight in for preprocessing time and space [eisenstat2013linear]. Klein and Eisenstat [eisenstat2013linear] also demonstrated that one can remove all logarithmic factors in the special case of undirected, unit-weighted graphs222[eisenstat2013linear] also shows how to use this data structure to obtain a linear-time algorithm for the Max Flow problem in planar, unit-weighted digraphs. Finally, Cabello, Chambers and Erickson [cabello2013multiple] gave an algorithm exploiting the same structural claims as in [Klein05] but give a new perspective by recasting the problem as a parametric shortest paths problem. This allowed them to generalize the result in [Klein05] to surface-embedded graphs of genus , with preprocessing time/space and query time .

The Seminal Result by Klein [Klein05].

On a high-level, the result by Klein [Klein05] is obtained by the observation that moving along a face with vertices , from vertex to , the difference between the shortest path trees and consists on average of edges. [Klein05] therefore suggests to dynamically maintain a tree , initially equal to the shortest path tree of , and then to make the necessary changes to to obtain the shortest path tree of , and so on for . Overall, this requires only changes to the tree over the entire course of the algorithm while passing through all shortest path trees.

To implement changes to efficiently, Klein uses a dynamic tree data structure to represent , and uses duality of planar graphs in the concrete form of an interdigitizing tree/ tree co-tree decomposition, with the dual tree also maintained dynamically as a top tree. Finally, he uses an advanced persistence technique [driscoll1989making] to allow access to the shortest path trees for any efficiently.

Even though formalizing each of these components requires great care, the algorithm by Klein is commonly taught in courses and books on algorithms for planar graphs (see for example [klein2014optimization, demaineCoursePlanarity, topologyErickson]), but with dynamic trees and persistence abstracted to black box components.

Our Contribution.

We give a new approach for the MSSP problem that we believe to be significantly simpler and that matches (and even slightly improves) the time and space bounds of [Klein05]. Our algorithm only uses the primal graph, and consist of an elegant interweaving of Single-Source Shortest Paths (SSSP) computations and contractions in the primal graph.

Our contribution achieved via two variations of our MSSP algorithm comprises of:

  • A Simple, Efficient Data Structure: We give a MSSP data structure with preprocessing time/space and query time which slightly improves the state-of-the-art result by Klein [Klein05] for subpolynomial and otherwise recovers his bounds.

    Our result is achieved by implementing SSSP computations via the linear-time algorithm for planar digraphs by Henzinger et al. [HenzingerKRS97]. Abstracting the algorithm [HenzingerKRS97] in black-box fashion, our data structure is significantly simpler than [Klein05] and we believe that it can be taught at an advanced undergraduate level.

    Further, by replacing the black-box from [HenzingerKRS97] with a standard implementation of Dijkstra’s algorithm, our algorithm can easily be taught without any black-box abstractions, at the expense of only an -factor to the preprocessing time.

  • A More Practical Algorithm: We also believe that our algorithm using Dijkstra’s algorithm for SSSP computations is easier to implement and performs significantly better in practice than the algorithm by Klein [Klein05]. We expect this to be the case since dynamic trees and persistence techniques are complicated to implement and incur large constant factors, even in their heavily optimized versions (see [tarjan2010dynamic]). In contrast, it is well-established that Dijkstra’s algorithm performs extremely well on real-world graphs, and contractions can be implemented straight-forwardly.

    In fact, one of the currently most successful experimental approaches to compute shortest-paths in road networks is already based on a framework of clever contraction hierarchies and fast SSSP computations (see for example [geisberger2008contraction]), and it is perceivable that our algorithm can be implemented rather easily by adapting the components of this framework.

We point out that our result can be shown to be tight in and by straight-forwardly extending the lower bound in [eisenstat2013linear]. We can report paths in the number of edges plus time.

2 Preliminaries

Given a graph , we use to refer to the vertices of , and to refer to its edges. We denote by or the weight of edge in , by the shortest distance from to in and by a shortest path from to . By SSSP tree from a vertex , we refer to the shortest path tree from in obtained by taking the union of all shortest paths starting in (where we assume shortest paths satisfy the subpath property). We use to denote a tree rooted at a vertex . For a vertex of , we let denote the parent of in .

Induced Graph/Contractions.

For a vertex set , we let denote the subgraph of induced by . We sometimes abuse notation slightly and identify an edge set with the graph having edges and the vertex set consisting of endpoints of edges from . For any edge set , we let denote the graph obtained from by contracting edges in where we remove self-loops and retain only the cheapest edge between each vertex pair (breaking ties arbitrarily). If only contains a single edge , we slightly abuse notation and write instead of . When we contract components of vertices into a super-vertex, we will identify the component with some vertex . We use the convention that when we refer to some vertex from the original graph in the context of the contracted graph, then refers to the identified vertex .

Simplifying assumptions.

We let refer to the input graph and assume that is a planar embedded graph where the embedding is given by a standard rotation system, meaning that neighbors of a vertex are ordered clockwise around it. We assume that has unique shortest paths, that is the infinite face , and that this face is a simple cycle with edges of infinite weight. We let denote the vertex set of and let be the vertices of in clockwise order, starting from some arbitrary vertex .

We assume that no shortest path has an ingoing edge to a vertex of ; in particular, infinite-weight edges are not allowed to be used in shortest paths. In addition, we assume that every vertex can reach every vertex of in ; in words, there is a path from to that only intersects in .

With simple transformations, it is easy to show that all assumptions can be ensured with only additional preprocessing time; see Appendix A for details.

3 High-Level Overview

To make it easier to understand the formal construction and analysis of our new data structure, we start by giving a high-level overview.


We first focus on the preprocessing step which constructs the data structure using a divide-and-conquer algorithm. A formal description can be found as pseudo-code in Algorithm LABEL:alg:MSSP_Preproc but here we only give a sketch.

The general subproblem is to compute shortest path trees from roots forming an interval of vertices along (the initial interval contains every vertex of ). Shortest path trees are computed from the two endpoints of as well as from the middle vertex of . These three roots split into two equal-sized sub-intervals on which the algorithm recurses. Since a shortest path tree can be computed in linear time in a planar graph, the naive implementation would thus give an running time.

To obtain an efficient construction, we rely on the following well-known result about shortest path trees from the roots on : for any edge of , the roots of shortest path trees containing are consecutive on . We will use the following immediate corollary: for any tree which is a subgraph of , the roots of shortest path trees containing are consecutive on .

To exploit this result in the divide-and-conquer algorithm, let be one of the two sub-intervals of above and let and be the two shortest path trees computed from the endpoints of . The intersection of edges of and forms a forest. Consider any tree in this forest and suppose that is contained in the interval of roots whose shortest path trees contain . Then for the recursive call to , can be contracted since all shortest path trees computed in that recursive call must contain ; see Figure 2 with playing the role of .

Hence, instead of recursing on with the entire graph , the algorithm instead recurses on the graph obtained from by contracting all trees satisfying the above condition. To ensure that contractions preserve shortest paths, let be one of the contracted trees. Then edge weights are modified as follows (see Figure 1):

  • For every edge ingoing to , its weight is increased to unless its endpoint is the root ; this ensures that shortest paths can only enter through .

  • For every edge outgoing from , its weight is increased by the shortest path distance from to in ; this ensures that the contraction of does not decrease shortest path distances.

It turns out that this simple preprocessing only requires time. To sketch why this is true, consider any edge of and let be the interval of roots of whose shortest path trees contain . Let us refer to the intervals obtained during the recursion as subproblem intervals. We can now make the following observations:

  • If a subproblem interval is disjoint from then is not part of any shortest path tree in the recursive call to .

  • If a subproblem interval is contained in then since is contracted, is also not part of any shortest path tree in the recursive call to .

  • On each recursion level, only subproblem intervals partially intersect .

It follows that is only part of shortest path trees in all recursive calls so the total size of all shortest path trees is . The time spent on computing a shortest path tree in a graph is linear in the size of . By sparsity of simple planar graphs, the size of is proportional to the number of tree edges. It follows that all shortest path trees can be computed in a total of time.

We argue that the additional work spent in the recursive calls can also be executed within this time bound. For instance, determining whether to contract a tree in the intersection of two shortest path trees and can be done by looking at the cyclic ordering of the two parent edges of resp.  ingoing to the root of and the edges of emanating from ; see Figure 2. This takes time linear in the size of the current graph over all trees .

Handling a query.

Efficiently answering a query is now simple, given the above preprocessing. Pseudo-code for the query algorithm can be found in Algorithm LABEL:alg:MSSP_Query but here we only describe it in words and sketch the analysis.

A query for the shortest path distance from a root of to a vertex is done by following the path down the recursion tree for the subproblem intervals containing . For each such subproblem interval , if is an endpoint of , the shortest path distance is returned since it is stored in the shortest path tree computed from . Otherwise, let be the tree that contains and that is contracted for the next recursive step (this includes the special case where is the trivial tree consisting of the single vertex ). The shortest path from to passes through the root of . We compute the -to- distance by recursively computing the -to- distance and adding to it the -to- distance; the latter is precomputed within the time bound for the preprocessing step above. As each recursive step takes time, we get a total query time of .

4 The MSSP Data Structure

We now give a formal description and analysis of our MSSP data structure.


The preprocessing procedure in LABEL:alg:MSSP_Preproc starts by partitioning the interval into two roughly equally sized subintervals and , in Lines LABEL:lne:start-LABEL:MSSP:Trees. It then computes the shortest path trees of the boundary vertices in the graph (after removing the other boundary vertices). If , the data structure is recursively built for each of the two subintervals in the loop starting in LABEL:MSSP:J. To get the desired preprocessing time, the data structure ensures that the total size of all graphs at a given recursion level is . For each subinterval , this is ensured by letting the graph for the recursive call be a suitable contraction of . More precisely, is obtained from by contracting suitable edges that are guaranteed to be in the SSSP trees of every root with . The construction of and the procedure Contract handle the details of these contractions (illustrated in Figure 1). They also store in LABEL:MSSP:global the information necessary for later queries.

Figure 1: To the left, we have tree . To the right we contract and identify the supervertex with . We update the weight of outgoing edges and remove the edges ingoing in .

A small but important implementation detail, we point out, is that while the pseudocode specifies that LABEL:alg:MSSP_Preproc initializes each graph as a copy of in LABEL:lne:copyGraph, the data structure technically only copies the subset of the vertices on . By our earlier simplifying assumption, the omitted roots are not part of any shortest path tree in any recursive calls involving sub-intervals of so omitting them will not affect the behaviour of MSSP. Including the entire face in all recursive calls, however, eases the presentation of proofs.


The query procedure is straight-forward and given by LABEL:alg:MSSP_Query.


5 Analysis

We now prove the following theorem which summarizes our main result.

Let be an -vertex planar embedded graph and be the infinite face on . Then we can build a data structure answering the distance between any vertex and any other vertex in time, using procedure . Preprocessing requires time and space, using procedure MSSP.


Let us first prove correctness of the data structure. We start with the observation that no edge incident to is ever contracted.

For any graph , no edge incident to is contracted by MSSP.


This is immediate from our assumption that no shortest path has an ingoing edge to a vertex of since only edges shared by shortest path trees are contracted. ∎

Next, we prove a lemma and its corollary that roughly show that the contractions made in Procedure MSSP do not destroy shortest paths from roots on sub-intervals of . The reader is referred to Figure 2 for intuition.

Figure 2: The shortest path trees from and share the dashed edges denoting the tree containing . The shortest -to-, -to- paths and the subpath from to in clockwise order along define (fat line). As are in clockwise order around , is in . For , any -to- path intersects either the shortest -to- or the shortest -to- path.

We first need the following simple claim. For any invocation of MSSP, any , and any , some -to- path exists in .


By assumption, an -to- path exists in . The claim now follows since is obtained from contractions in by Section 5. ∎

Consider any invocation of MSSP where has unique shortest paths from for each . Then for each vertex in Line LABEL:MSSP:Ts and for each , .


The proof is trivial for , thus we assume . Now consider paths and . Both paths exist by Section 5. By uniqueness of shortest paths in , they share only vertex .

Next, consider the concatenation of and the reverse of . From the above, is simple. Further, consider the concatenation of and the path segment from to in clockwise order around . We note that is a cycle. As is simple, so is , and by our simplifying assumption for shortest paths and Section 5, only intersects in vertices and . Thus, is a simple directed cycle.

By the Jordan curve theorem, partitions the plane into two regions. One region, denoted , is the region to the right when walking along . does not intersect the simple curve since is a planar embedded graph and since shortest paths are simple. It also does not intersect as there are no ingoing edges to in (and is preserved in contractions by Section 5). Since for each child of in , the edges are clockwise around , children of are contained in , and hence so is .

By the choice of , does not belong to so intersects . Since and since there is no edge of with and , cannot intersect so it must intersect in and hence intersect either or ; assume the former (the other case is symmetric). Then intersects in some vertex . Since shortest paths are unique, the subpath of from to must then equal and since is on this subpath, the lemma follows. ∎

Let be one of the graphs obtained in a call to MSSP by contracting edges in . Then, for each and each , is unique and .


By Section 5, when contracting by , no edge on the path has its weight increased to . Further, for any edge , either existed already in in which case its weight is unchanged, or originated from an edge for . But in the latter case, contains followed by (Section 5), whose weight is . Thus .

It is straight-forward to see that distances in also have not decreased since edges affected by the contractions obtain weights corresponding to paths in between their endpoints or weight . Uniqueness follows since two different shortest paths in from to a vertex would imply two different shortest paths between the same pair in and, by an inductive argument, also in , contradicting our assumption of uniqueness. ∎

In fact, Section 5 is all we need to prove correctness of our algorithm.

The call Query outputs , for . In particular, Query outputs for .


We prove this by induction on . If then Query directly returns . This, in turn, is equal to as the only -to- paths not considered contain an -weight edge with both endpoints in . Therefore the claim holds if as is implied.

For the inductive step, we thus assume and . Let and assume (the case is symmetric). Let be the vertex in such that , where possibly (Line LABEL:MSSP:uInTs). By the inductive hypothesis, Query returns Query. By Section 5, . By definition of , is a suffix of , meaning that . Finally, by Lemma 5 the shortest path in from to contains , therefore . ∎

Bounding Time and Space.

The following Lemma captures our key insight about LABEL:alg:MSSP_Preproc that ensures that the algorithm can be implemented efficiently.

Let be the set of all intervals , such that is executed at recursion level after invoking .

For each edge and recursion level , there are only intervals for which there exists an such that the SSSP tree from in contains .


We use induction on . As the Lemma is trivial for level . For , we show the inductive step . Each interval satisfies exactly one of the following conditions:

  • : Consider a recursive call for issued in where was obtained by contracting some edge set in . By Section 5, for any , , but due to our condition and , this path cannot contain .

  • : Let be the subset of intervals satisfying this condition and let be the intervals contained in such intervals . We show that for at most one does there exist a sub-interval where has not been contracted in .

    Consider the set of shortest paths in from each endpoint of an interval in to vertex . Their union is a tree with leaves in and with all edges directed towards the root ; see the dashed paths in Figure 3. By definition of and and by repeated applications of Corollary 5 to intervals containing at recursion levels less than , each shortest path in is a subpath of a shortest path to in with as the final edge. Since shortest paths are simple, cannot belong to .

    Now, consider an interval . Let be the nearest common ancestor of and in . Let be the simple directed cycle obtained by the concatenation of the path , the reverse of the path , and the path from to in counter-clockwise order along . Let be the open region of the plane to the left of . Note that shortest path is concatenated with . If emanates to the left of at then since a shortest path cannot cross itself, must belong to . In this case, cannot also belong to for any other since these regions are pairwise disjoint; see Figure 3. Hence, there is at most one choice of where emanates to the left of at .

    Using the above notation, it now suffices to show that for an interval where emanates to the right of at , is contracted in .

    Let be the parent interval containing . By Corollary 5, is obtained from by edge contractions and is obtained similarly from . Let resp.  be the ingoing edge to in resp. . Edge is not in the shortest path tree from in (otherwise, this tree would have both and ingoing to ) so by Corollary 5, is not contracted in . Similarly, is not contracted in . It follows that is a vertex in . Let be the first edge on ; this is well-defined since contains at least one edge, namely . By the choice of and by the embedding-preserving properties of contractions, , , and are clockwise around . Inspecting the description of MSSP, we see that is contained in a tree with , so is contracted in .

    Figure 3: Dashed lines are parts of shortest paths from vertices in to and form a tree. In the second recursion level we have intervals . Vertex is the nearest common ancestor of and and is the open region to the left of the simple cycle defined by , the reverse of and the part of from to in counter-clockwise order. Regions are defined similarly for the other intervals. Focusing on interval , let be the vertex after towards in the tree (in this case ). Edges are in counter-clockwise order, implying that belongs to . Since regions are pairwise disjoint, belongs to no other region.
  • , and : At most two intervals satisfy this condition which can then spawn at most four intervals in ; this follows from repeated applications of Corollary 5 combined with the easy observation that roots of whose shortest path trees in contain are consecutive in the cyclic ordering along  [Klein05].

The procedure uses time and space. Procedure Query has running time.


For each recursion level , Section 5 implies that each edge appears in at most computed SSSP trees. Further, . Thus, the total number of vertices in summed over all is . By sparsity of planar graphs, the total number of edges in these graphs is as well.

For each such graph , each SSSP computation in can be implemented in time linear in the size of by [HenzingerKRS97]. We also spend this amount time on constructing the graphs from since the set and associated trees can be found in time per edge. Each edge is outgoing from at most one and ingoing to at most one contracted tree and thus possibly changing its weight requires only time.

It follows that the entire time spent on recursion level is . Since there are at most levels, the first part of the corollary follows. The second part follows since each recursive step in Query takes constant time. ∎


Appendix A Satisfying the input assumptions

In this section, we show how to ensure the input assumptions from the preliminaries.

If is not the external face , a linear time algorithm can reembed to ensure this.

Next, we need to be a simple cycle. We let be the vertices on ordered by their first appearance in the walk along in clockwise order starting in an arbitrary vertex , such that the rest of is on the right when moving on the walk. For each , we add a vertex , and a zero-weight edge embedded in the region enclosed by that does not contain the rest of . Finally, we add edges in a simple cycle, with infinite weights, and redefine to be this cycle. It is not hard to see that this transformation can be done in time and that any query in the original graph can be answered by querying in the transformed graph.

Let . To ensure the requirement that every can reach every vertex of in , we add suitable edges of large finite weight to to make this subgraph strongly connected without violating the embedding of .

Disallowing shortest paths from having edges ingoing to will not disallow any shortest path from in the original graph: each such path can be mapped to a path of the same weight in the transformed graph that only intersects in .

Finally, unique shortest paths can be ensured using the deterministic perturbation technique in [UniqueShortestPaths]).