Abstract 1 Introduction 2 Fundamental concepts 3 Touring overlapping orthogonal polygons 4 Touring step-disjoint orthogonal polygons 5 Touring step-disjoint ortho-convex polygons References

Touring a Sequence of Orthogonal Polygons

Katrin Casel ORCID Humboldt-University Berlin, Germany    Sándor Kisfaludi-Bak ORCID Aalto University, Espoo, Finland    Linda Kleist ORCID University of Hamburg, Germany    Jeroen S.K. Lamme ORCID Eindhoven University of Technology, The Netherlands    Eunjin Oh ORCID POSTECH, Pohang, South Korea    Yanheng Wang ORCID ETH Zurich, Switzerland
Abstract

We study the problem of computing a shortest tour that visits a sequence of k polygons P1,,Pk with a total number of n vertices. A tour is an oriented curve such that there exist points piPi for all i where pi appears not after pi+1. In a seminal paper, Dror, Efrat, Lubiw and Mitchell (STOC 2003) considered the problem under L2 distance, and gave O~(nk) and O~(nk2) algorithms for disjoint and intersecting convex polygons, respectively. In this paper, we consider the orthogonal setting (with orthogonal polygons and Manhattan distance) and obtain the following results:

  • a truly subquadratic O~(n2148) algorithm when consecutive polygons in the sequence are disjoint;

  • an O~(n) algorithm for ortho-convex polygons when consecutive polygons are disjoint;

  • an O(n) algorithm for axis-aligned rectangles;

  • O~(n2) and O~(n1.5k2) algorithms without restrictions.

Our algorithms build on a wide range of techniques, including additively weighted Voronoi diagrams, rectangle decompositions, persistent data structures, and dynamic distance oracles for weighted planar graphs.

Keywords and phrases:
shortest path, subquadratic time, dynamic planar distance oracle
Category:
Track A: Algorithms, Complexity and Games
Funding:
Sándor Kisfaludi-Bak: Supported by the Research Council of Finland, Grant 363444.
Eunjin Oh: Supported by Institute of Information & Communications Technology Planning & Evaluation (IITP) grant funded by the Korea government (MSIT) (No.RS-2024-00440239, Sublinear Scalable Algorithms for Large-Scale Data Analysis) and the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT) (No.RS-2024-00358505).
Yanheng Wang: Part of this work was finished at Saarland University, Saarbrücken, Germany. It was part of the project TIPEA that has received funding from the European Research Council (ERC) under the European Unions Horizon 2020 research and innovation programme (grant agreement No. 850979).
Copyright and License:
[Uncaptioned image] © Katrin Casel, Sándor Kisfaludi-Bak, Linda Kleist, Jeroen S.K. Lamme,
Eunjin Oh, and Yanheng Wang; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry
; Theory of computation Dynamic programming
Related Version:
The full version is available at: https://arxiv.org/abs/2605.07882
Acknowledgements:
This work was initiated at the 2025 Lorentz Center workshop “Fine-Grained and Parameterized Computational Geometry” in Leiden, the Netherlands.
Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis

1 Introduction

Shortest paths between two points in geometric environments can often be computed in near-linear time. However, in settings where the path is constrained to avoid or pass through given regions, polynomial-time algorithms might not exist. For example, computing a shortest path that avoids axis-aligned half-planes in 3, or one that passes through non-convex regions in 2 are both NP-hard problems [30, 20].

In this paper we study a constrained shortest path problem Polygon Touring: given a sequence P1,,Pk2 of polygons with n vertices in total, compute (the length of) a shortest tour that visits the polygons in order. A tour π is an oriented open curve, and it visits a sequence of polygons P1,,Pk if there exist points piPi for all i{1,,k} such that π goes through p1,,pk in order. We highlight that the points may coincide; see Figure 1 for an example. One can measure the length of a tour in different metrics, and natural choices include the Manhattan (L1) and Euclidean (L2) metrics.

Figure 1: A tour visiting a sequence of five orthogonal polygons. All polygons but P2 are ortho-convex. Note that deleting P5 yields a step-disjoint instance.

Polygon Touring has obvious applications in motion planning and logistics in physical environments [21, 25, 27, 32]. It is also used as a subroutine in several geometric optimization problems, such as the watchman route problem [29, 31], the safari and zookeeper problems [35, 5, 22], and even variants of convex hull [28, 36, 19, 1]. The problem can also be understood as the 2-dimensional offline version of the convex body chasing problem [23, 33, 3, 2, 13, 34].

Dror, Efrat, Lubiw and Mitchell [20] studied Polygon Touring under L2 when the polygons are convex. In their formulation the starting point of the tour is fixed, i.e., P1 degenerates to a single point. They gave an O(nklogn)-time algorithm if the given convex polygons are disjoint, and an O(nk2logn)-time algorithm if they are allowed to overlap. On the other hand, they showed that the problem becomes NP-hard if the polygons are non-convex, or even if each Pi consists of a pair of segments with a shared endpoint.

This raises interesting questions from a fine-grained perspective. For example, is there a truly subquadratic time algorithm (i.e., of running time O(n2ε) for some ε>0) that solves Polygon Touring under L2, assuming convex disjoint polygons of constant size each?

As our take to the question, we consider an interesting variant of touring orthogonal polygons (where every edge is either horizontal or vertical) under L1. This setting avoids precision issues under L2 and allows us to concentrate on the combinatorial side of the problem. Here obtaining an O~(n2)-time algorithm is in fact an open problem. Dror et al. [20] claimed an O(n2)-time algorithm but did not present a full proof. A straightforward interpretation of their sketch would lead to an algorithm in cubic time (more precisely, O(n2k) time).

Question 1.

Is there an O~(n2)-time algorithm for touring a sequence of orthogonal polygons under L1? What about O~(nk) or even truly-subquadratic time?

Guided by known results in L2, we can expect that the problem becomes easier when the polygons are disjoint and/or convex. In case of orthogonal polygons the only convex polygons are axis-aligned rectangles. This leads us to the second question:

Question 2.

Is there a faster algorithm for touring a sequence of disjoint orthogonal polygons under L1? What about touring a sequence of rectangles under L1?

Our contribution

Table 1: Overview of our results for Orthogonal Polygon Touring(n,k).
input restriction time complexity refer to
O(n2log2n) Theorem 1
O~(n1.5k2) Theorem 4
step-disjoint O~(n2148) Theorem 3
step-disjoint, ortho-convex O~(n) Theorem 5
rectangles O(n) Theorem 2

In what follows, we consider Polygon Touring for a sequence of k orthogonal polygons with n vertices in total and measure all distances in L1 metric. We denote this problem by Orthogonal Polygon Touring(n,k). Table 1 summarizes our results. As a baseline, we design an O~(n2)-time algorithm, thereby partially answering Question 1.

Theorem 1.

Orthogonal Polygon Touring(n,k) is in time O(n2log2n).

The proof of Theorem 1 already contains some non-trivial ideas that recur in the other results. First observe that we may restrict our attention to tours whose vertices lie on the the grid, i.e., the intersections of the horizontal and vertical lines through polygon vertices. Since the grid has O(n2) points, this leads to a naive dynamic program that runs in time O(n2k). To improve the running time it is helpful to consider the case of step-disjoint polygons, where any two consecutive polygons in the sequence are disjoint. (In Figure 1, P1,,P4 is step-disjoint, while P1,,P5 is not.) In this case, a shortest tour π must enter each polygon Pi at a boundary point which is also on the grid; we call these points portals. Note that the number of portals on Pi is at most n times the number of edges in Pi, so the total number of portals over all polygons is O(n2). It remains to design an efficient data structure that allows one to query, for each portal on Pi+1, the shortest tour ending there. Since such tour must pass through a portal on Pi, we can build an additively weighted Voronoi diagrams over the portals on Pi to handle these queries efficiently.

In the general case where consecutive polygons can overlap, a shortest tour may enter a polygon directly at a grid point in its interior; see for example P5 in Figure 1. We handle the situation by “tunneling” through the overlapping polygons with the help of a segment-tree-based data structure.

We do not know how to push this approach to fully address Question 1. Nevertheless, we manage to obtain truly-subquadratic time algorithms under various natural restrictions. In the most restricted case, we consider a sequence of rectangles and answer the second half of Question 2:

Theorem 2.

Orthogonal Polygon Touring(n,k) for rectangles can be solved in O(n)=O(k) time.

This highly specialized algorithm uses the convexity of rectangles in a strong way, and does not even generalize to polygons with O(1) edges each (such as L-shapes). It is also challenging to solve the other extreme: a sequence of O(1) polygons with Θ(n) edges each. As our main result, we propose ideas to solve both extremes for step-disjoint sequences, and to interpolate the extremes into a truly subquadratic algorithm. This answers the first half of Question 2.

Theorem 3 (Main theorem).

Orthogonal Polygon Touring(n,k) for step-disjoint orthogonal polygons can be solved in O~(n2148) time.

The global structure of the algorithm is to split the sequence into batches of two types: a dense batch contains few polygons (but each polygon may have many edges), whereas a sparse batch contains polygons with few edges. It uses different strategies to process the two types and chain them together. For simplicity, we expose the ideas on two extreme cases: In the dense case kn0.1 is small (thus all polygons are in one dense batch); and in the sparse case k=Ω(n) and all polygons have O(1) edges (thus all polygons are in one sparse batch).

In the dense case, we start by partitioning the plane into rectangles using a technique of De Berg and Van Kreveld [18]. The partition has the property that, for every polygon Pi and rectangle R, the intersection PiR is either a collection of horizontal stripes or a collection of vertical stripes. As a result, the tour inside R is rather simple and can be reduced to one-dimensional problems. Our idea is to build a dynamic program on the grid points induced by rectangle boundaries. For each such grid point p (called a hub) and each index i we want to compute the shortest tour visiting P1,,Pi,p. We need to iterate over index pairs 1ijk during the computation, and the number of hubs can be bounded by O(n1.5), so this results in an algorithm with running time O~(n1.5k2). Due to the quadratic dependence on k this algorithm is not subquadratic for larger values of k, so we need a completely different strategy for the sparse case.

In the sparse case, we face a long sequence of polygons with few edges. Importantly, if the tour is visiting a pair of consecutive polygons Pi and Pi+1 and makes a turn (i.e., changes from horizontal to vertical or vice versa) somewhere between their visits, then the turn can only be justified by a local grid point, i.e., on some point that is the intersection of some horizontal and vertical lines through the vertices of Pi and Pi+1. Since both polygons have few edges, the local grid has very small complexity. Tours making a turn between each consecutive pair can be handled using weighted Voronoi diagrams.

Unfortunately, it is possible that a tour traverses a subsequence of consecutive polygons without making any turns, and hence without snapping to the local grid. Tracking such tours efficiently is far from trivial. In order to compute tours that stay on a given horizontal line y=y, we build an auxiliary planar graph whose nodes are arranged by layers that correspond to the polygon index 1ik, and inside each layer by x-coordinates that correspond to the x-coordinates where the polygons intersect the line y=y. The shortest horizontal tour on y=y visiting the polygons corresponds to a shortest path in this graph that percolates from the first layer to the last layer. We cannot afford building these graphs from scratch for each relevant value of y, as this requires quadratic time. However, we observe that as we sweep a horizontal line bottom up, the number of updates to the planar graph is linear in total, and we can apply a multi-source distance oracle for dynamic planar graphs by Charalampopoulos and Karczmarz [16] to beat quadratic time.

Interpolating the dense and sparse cases requires further finesse. In particular, we need to deal with instances that contain both dense and sparse batches. A challenge is to pass information from one batch to the next and bridge the difference in strategies. The bridging is efficient only if the polygon delimiting the two batches has a small number of edges. Fortunately, we show a batching strategy such that all the delimiters have small complexity.

This concludes our overview of the main theorem. As a byproduct of the dense case we also obtain an algorithm for potentially overlapping polygons. The algorithm is truly-subquadratic (hence, faster than Theorem 1) whenever kn0.25ε for any ε>0.

Theorem 4.

Orthogonal Polygon Touring(n,k) can be solved in O~(n1.5k2) time.

In another result, we consider ortho-convex polygons, which are orthogonal polygons with the property that any horizontal or vertical line intersects them in a segment. If the ortho-convex polygons are step-disjoint, then a vertical edge S of Pi cannot have points of Pi1 both to its left and right. Hence, for each grid point pS, the shortest tour visiting P1,,Pi1,p can be efficiently described by the distance functions on the vertical edges of Pi1 that are “facing” S. The distance functions in turn are piecewise linear and have slopes 1, 0 or 1. By handling and updating these functions in a persistent data structure we are able to solve the step-disjoint ortho-convex case in near-linear time, avoiding the reliance on dynamic planar graph algorithms.

Theorem 5.

Orthogonal Polygon Touring(n,k) can be solved in O(nlogn) time for step-disjoint ortho-convex polygons.

While this paper is about fast algorithms for Orthogonal Polygon Touring, the problem is also interesting from the lower bound/fine-grained complexity perspective. In particular, it does not seem to have the same quantifier structure as typical geometric problems studied in the fine-grained literature such as curve and shape similarity problems [6, 10, 11, 8, 12], intersection graph problems [9, 14], clustering [15], and point-line incidence problems [24, 4]. We raise the following natural question.

Question 3.

Is there a super-linear conditional lower bound for touring a sequence of convex polygons under L2, or for touring orthogonal polygons under L1?

Towards this direction we consider the generalized problem in 3-dimensional space: touring a sequence of k orthogonal polytopes of n vertices in total. The problem has a straightforward O~(n3k) algorithm. We show a conditional lower bound assuming the orthogonal vectors hypothesis (OVH). See [7] for an overview of popular fine-grained conjectures.

Theorem 6.

Assuming OVH, no algorithm can solve Orthogonal Polytope Touring(n,k) for step-disjoint 3-dimensional polytopes in time O(n2ϵpoy(k)), for any ε>0.

Organization.

Section 2 introduces the fundamental concepts and structures. Section 3 studies the general case without input restriction. Sections 4 and 5 assume step-disjointness and present truly-subquadratic time algorithms for orthogonal polygons and ortho-convex polygons, respectively. Along the way we also obtain an algorithm that handles (a small number of) overlapping polygons. The remaining results (Theorems 2 and 6) are presented in the full version of this paper. A few lemmas are marked with asterisks: their proofs are straightforward and thus omitted. The reader may find them in the full version as well.

2 Fundamental concepts

We write [N]:={1,,N}. A polygon is orthogonal if all its edges are horizontal or vertical. For simplicity of presentation, we assume that all polygons are in general position, i.e., no two edges are collinear. The assumption can be removed by imposing an ordering on collinear edges. For a polygon P, let x(P) and y(P) be the sets of x and y-coordinates of the vertices of P, respectively. Denote n(P):=|x(P)|=|y(P)|. In the Orthogonal Polygon Touring(n,k) problem, we are given orthogonal polygons P1,,Pk with total complexity n:=i=1kn(Pi), and the goal is to compute (the length of) a shortest tour under L1 metric that visits P1,,Pk. We say that the input sequence of polygons is step-disjoint if Pi and Pi+1 are disjoint for all 1ik1.

For each index i[k] and point p, we define fi(p) as the length of a shortest tour that visits P1,,Pi1,p in sequence. We also define next(i,p):=min{ji:pPj}. (If j does not exist then let next(i,p):=k+1.) These definitions play a central role in our algorithms.

It is sometimes convenient to represent tours as discrete sequences instead of continuous curves. The notion of skeletons serves this purpose.

Definition 7.

A skeleton visiting P1,,Pk is a sequence (i1,q1),,(im,qm) such that 1=i1i2,,im<im+1:=k+1 and qtiti<it+1Pi for all t[m]. We say that the skeleton has size m and length i=2mdist(qi1,qi).

So far as the minimum length is concerned, skeletons and tours are equivalent:

Lemma 8 ().

The minimum length of tours visiting P1,,Pk is equal to the minimum length of skeletons visiting P1,,Pk.

The next lemma provides crucial insights into the structure of minimum length skeletons.

Lemma 9.

Among all minimum length skeletons visiting P1,,Pk, there is a skeleton (i1,q1),,(im,qm) with the four properties listed below. Here we denote Qt:=iti<it+1Pi.

  1. 1.

    For each t[m], we have next(it,qt)=it+1.

  2. 2.

    For each t[m], we have qtQt.

  3. 3.

    For each t[2,m], at least one of the following holds:

    1. (1)

      qt is a vertex of Qt or an intersection point in Qt1Qt;

    2. (2)

      qt1,qt are on horizontal edges of Qt1,Qt respectively, and x(qt1)=x(qt);

    3. (3)

      qt1,qt are on vertical edges of Qt1,Qt respectively, and y(qt1)=y(qt);

  4. 4.

    There exists t[m] for which (1) holds.

Proof.

Among all minimum length skeletons (i1,q1),,(im,qm), pick those with the minimum size m. Among all picked skeletons, further pick those such that (i2i1,,im+1im) is lexicographically maximum. We call these skeletons irreducible.

Claim.

Every irreducible skeleton (i1,q1),,(im,qm) satisfies property 1 and has q1Q1.

Proof.

On one hand, next(it,qt)it+1 because qtQt=iti<it+1Pi by the definition of skeletons. On the other hand, next(it,qt)it+1 because otherwise we can replace it+1 with next(it,qt) in the skeleton, which results in another skeleton with the same length and size but a higher lexicographic rank, a contradiction to irreducibility. This shows next(it,qt)=it+1.

Next we show q1Q1. Note that q1Pi2 since next(1,q1)=i2. In particular, q1Q2. Suppose to contradiction that q1Q1, then it must be in the interior of Q1Q2. As q2Q2, we can move q1 towards q2 while staying inside Q1. The skeleton still visits P1,,Pk but the length strictly decreases, which is a contradiction.

In the rest of the proof, we will start from an arbitrary irreducible skeleton σ and modify it into another irreducible skeleton σ that is closer to satisfying properties 2 and 3. In more detail, we will move a point qt to qt, meaning that we replace qt with qt in σ to obtain σ. We will make sure that qtQt and σ has the same length as σ. Once these two conditions are met, it follows that σ still visits P1,,Pk and has the same length, size and lexicographic rank as σ, so it remains irreducible.

To implement the scheme, we first iterate over t[m1]. We have qtPit+1 because next(it,qt)=it+1 by property 1. In particular, qtQt+1. Since qt+1Qt+1, the shortest path between qt,qt+1 must cross the boundary Qt+1. Therefore, we can move qt+1 to Qt+1 while preserving the length. The resulting skeleton is still irreducible. After all iterations, we obtain an irreducible skeleton with property 2.

Next we iterate over s=2,,m. In step s, the goal is to move qs1,qs such that for every t[2,s] either (1), (2) or (3) holds. By property 2, qs1 and qs are on edges es1Qs1 and esQs, respectively. Assume that es is horizontal; the vertical case is symmetric. We distinguish four cases, illustrated in the four columns of Figure 2.

  • If es1 is horizontal, then we move qs along es towards qs1 until it hits a vertex of Qs, or until x(qs1)=x(qs). This ensures (1) or (2) for t=s.

  • If es1 is vertical and entirely below/above es, then we move qs1 to the top/bottom endpoint of es1. Now that qs1 is a vertex, (1) holds for t=s1; moreover, qs1 must lie on a horizontal edge, so we can apply the previous case to move qs and ensure (1) or (2) for t=s.

  • If es1 is vertical and entirely to the left/right of es, then we move qs to the left/right endpoint of es and ensure (1) for t=s.

  • If es1 is vertical and intersects es, then we move qs to the intersection and ensure (1) for t=s.

In any case the goal is achieved. Furthermore, qs1,qs remain on Qs1,Qs, respectively, and the length of the skeleton does not change. Therefore, the resulting skeleton is still irreducible and satisfies property 2. After all iterations, we obtain an irreducible skeleton that satisfies both properties 2 and 3.

Figure 2: The four cases when es is horizontal. The first and second rows illustrate the situation before and after the move, respectively. The orange path in the background illustrates a shortest path between qs1 and qs.

Finally, suppose that property 4 is not yet fulfilled. Then for all t[2,m] either (2) or (3) holds. Assume by symmetry that q1 is on a horizontal edge of Q1, then it is not on a vertical edge as it is not a vertex. Hence q2 must be on a horizontal edge of Q2 and x(q1)=x(q2). Propagating the argument, all q1,,qm are on horizontal edges and have the same x-coordinate. We move all points to the right by the same distance, until some point qt becomes a vertex of Qt, which witnesses property 4. Clearly every point qs remains on a horizontal edge of Qs and has the same x-coordinate, and the length of the skeleton does not change. Therefore, irreducibility and properties 2, 3 are also preserved.

Motivated by Lemma 9, we define the grid of a set of orthogonal polygons 𝒫 as

grid(𝒫):=(P𝒫x(P))×(P𝒫y(P))2.

We define the portals of Pi as porti:=Pigrid({P1,,Pk}).

Corollary 10.

Among all minimum length skeletons visiting P1,,Pk, there is a skeleton (i1,q1),,(im,qm) with the four properties in Lemma 9, as well as the property that qtiti<it+1porti for all t[m].

Proof.

Take a skeleton (i1,q1),,(im,qm) given by Lemma 9. By property 4, some of q1,,qm are vertices or intersections. We split the skeleton at these points into pieces. Consider any piece but the first one. The piece starts with a point qt that is a vertex or an intersection, and no other point is a vertex or an intersection. By property 3, points in this piece either all lie on horizontal edges and have x-coordinate x(qt)i=1kx(Pi), or all lie on vertical edges and have y-coordinate y(qt)i=1ky(Pi). Therefore, every point qs in the piece is a portal. Moreover, since qsQsisi<is+1Pi, we have qsisi<is+1porti. For the first piece, we can make the same argument from where it ends.

When the polygon sequence is step-disjoint, we get a significantly simpler structure:

Corollary 11.

Among all shortest tours that visit a sequence of step-disjoint polygons P1,,Pk, there is a tour that visits a sequence of points p1port1,,pkportk such that for each i[2,k],

  1. (1)

    pi is a vertex of Pi; or

  2. (2)

    pi1,pi are on horizontal edges of Pi1,Pi respectively, and x(pi1)=x(pi); or

  3. (3)

    pi1,pi are on vertical edges of Pi1,Pi respectively, and y(pi1)=y(pi).

Proof.

Take a skeleton (i1,p1),,(im,pm) given by Corollary 10. Since the polygon sequence is step-disjoint, we have next(it,pt)=it+1 for all t by definition, so inductively it=t. Hence the skeleton has form (1,p1),(2,p2),,(k,pk), and for all i[k] we have Qi=Pi and piporti.

3 Touring overlapping orthogonal polygons

In this section, we study Orthogonal Polygon Touring for the general case. Dror et al. [20] stated that the problem can be solved in O(n2) time without elaborating on the proof; a straightforward interpretation of their idea actually needs O(n2k) time. We describe here a simple algorithm in time O(n2log2n), which essentially closes the gap and also serves as a baseline for our other algorithms.

Theorem 1. [Restated, see original statement.]

Orthogonal Polygon Touring(n,k) is in time O(n2log2n).

Proof.

As a preparation, we construct a binary tree, where each leaf node represents an element (i.e., a singleton interval) of [k], and each non-leaf node represents the union of the intervals of its two children; this is a discrete variant of a segment tree [17]. We write I(u) for the interval represented by node u and define Q(u):=iI(u)Pi. Note that Q(u)=Q(v)Q(w) where v,w are the children of u, so we can compute Q(u) for all uT in a bottom-up fashion. Then we build a point location data structure for each Q(u).

It is well-known that the intersection of two orthogonal polygons P and Q can be computed in time O((n(P)+n(Q))2), and a point-location data structure on a polygon P can be built in time O(n(P)logn(P)). So the total time spent per level of T is O((i=1kn(Pi))2logn)=O(n2logn). As there are logk levels, the construction time is O(n2log2n).

Figure 3: Left: an illustration of a segment tree over [8], where the red nodes form the canonical decomposition of [2,8]. Middle: the gray region depicts Q(u). Right: an additively weighted Voronoi diagram on four portals under the L1 metric.

Next we describe a subroutine that, given an index i[k] and a point p, computes the value next(i,p) in time O(log2n). To this end, first compute the canonical decomposition of the interval [i,k]; that is, find logk nodes u1,,uT such that [i,k]=I(u1)I(u) is a disjoint union. Then compute the minimal t[] such that pQ(ut). We descend from node ut towards the leaves; at each step we go to the left child v if pQ(v), and the right child otherwise. In the end we arrive at a leaf that corresponds to exactly min{ji:pPiPj}=next(i,p).

Computing the canonical decomposition takes O(logk) time. Computing t needs logk queries into the point-location data structures. The descent from ut to the leaf needs O(logk) queries as well. Since each query is answered in O(logn) time, the subroutine takes time O(log2n) as claimed. For each i[k] and pporti, we call the subroutine to compute next(i,p) and store the values in a look-up table. Since i=1k|porti|i=1k2n(Pi)n=2n2, the table can be computed in time O(n2log2n).

With these preparations, the main algorithm is a dynamic program. As the base case, we have f1(p)=0 for all pport1. We claim the following recursive formula:

Claim.

For all 2jk and qportj, we have

fj(q)={fj1(q)if qPj1,min{fi(p)+dist(p,q):pporti,i<j,next(i,p)=j}otherwise.
Proof.

If qPj1 then fj(q)=fj1(q) by definition. From now on we assume qPj1. The direction is easy: fi(p) corresponds to a tour visiting P1,,Pi1,pPi, and dist(p,q) corresponds to a tour visiting p,Pi+1,,Pj1,q since next(i,p)=j. Their sum thus corresponds to a tour visiting P1,,Pj1,q.

For the direction, let (i1,q1),,(im,qm) be a minimum length skeleton visiting P1,,Pj1,q given by Corollary 10. Note that qm=qPj1 by definition, thus m2. Moreover, we have im=j because qimijPi but qPj1.

By the guarantee of Corollary 10, p:=qm1im1i<jporti and next(p,im1)=im=j. Hence there exists i[im1,j) such that pporti. For this i we clearly also have next(p,i)=j. Finally, Lemma 8 implies that fj(q) is exactly the length of this skeleton, which is equal to fi(p)+dist(p,q).

The dynamic program iterates over j=2,,k. In each iteration, we construct the additively weighted Voronoi diagram D (under L1 metric) on the point set

Sj:={pporti:i<j,next(i,p)=j},

where each point p has weight fi(p). For each qportj, if qPj1 then we assign fj(q):=fj1(q), else we assign fj(q):=D.dist(q). The correctness follows from the claim above. After all iterations finish, we return min{fi(p):pporti,i[k],next(p,i)=k+1}.

In each iteration j, constructing the Voronoi diagram takes O(|Sj|logn) time [26], and the queries take O(|portj|logn) time. Over all iterations, the time is O(j=1k(|Sj|+|portj|)logn). Note that

j=1k|Sj|=j=1ki<jpporti𝟏next(i,p)=j=i=1kpporti1=i=1k|porti|.

Hence the total time is O(j=1k|portj|logn)=O(n2logn).

4 Touring step-disjoint orthogonal polygons

We move on to study step-disjoint orthogonal polygons P1,,Pk and prove Theorem 3, which breaks the quadratic-time barrier. As a rough outline, the algorithm decomposes the sequence of polygons into batches, where each batch either contains a small number of vertices (sparse batch), or has few polygons (dense batch). The algorithm processes the batches in order. In each round it extends the prefix shortest tours computed so far to visit one more batch. Different strategies are used for sparse and dense batches, and they are driven by different structural insights.

We will make use of two results from the literature. One is a generalized distance oracle for dynamic planar graphs [16, Theorem 18]:

Theorem 12.

Let G be a weighted planar digraph on n nodes, with a set UV(G) of facilities. There exists a data structure maintaining G under edge insertions, edge deletions and changes of U in O~(n3/4|U|1/4+n4/5) update time. Given any vV(G), it can compute minuUdist(u,v) in O~(1) time. The initialization time is O~(n).

The other is a rectangle partition of 2 with low stabbing number [18, Lemma 3.1].

Lemma 13 ().

In time O(n), we can partition 2 into n+1 rectangles such that

  1. (i)

    no rectangle contains a vertex of P1,,Pk in its interior;

  2. (ii)

    every vertical/horizontal line intersects at most O(n) rectangles.

4.1 Decomposition into batches

Let 0<α<β<1 be constants to be determined later. (For concreteness, think of α=0.85 and β=0.98.) We will carefully choose some polygons Pi1,Pi2,,Pir as delimiters, where 1i1<i2<<irk. They split the input sequence into batches (P1,,Pi1),(Pi1,,Pi2),,(Pir,,Pk). We say that a batch (Pi)aib is sparse if i=abn(Pi)3nβ; and it is dense if ban1α+1. Note that a batch can be both sparse and dense.

Lemma 14.

In time O(k) we can compute a set of at most 3n1β delimiters, each of complexity at most nα, such that every batch is either sparse or dense.

Proof.

We color each polygon Pi blue if n(Pi)nα, and red otherwise. This breaks the input sequence into blue and red blocks. We further differentiate a red block (Pi)aib by two types: it is light red if i=abn(Pi)nβ, and dark red otherwise. Clearly there are at most n1β dark red blocks.

Now we fix two consecutive dark red blocks, and consider the sequence of polygons (Pi)aib in between. It must start with a blue block, alternate between light red and blue blocks, and end with a blue block. We mark Pa and Pb as delimiters. We then iterate over i=a,,b and keep a running sum N. At iteration i we let N:=N+n(Pi). If N>nβ and Pi is blue, then we mark Pi as a delimiter and reset N to zero. We run the procedure between every pair of consecutive dark red blocks, and return all the marked delimiters. The running time is clearly O(k). Next we argue that the required properties hold.

The number of delimiters is bounded as follows. Between every pair of consecutive dark red blocks, we mark (i) a delimiter in the beginning; (ii) a delimiter in the end; and (iii) one or more delimiters in the middle. Over all consecutive pairs, the total contribution of (i)(ii) is at most twice the number of dark red blocks, that is 2n1β. The total contribution of (iii) is at most n1β because each time we mark a delimiter this way, the running sum must have exceeded nβ.

By construction every delimiter is blue (i.e., has complexity at most nα). Now consider an arbitrary batch (Pi)aib. There are only two cases:

  • It consists of a dark red block and two adjacent blue polygons. We have ban1α+1 since each red polygon has complexity at least nα and the total complexity is at most n. Hence the batch is dense.

  • It is formed when we scan the sequence between consecutive dark red blocks. The scanning procedure ends the batch as soon as the running sum N exceeds nβ and we see a blue polygon. Since each light red block and each blue polygon can contribute at most nβ to the sum, we have i=abn(Pi)3nβ. Hence the batch is sparse.

From now on we assume that the decomposition in Lemma 14 is computed. Our algorithm will process the batches in order and pass necessary information from one batch to the next. When we finish processing a batch (Pi)aib, we would have computed fb(p) for all pportb. We employ different strategies to process sparse and dense batches. Let us explain the high-level ideas.

Inside a sparse batch, we define terminals as the local analogue of portals. More precisely, these are the boundary points on the grid induced by the batch. Clearly there are at most (3nβ)2=9n2β terminals. We show that there exists a global shortest tour that traverses this batch in one of three ways: (i) it visits a terminal on each polygon in the batch; (ii) it travels horizontally throughout the batch; or (iii) it travels vertically throughout the batch. To handle (i), we use a simple dynamic program over terminals, which costs only polylogarithmic time per terminal. To handle (ii) or (iii), we build a dynamic planar graph and use a line sweep procedure to extract shortest tours to all portals on the last polygon.

Inside a dense batch, the number of terminals can be quadratic, so (i) can no longer be handled efficiently even though the structural insight remains valid. To overcome this barrier, we partition the plane into rectangles with a low stabbing number, which effectively summarizes the geometry. This way, we obtain only O(n3/2) (instead of O(n2)) points worth considering in the dynamic program, which we call hubs. Since the number of polygons is small in a dense batch, this already implies a subquadratic-time dynamic program. However, a hub might not lie on the boundary of any polygon, so we have to deal with the intricate problem of converting f-values on portals to f-values on hubs, and vice versa. We apply two line sweeps based on dynamic planar graphs, one before and one after the dynamic program, to convert between the two worlds.

4.2 Processing sparse batches

Theorem 15.

Let (Pi)aib be a sparse batch. Given fa(p) for all pporta, we can compute fb(p) for all pportb in time O~(n2β+n1+α+n(7+α)/4+n9/5).

We devote the section to proving Theorem 15. Throughout we fix a sparse batch (Pi)aib. We define the terminals of Pi as termi:=Pigrid({Pi}aib). Note that termiporti. Since a sparse batch has complexity O(nβ), the number of terminals is O(n2β).

Lemma 16.

Let pportb. Among all shortest tours visiting P1,,Pb1,p, there is a tour that satisfies one of the following properties:

  1. 1.

    it visits port1,,porta1,terma,,termb1,p;

  2. 2.

    it visits port1,,porta and stays on a horizontal line afterwards until it reaches p;

  3. 3.

    it visits port1,,porta and stays on a vertical line afterwards until it reaches p.

Proof.

Let π be a shortest tour visiting P1,,Pb1,p given by Corollary 11. We claim that π is the tour we are looking for.

To this end, define p1port1,,pb1portb1 as in Corollary 11. First suppose that none of pa,,pb1 is a vertex. If pb1 is on a horizontal edge (thus not on a vertical edge), then Corollary 11 guarantees that x(pb2)=x(pb1)=x(p) and pb2 is on a horizontal edge as well. Propagating the argument in reverse order of time, we conclude that x(pa)==x(pb1)=x(p), so π satisfies property 3. In the symmetric case that pb is on a vertical edge, we conclude that π satisfies property 2.

Next suppose that some of pa,,pb1 are vertices. We split the sequence pa,,pb1 at these vertices into subsequences. Consider any subsequence but the first one. It must start from a vertex, say pi, and does not contain any other vertex. So either all points in it share the same x-coordinate x(pi), or all share the same y-coordinate y(pi). Hence all are terminals. For the first subsequence, we can make the same argument from where it ends. We have thus shown that pitermi for all ai<b, hence π satisfies property 1.

For index aib and point pporti, let fi1(p) be the minimum length among all tours that visit port1,,porta1,terma,,termi1,p. Let fi2(p) be the minimum length among all tours that visit port1,,porta,Pa+1,,Pi1,p and stay horizontal after porta. Let fi3(p) be defined similarly to fi2(p) but now the tour must stay vertical after porta. Lemma 16 states that fi(p)=min{fi1(p),fi2(p),fi3(p)}, so we compute the three values separately.

Type-1 tours.

For aib and pporti, we have the recursive formula

fi1(p)={fi(p)i=a,min{fi11(q)+dist(p,q):qtermi1}i(a,b].

This leads to a straightforward dynamic program: For i=a+1,,b, build a Voronoi diagram D over all qtermi1 using fi11(q) as additive weights, then let fi1(p):=D.dist(p) for all ptermi. (In the last iteration we do so for all pportb.)

Let us analyze the running time of iteration i. Building the Voronoi diagram takes time O~(|termi1|). Querying the Voronoi diagram takes time O~(|termi|) in total. (For the last iteration querying takes time O~(|portb|), which is O~(n1+α) because the delimiter Pb has complexity nα.) Recall that i=ab|termi|=O(n2β) by sparsity, the time complexity over all iterations is O~(n2β+n1+α).

Type-2/3 tours.

These two types are symmetric, so we focus on type 2. We sort 𝒴:=y(P1)y(Pk) in increasing order and cut it into contiguous groups of size n1α each.

Fix an arbitrary group Y𝒴. We sweep a horizontal line yY bottom up. At each sweep step we aim to compute f2(p) for all pportby. To this end we build a weighted planar digraph G(y) as follows (see Figure 4 for an illustration).

  • The node set consists of multiple layers SXaXb, where

    Xi :={x(Pi)i=ax(Pi)x(Pi1)a<ib
    S :={sx,h:xXa,hY}.

    The nodes in each layer Xi are arranged on a line in the natural order. A node xXi is active if (x,y) is a portal.

  • For every pair of neighboring nodes x,xXi in the same layer, we add an edge xx of weight |xx|.

  • For every active node xXi and its copy xXi+1, we add an edge xx of weight 0.

  • For every sx,hS, we add an edge sx,hx. The weight is fa(x,h) if (x,h) is a portal, and otherwise.

  • Finally, we specify U(y):={sx,y:xXa} as the facilities.

Figure 4: The structure of the plane graph G(y) for a batch of three polygons P4,P5,P6. Active nodes are drawn as dots, and inactive nodes are drawn as crosses. Edges are oriented downwards, whose weights are omitted for clarity.

It is clear from the construction that G(y) is planar. Note that |S|=O(nα|Y|)=O(n), and i=ab|Xi|2i=abn(Pi)=O(n) by sparsity. So the number of nodes is bounded by O(n). Moreover, we have f2(x,y)=minuU(y)dist(u,x) for all xXb. In other words, the f2-values can be retrieved by querying the corresponding nodes in the graph.

Observe that G(y) changes marginally when we sweep y for one step: The set of nodes do not change, and at most two inter-layer edges are inserted/removed due to activation/deactivation of nodes. The facilities U(y) change completely, but the size is bounded by |x(Pb)|nα.

Applying the data structure from Theorem 12, we get the following running time:

  • Initialization takes time O~(n);

  • In each sweep step, it takes time O~(n(3+α)/4+n4/5) to update the graph, and time O~(nα) to query the distances to portals.

Finally, we sum over all groups Y. There are nα groups, thus the same number of initializations. Over all groups there are O(n) sweep steps. So the total time of handling type-2 tours in this batch is

O~(n1+α+n1+(3+α)/4+n1+4/5+n1+α)=O~(n1+α+n(7+α)/4+n9/5).
Summary.

Having computed fb1,fb2,fb3, we can compute fb(p)=min{fb1(p),fb2(p),fb3(p)} for all pportb. Correctness is guaranteed by Lemma 16. This completes the proof of Theorem 15.

4.3 Processing dense batches

Theorem 17.

Let (Pi)aib be a dense batch. Given fa(p) for all pporta, we can compute fb(p) for all pportb in time O~(nγ), where γ:=max{95,1+α,7+α4,52α,722α,92α4,332α16}.

We devote the section to proving Theorem 17. Throughout we fix a dense batch (Pi)aib, which by definition satisfies ba=O(n1α). We also fix a rectangle partition from Lemma 13. Property (i) in Lemma 13 implies that for any polygon Pi and rectangle R, the intersection PiR is either a collection of vertical stripes, a collection of horizontal stripes, or empty.111Technically, Pi and R might intersect only on the boundary of R. Nevertheless, this corner case does not affect our arguments. Our algorithm still works by considering the adjacent rectangle R for which PiR is indeed either a collection of vertical stripes or a collection of horizontal stripes. If it is non-empty, we say that Pi is vertical or horizontal in R, respectively.

A hub is a point pgrid({P1,,Pk}) that appears on the boundary of some rectangle. Equivalently, every hub is on the intersection of some vertical/horizontal line through the polygon vertices and some rectangle boundary. Since every line may generate at most O(n) hubs by property (ii) in Lemma 13, and since there are 2n lines in total, we have the following:

Observation 18.

The number of hubs is O(n3/2).

Before we continue, we introduce a canonical decomposition of a tour into phases. Assume that tour π visits pa,,pb in sequence, where pi is the first point in Pi visited by π. Let q1,,qh be the sequence of hubs visited by π. A subtour π[qa,qa+1] between consecutive hubs is called a progression phase if it contains some point pi where aib (generally it may contain a sequence of points pi,,pj). The subtours sandwiched between progression phases are called teleportation phases. See Figure 5 for an example.

Figure 5: An illustration of a tour that visits four polygons P1,P2,P3,P4 and nine hubs. It has two progression phases (in red) and two teleportation phases (in black).
Lemma 19.

Among all shortest tours that visit P1,,Pb in sequence, there is a tour such that every progression phase is confined within a rectangle of the decomposition.

Proof.

We take a shortest tour π that conforms to Corollary 11. Recall that π snaps to grid({P1,,Pk}), its intersection points with the rectangle boundaries are hubs. Recall that every progression phase of π is a subtour between consecutive hubs, so it must be confined within a rectangle.

Zooming into a progression phase, we show that vertical and horizontal movements are in a sense independent.

Lemma 20.

Let R be a rectangle from the decomposition. Consider a shortest tour and its subtour π inside R. Suppose that π starts at hub p, visits Pi,,Pj in sequence, and ends at hub q. Let Ih{i,,j} be the indices corresponding to horizontal polygons in R, and Iv{i,,j} be the indices corresponding to vertical polygons in R. Then the vertical movements of π, all combined, is a shortest vertical tour that visits x(p),(Pt)tIh,x(q) in R. Similarly, the horizontal movements of π, all combined, is a shortest horizontal tour that visits y(p),(Pt)tIv,y(q) in R.

Proof.

We prove the statement for vertical movements; the proof for horizontal movements is symmetric. Assume towards contradiction that there is a shorter vertical tour η that visits x(p),(Pt)tIh,x(q) in R. We replace the vertical movement of π that reaches a polygon Pi by the movement of η that reaches Pi, without changing the order of the movements. The resulting tour starts at hub p, visits Pi,,Pj in sequence, ends at hub q and is shorter, contradicting the optimality of π.

Our algorithm mirrors the alternation between progression and teleportation phases: In a progression phase we walk inside a rectangle and visit a sequence of new polygon(s), while in a teleportation phase we may jump far in space but do not visit any new polygon. The algorithm can be outlined as follows:

  • We use the known fa() values on portals of Pa to initialize fa() on hubs.

  • We run a dynamic program that iterates over j=a+1,,b. In each iteration we compute fj() by implementing one alternation of progression and teleportation phases.

  • In the end, all hubs receive the correct fb() values. We project them back to fb() values on portals of Pb, thereby achieving the goal of the batch.

We will now elaborate on the algorithm.

Initialization.

For initialization, we want to derive fa() values on hubs from the already computed fa() values on porta. We use the same line-sweep procedure as we did for type-2 and 3 tours in sparse batches. Namely, we sweep a global line y and maintain a dynamic planar graph G(y). The graph is unchanged, so the time analysis for updating edges/facilities remains valid. On the other hand, the queries are slightly different: For every hub p=(x,y) and every index aib, we initialize fi(p):=min{query(x)+|xx|,query(x′′)+|x′′x|}, where (x,y) is the closest portal on Pi to the left of p, and (x′′,y) is the closest portal on Pi to the right of p. Hence, for every sweep step we make O((ba)n)=O(n3/2α) queries. Summing over O(n) sweep steps, the total query time is O~(n5/2α).

Altogether, the initialization costs time O~(n1+α+n(7+α)/4+n5/2α+n9/5).

Dynamic program.

For each ajb, rectangle R and hub qR, we define gj(R,q) as the minimum length among all tours that visit P1,,Pj,q and whose final leg is a progression phase in R. The next two lemmas relate f and g.

Lemma 21.

Fix ajb. Given gj(R,p) for all rectangles R and hubs pR, we can compute fj(q) for all hubs q in time O~(n3/2).

Proof.

Recall that fj(q) is the minimum length of a tour that visits P1,,Pj,q. Note that

fj(q)=minhub p(dist(p,q)+minRpgj(R,p)).

The direction is clear since the right hand side always composes a tour that visits P1,,Pj,q in sequence. For the direction, consider a tour defining fj(q). If its last leg was a progression phase in some R, then by definition fj(q)=gj(R,q). Else, its last leg was a teleportation phase from some hub p, prior to which was a progression phase in some R. So fj(q)=gj(R,p)+dist(p,q).

To compute it efficiently, we build a Voronoi diagram D on hubs, with each hub p additively weighted by minRpgj(R,p). Then for each hub q, we compute fj(q):=D.dist(q). Correctness follows directly from the recursion above, so it remains to analyze time complexity. The Voronoi diagram has O(n3/2) sites (hubs) by Observation 18. Computing the additive weight of each site takes time O(1), so the construction of the diagram takes time O~(n3/2). Every hub gives rise to one query into the diagram, which takes time O~(1). So the total query time amounts to O~(n3/2).

Lemma 22.

Fix R and ajb. Given fa(p),,fj1(p) for all hubs pR, we can compute gj(R,q) for all hubs qR in time O(n1αNlogN), where N is the number of hubs on R.

Proof.

Write ij if aijb and each of Pi,,Pj intersects R. In this case, we can partition {i,,j}=:IvIh based on whether a polygon is vertical or horizontal in R. Let hcost(R,i,j,x,x) be the length of the shortest horizontal tour that visits x,(Pt)tIv,x in R; let vcost(R,i,j,y,y) be the length of the shortest vertical tour that visits y,(Pt)tIh,y in R. We claim that

gj(R,q)=minhub pRij(fi1(p)+hcost(R,i,j,x(p),x(q))+vcost(R,i,j,y(p),y(q))).

The direction is clear. For the direction, we consider a shortest tour that defines gj(R,q). Its final leg is a progression phase in R that visits a non-empty sequence of polygons Pi,,Pj where aib and ij. This part of the tour may contain horizontal and vertical movements, and by Lemma 20 the two movements have length hcost(R,i,j,x(p),x(q)) and vcost(R,i,j,y(p),y(q)), respectively. Before this, the tour must have visited P1,,Pi1, so it has length fi1(p) by definition.

We will now compute the recursion efficiently. For each edge eR, we define

gje(R,q):=minhub peij(fi1(p)+hcost(R,i,j,x(p),x(q))+vcost(R,i,j,y(p),y(q))).

Clearly gj=min{gje:e is an edge of R}. So it remains to compute gje for each e.

By symmetry we focus on the case that e is the left edge. Since x(p)=x(e) is a fixed value for all hubs pe, we can factor out the horizontal cost and write

gje(R,q)=minij(hcost(R,i,j,x(e),x(q))+minhub pe(fi1(p)+vcost(R,i,j,y(p),y(q)))).

From now on we fix ij. We compute hcost(R,i,j,x(e),x(q)) for all q by running Dijkstra’s algorithm on a layered graph. Specifically, let L{i,,j} be the indices of the vertical polygons in R. For each L we define a layer V:=x(PR). We also introduce a source layer V0:={x(e)} as well as a sink layer V that contains the x-coordinates of hubs on R. The edges are defined as follows:

  • We arrange the nodes in each layer on a real line, and add an edge between every pair of adjacent nodes. The edge weight is the difference of their x-coordinates.

  • For {0}L and every xV, we find the smallest index > such that PR does not cover x. (We set := if no such index exists.) Then we add an edge from x to

    • the closest node xV to the left of x; and

    • the closest node xV to the right of x.

    The edge weights are both |xx|.

By construction, a shortest tour from x(e) to xV in the graph corresponds to a shortest horizontal tour that visits x(e),(P)L,x in R. So to compute hcost(R,i,j,x(e),x(q)) for all hubs q, it suffices to run Dijkstra’s algorithm from x(e) and read off the distances to all xV. Note that the number of nodes is bounded by O(N), and the number of edges is linear in the number of nodes. Hence Dijkstra’s algorithm runs in time O(NlogN).

In a similar fashion we compute minpe(fi1(p)+vcost(R,i,j,y(p),y(q))) for all q. This time, let L{i,,j} collect the indices of the horizontal polygons in R. For each L we define a layer V:=y(PR). We introduce a source node s and two more layers V0,V. The layer V0 contains the y-coordinates of hubs on e. The layer V contains the y-coordinates of all hubs on R. The edges are defined as follows:

  • We add an edge from the source s to every node yV0 with weight fi1(x(e),y).

  • We arrange the nodes in each layer on a real line, and add an edge between every pair of adjacent nodes. The edge weight is the difference of their y-coordinates.

  • For {0}L and every yV, we find the smallest index > such that PR does not cover y. (We set := if no such index exists.) Then we add an edge from y to

    • the closest node yV above y; and

    • the closest node yV below y.

    The edge weights are both |yy|.

Then we run Dijkstra’s algorithm from s and read off the distances to all yV. The running time is again O(NlogN).

After we have computed the two terms, we add them for each q. We iterate the procedure for every ij and thereby obtain ge, from which we compute g. Since there are at most ba=O(n1α) iterations, the total running time is as claimed.

Corollary 23.

Fix ajb. Given fa(p),,fj1(p) for all hubs pR, we can compute gj(R,q) for all rectangles R and hubs qR in time O~(n5/2α).

Proof.

We apply Corollary 23 for each rectangle R. Since each hub appears on at most four rectangles, the sum over all N’s is bounded by four times the number of hubs, which is O(n3/2).

Now we can assemble the dynamic program. For j=a+1,,b, we apply Corollary 23 to compute g(,,j) from fa(),,fj1(), then we apply Lemma 21 to compute fj() from g(,,j). Hence, each iteration corresponds to an alternation of progression and teleportation phases. When the last iteration finishes, we obtain fb(q) for all hubs q.

Since the number of iterations is ba=O(n1α), the time complexity is bounded by O~(n1α(n3/2+n5/2α))=O~(n7/22α).

Projection.

As the final step, we project the computed fb-values on hubs to fb-values on portals. Not surprisingly, we apply yet another line sweep, but the details are quite different from initialization.

Let 𝒴:=i=1ky(Pi). We sort 𝒴 in increasing order and break it into contiguous groups of size n(2α1)/4 each. Now fix an arbitrary group Y𝒴. We sweep a horizontal line yY bottom up. Since each y hits O(n) hubs, there are at most O(n(2α+1)/4) relevant hubs for the group. We collect the x-coordinates of these hubs into a set X.

For each line y, we build a weighted planar digraph G(y) as follows:

  • The node set consists of multiple layers SXaXb, where

    Xi :={Xx(Pi)i=aXx(Pi)x(Pi1)a<ib
    S :={si,x,h:aib,xX,hY}.

    The nodes in each layer Xi are arranged on a line in the natural order. A node xXi is active if (x,y) is a portal.

  • For every pair of neighboring nodes x,xXi in the same layer, we add an edge xx of weight |xx|.

  • For every active node xXi and its copy xXi+1, we add an edge xx of weight 0.

  • For every si,x,hS, we add an edge si,x,hx. The weight is fi(x,h) if (x,h) is a hub, and otherwise.

  • Finally, we specify U(y):={si,x,y:aib,xX} as the facilities.

See Figure 6 for an illustration. Clearly the graph is planar. Since the complexity of this batch is at most O(n), and ba=O(n1α), we can bound |G(y)|=O(n+n1α|X||Y|)=O(n) and |U(y)|=O(n1α|X|)=O(n(52α)/4).

Figure 6: The structure of the plane graph G(y) for a batch of three polygons P4,P5,P6. Active nodes are drawn as dots, and inactive nodes are drawn as crosses. The nodes that correspond to X are drawn as squares. Edges are oriented downwards, whose weights are omitted for clarity.

When we sweep y for one step, the graph G(y) changes only marginally. The set of nodes do not change, and at most two edges are inserted/removed due to activation/deactivation of nodes. The facilities U(y) change completely. To retrieve fb(p) for every p=(x,y)portby, we simply query the distance from U(y) to xXb. The data structure in Theorem 12 takes O~(n) time at initialization. For each sweep step, it takes time O~(n(172α)/16) to update the graph and facilities, and time O~(nα) to query the distance to portals.

Finally, we sum over all groups Y. There are n/|Y|=n(52α)/4 groups, thus the same number of initializations. Over all groups there are O(n) sweep steps. So the total time is

O~(n1+(52α)/4+n1+(172α)/16+n1+α)=O~(n(92α)/4+n(332α)/16+n1+α).
Summary.

Theorem 17 follows by chaining the initialization, dynamic program and projection.

4.4 Wrapping up the proofs of Theorems 3 and 4

Having shown our batching strategy and the way both sparse and dense batches are handled, we are now ready to prove our main result.

Theorem 3 (Main theorem). [Restated, see original statement.]

Orthogonal Polygon Touring(n,k) for step-disjoint orthogonal polygons can be solved in O~(n2148) time.

Proof.

We first compute a decomposition into sparse and dense batches by Lemma 14, which takes time O(k). If the first batch is sparse we can set f1(p)=0 for all portals pport1. Because the batch is sparse there are at most O(n1+β) of portals on P1. If the first batch is dense we alter its initialization procedure slightly: We use a single source node instead of a source layer in the graph G(y), and all edges incident to the source have weight zero; during the line sweep we do not update the facilities. The time bound remains valid. Then we chain Theorems 15 and 17 to process the batches in order. Each batch requires time O~(nγ) where

γ:=max{95, 2β, 1+α,7+α4,52α,722α,92α4,332α16}.

If the last batch is sparse we return the minimum of fk(p) over all pportk. This gives the shortest tour length by Corollary 11. Since the batch is sparse, the time is bounded by O(|portk|)=O(n1+β). If the last batch is dense we alter the projection procedure slightly. Instead of making a layer with portals in the graph G(y), we create a sink node and add an edge from each node in the last layer to the sink. The minimum tour length is exactly the distance from the source layer to the sink. The time bound remains valid. If we are interested in reconstructing the actual tour, we can use standard backtracking in the dynamic program.

We choose parameters α:=5/6<47/48=:β, thus γ=47/24. Since there are at most 3n1β=O(n1/48) batches, the entire algorithm runs in time O~(n95/48)=O~(n2148).

Our handling of the dense cases yields a proof of Theorem 4 as a byproduct. See 4

5 Touring step-disjoint ortho-convex polygons

In this section we study step-disjoint ortho-convex polygons. A polygon P is ortho-convex if P is a (possibly empty) line segment for every horizontal and vertical line . We show the following theorem.

Theorem 5. [Restated, see original statement.]

Orthogonal Polygon Touring(n,k) can be solved in O(nlogn) time for step-disjoint ortho-convex polygons.

Our algorithm iterates over P1,,Pk. In iteration i[k], the goal is to compute for every edge ePi the restriction fie of fi on e. After all iterations, we simply output the minimum of fke(p) over all edges ePk and portals pe. The correctness is guaranteed by Corollary 11.

Here is the challenge: In the worst case the total complexity of fi over all i[k] is Θ(n2), so we cannot explicitly compute them all. We bypass the issue by representing them in some (interrelated) data structures which avoid explicit evaluation on too many points.

In Section 5.1, we formalize the interface and guarantee of the data structure. Then in Section 5.2, we explain how to implement the algorithm efficiently by applying the data structure as a blackbox. Finally, the full version of this paper includes an implementation of the data structure itself.

5.1 Dynamic mountain ranges

We call a continuous, piecewise linear function f:[a,b] a mountain range if every piece has slope 0, 1 or 1. Its complexity |f| is the number of pieces it contains. A dynamic mountain range f is a mountain range that is initially zero everywhere and undergoes the following updates:

  • restrict(a,b): restrict the domain to [a,b].

  • shift(δ): add δ to f pointwise.

  • relax(λ,γ): given λ{1,1} and γ, replace f by f where

    f(x):=min{f(x),λx+γ}
  • join(g): denote the domain of f by [a,b]. Given another mountain range g over domain [b,c] such that f(b)=g(b), replace f by f where

    f(x):={f(x)x[a,b],g(x)x[b,c].

It also supports the query operation evaluate(x): given any x in the domain, report f(x).

Lemma 24 ().

There is a fully-persistent data structure that maintains a dynamic mountain range f in amortized time O(log|f|) per operation.

As a remark, persistence is needed in our application because we sometimes want to make parallel updates to the same mountain range and keep all the results.

5.2 The algorithm

The notion of (dynamic) mountain ranges is motivated by the following consideration. Corollary 11 implies that for each i[k] the function fie is a mountain range whose pieces meet at portals; moreover, ePi|fie|=O(n) due to ortho-convexity. Note that in the worst case i=1kePi|fie| can be Θ(n2), so we cannot afford to represent all of them explicitly. The trick is to break down these long mountain ranges into fragments that are interrelated by the shift/relax operations. In this way, we only need to represent a small subset of fragments by the dynamic mountain range data structure and infer the others when requested.

More specifically, our algorithm initializes a dynamic mountain range f1e for every edge eP1, using Lemma 24. Now focus on iteration i[2,k]. We inductively assume that the previous iteration has computed fi1e for all edges ePi1. We call pPi1Pi a terminal if pgrid({Pi1,Pi}). Note that a terminal is a portal, but not vice versa. We split every edge of Pi1,Pi at terminals, resulting in fragments. There are at most O(n(Pi1)+n(Pi)) terminals (and thus fragments) because each vertical/horizontal line hits the boundary of an ortho-convex polygon at most twice. It is straightforward to obtain fi1T for all fragments TPi1 using restrict. Based on these dynamic mountain ranges, the next two lemmas allow us to compute fiS for all fragments SPi efficiently. Finally, we can piece together fie for all edges ePi using join, and finish the goal of iteration i.

Lemma 25.

Given dynamic mountain ranges fi1T for all fragments TPi1, we can compute fi(p) for all terminals pPi in time O((n(Pi1)+n(Pi))logn).

Proof.

We start with a structural observation. Let p be a terminal lying on the boundary of Pi. Let q be the point in Pi1 closest to p with x(p)=x(q) (if it exists), and let q be the point in Pi1 closest to p with y(p)=y(q) (if it exists). Note that they are uniquely defined since Pi1 is ortho-convex. Let Vi1 be the set of vertices in Pi1. We claim that fi(p)=min{fi1(r)+dist(r,p):rVi1{q,q}}.

Indeed, note that q,qPi1 due to step-disjointness. Since p is a portal and q,q share a coordinate with p, both points are portals. Now consider a shortest tour that ends at p. By Corollary 11, we may assume that the tour visits either a vertex of Pi1 or q or q. On the other hand, the concatenation of a tour realizing fi1(r) and the tour rp visits P1,,Pi in order for any point rVi1{q,q}. Therefore, the claim holds.

As preprocessing, we compute fi1(r) for all rVi1 using evaluate, and then construct the additively weighted Voronoi diagram of Vi1 where each point r has weight fi1(r). This takes time O(n(Pi1)logn).

After the preprocessing, we are ready to compute fi(p) for each terminal pPi. To this end, we query the Voronoi diagram to obtain min{fi1(r)+dist(r,p):rVi1}. We compute the two terminals q,q (as defined before) and fi1(q),fi1(q) using evaluate. Finally, we can compute fi(p) using the claim above. Since the computation takes O(logn) time for each terminal by Lemma 24, and there are O(n(Pi1)+n(Pi)) terminals on Pi, the overall running time is O((n(Pi1)+n(Pi))logn).

Lemma 26.

Given dynamic mountain ranges fi1T for all fragments TPi1, and fi(p) for all terminals pPi, we can compute fiS for any fragment SPi in time O(logn).

Proof.

We show how to do this for a horizontal fragment S of Pi; the vertical fragments can be handled symmetrically. Let terminals q,q be the left and right ends of S. Let T be the horizontal fragment in Pi1 closest to S such that x(S)=x(T). For any point pS, we claim that

fi(p)=min{fi1(projT(p))+|y(S)y(T)|,fi1(q)+x(p)x(q),fi1(q)+x(q)x(p)}.

To see this, observe that there are three possibilities of the last visited point rPi1 to reach p by Corollary 11. For the first case that x(p)=x(r), since Pi1 is ortho-convex, all points in Pi1 with x-coordinate x(p) must appear on the same side of S. Hence rT, or in other words r=projT(p). For the second case that y(p)=y(r), since Pi1,Pi are disjoint, x(r)[x(q),x(q)]. In particular, the tour rp goes through q or q. For the third case that r is a vertex, x(r)(x(q),x(q)) by definition of fragments, thus the tour rp goes through q or q. Therefore, the claim holds.

To compute fiS, we first compute the closest horizontal fragment TPi1 with x(S)=x(T). The first term in the claim can be obtained by fi1T.shift(|y(S)y(T)|). The second term is a linear function in x(p) with slope +1, namely x(p)x(p)+(fi1(q)x(q)). Similarly, the third term is a linear function in x(q) with slope 1, namely x(p)x(p)+(fi1(q)+x(q)). So the minimum can be computed by calling relax(1,fi1(q)x(q)) and then relax(1,x(q)+fi1(q)). All the operations cost O(logn) time by Lemma 24.

Chaining Lemmas 25 and 26, the description of iteration i is complete. Since each iteration takes O((n(Pi1)+n(Pi))logn) time, overall we need O(i=1kn(Pi)logn)=O(nlogn) time. In the end, we return minpportkfk(p), which is correct by Corollary 11. Since |portk|2n by ortho-convexity, we can find the minimum in O(nlogn) time. This concludes the proof of Theorem 5.

References

  • [1] Antonios Antoniadis, Mark de Berg, Sándor Kisfaludi-Bak, and Antonis Skarlatos. Computing smallest convex intersecting polygons. Journal of Computational Geometry, 16(1):167–202, 2025. doi:10.20382/jocg.v16i1a6.
  • [2] Charles Joseph Argue, Anupam Gupta, Ziye Tang, and Guru Guruganesh. Chasing convex bodies with linear competitive ratio. Journal of the ACM, 68(5):32:1–32:10, 2021. doi:10.1145/3450349.
  • [3] Nikhil Bansal, Martin Böhm, Marek Eliáš, Grigorios Koumoutsos, and Seeun William Umboh. Nested convex bodies are chaseable. Algorithmica, 82(6):1640–1653, 2020. doi:10.1007/s00453-019-00661-x.
  • [4] Luis Barba, Jean Cardinal, John Iacono, Stefan Langerman, Aurélien Ooms, and Noam Solomon. Subquadratic algorithms for algebraic 3SUM. Discrete & Computational Geometry, 61(4):698–734, 2019. doi:10.1007/s00454-018-0040-y.
  • [5] Sergei Bespamyatnikh. An O(nlogn) algorithm for the zoo-keeper’s problem. Computational Geometry, 24(2):63–74, 2003. doi:10.1016/S0925-7721(02)00092-5.
  • [6] Karl Bringmann. Why walking the dog takes time: Fréchet distance has no strongly subquadratic algorithms unless SETH fails. In 2014 IEEE 55th Annual Symposium on Foundations of Computer Science (FOCS), pages 661–670. IEEE Computer Society, 2014. doi:10.1109/FOCS.2014.76.
  • [7] Karl Bringmann. Fine-grained complexity theory (tutorial). In Rolf Niedermeier and Christophe Paul, editors, 36th International Symposium on Theoretical Aspects of Computer Science (STACS 2019), volume 126 of LIPIcs, pages 4:1–4:7. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019. doi:10.4230/LIPIcs.STACS.2019.4.
  • [8] Karl Bringmann, Sándor Kisfaludi-Bak, Marvin Künnemann, Dániel Marx, and André Nusser. Dynamic time warping under translation: Approximation guided by space-filling curves. Journal of Computational Geometry, 14(2):83–107, 2023. doi:10.20382/jocg.v14i2a6.
  • [9] Karl Bringmann, Sándor Kisfaludi-Bak, Marvin Künnemann, André Nusser, and Zahra Parsaeian. Towards sub-quadratic diameter computation in geometric intersection graphs. In 38th International Symposium on Computational Geometry (SoCG 2022), volume 224 of Leibniz International Proceedings in Informatics (LIPIcs), pages 21:1–21:16. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.SoCG.2022.21.
  • [10] Karl Bringmann and Marvin Künnemann. Quadratic conditional lower bounds for string problems and dynamic time warping. In 2015 IEEE 56th Annual Symposium on Foundations of Computer Science (FOCS), pages 79–97. IEEE Computer Society, 2015. doi:10.1109/FOCS.2015.15.
  • [11] Karl Bringmann and André Nusser. Translating Hausdorff is hard: Fine-grained lower bounds for Hausdorff distance under translation. Journal of Computational Geometry, 13(2):30–50, 2022. doi:10.20382/jocg.v13i2a3.
  • [12] Karl Bringmann, Frank Staals, Karol Węgrzycki, and Geert van Wordragen. Fine-grained complexity of Earth Mover’s Distance under translation. In 40th International Symposium on Computational Geometry (SoCG 2024), volume 293 of Leibniz International Proceedings in Informatics (LIPIcs), pages 25:1–25:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.SoCG.2024.25.
  • [13] Sébastien Bubeck, Yin Tat Lee, Yuanzhi Li, and Mark Sellke. Competitively chasing convex bodies. SIAM Journal on Computing, 52(2):STOC19–339–STOC19–353, 2023. doi:10.1137/20M1312332.
  • [14] Timothy M. Chan, Hsien-Chih Chang, Jie Gao, Sándor Kisfaludi-Bak, Hung Le, and Da Wei Zheng. Truly subquadratic time algorithms for diameter and related problems in graphs of bounded VC-dimension, 2025. To appear in proceedings of FOCS 2025. doi:10.48550/arXiv.2510.16346.
  • [15] Timothy M. Chan, Qizheng He, and Yuancheng Yu. On the fine-grained complexity of small-size geometric set cover and discrete k-center for small k. In 50th International Colloquium on Automata, Languages, and Programming (ICALP 2023), volume 261 of Leibniz International Proceedings in Informatics (LIPIcs), pages 34:1–34:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPIcs.ICALP.2023.34.
  • [16] Panagiotis Charalampopoulos and Adam Karczmarz. Single-source shortest paths and strong connectivity in dynamic planar graphs. Journal of Computer and System Sciences, 124:97–111, 2022. doi:10.1016/J.JCSS.2021.09.008.
  • [17] Mark de Berg, Otfried Cheong, Marc J. van Kreveld, and Mark H. Overmars. Computational Geometry: Algorithms and Applications. Springer, 3rd edition, 2008. doi:10.1007/978-3-540-77974-2.
  • [18] Mark de Berg and Marc van Kreveld. Rectilinear decompositions with low stabbing number. Information processing letters, 52(4):215–221, 1994. doi:10.1016/0020-0190(94)90129-5.
  • [19] José Miguel Díaz-Báñez, Matias Korman, Pablo Pérez-Lantero, Alexander Pilz, Carlos Seara, and Rodrigo I. Silveira. New results on stabbing segments with a polygon. Computational Geometry, 48(1):14–29, 2015. doi:10.1016/j.comgeo.2014.06.002.
  • [20] Moshe Dror, Alon Efrat, Anna Lubiw, and Joseph S. B. Mitchell. Touring a sequence of polygons. In Proceedings of the Thirty-Fifth Annual ACM Symposium on Theory of Computing (STOC 2003), STOC ’03, pages 473–482, 2003. doi:10.1145/780542.780612.
  • [21] Jan Faigl, Vojtěch Vonásek, and Libor Přeučil. A multi-goal path planning for goal regions in the polygonal domain. In Proceedings of the 5th European Conference on Mobile Robots (ECMR 2011), pages 171–176, 2011. URL: https://comrob.fel.cvut.cz/papers/ecmr11mtp.pdf.
  • [22] Jan Faigl, Vojtěch Vonásek, and Libor Přeučil. Visiting convex regions in a polygonal map. Robotics and Autonomous Systems, 61(10):1070–1083, 2013. doi:10.1016/j.robot.2012.08.013.
  • [23] Joel Friedman and Nathan Linial. On convex body chasing. Discrete & Computational Geometry, 9(3):293–321, 1993. doi:10.1007/BF02189324.
  • [24] Anka Gajentaan and Mark H. Overmars. On a class of O(n2) problems in computational geometry. Computational Geometry: Theory and Applications, 5(3):165–185, 1995. doi:10.1016/0925-7721(95)00022-2.
  • [25] Shu Ishida, Marc Rigter, and Nick Hawes. Robot path planning for multiple target regions. In 2019 European Conference on Mobile Robots (ECMR), pages 1–6. IEEE, 2019. doi:10.1109/ECMR.2019.8870971.
  • [26] Rolf Klein. Concrete and abstract Voronoi diagrams. Springer, 1989. doi:10.1007/3-540-52055-4.
  • [27] Miroslav Kulich, Jan Vidašič, and Jan Mikula. On the Travelling Salesman Problem with Neighborhoods in a Polygonal World. In José M. Cascalho, Mohammad Osman Tokhi, Manuel F. Silva, Armando Mendes, Khaled Goher, and Matthias Funk, editors, Robotics in Natural Settings, volume 530 of Lecture Notes in Networks and Systems, pages 334–345. Springer, Cham, 2023. doi:10.1007/978-3-031-15226-9_32.
  • [28] Maarten Löffler and Marc van Kreveld. Largest and smallest convex hulls for imprecise points. Algorithmica, 56(2):235–269, 2010. doi:10.1007/s00453-008-9174-2.
  • [29] Joseph S. B. Mitchell. Approximating watchman routes. In Proceedings of the Twenty-Fourth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2013), pages 844–855. SIAM, 2013. doi:10.1137/1.9781611973105.60.
  • [30] Joseph S. B. Mitchell and Micha Sharir. New results on shortest paths in three dimensions. In Proceedings of the Twentieth Annual ACM Symposium on Computational Geometry, SCG ’04, pages 124–133, New York, NY, USA, 2004. Association for Computing Machinery. doi:10.1145/997817.997839.
  • [31] Bengt J. Nilsson and Eli Packer. Approximation algorithms for the two-watchman route in a simple polygon. Algorithmica, 86(9):2845–2884, 2024. doi:10.1007/s00453-024-01245-0.
  • [32] Justo Puerto and Carlos Valverde. The hampered travelling salesman problem with neighbourhoods. Computers & Industrial Engineering, 188:109889, 2024. doi:10.1016/j.cie.2024.109889.
  • [33] Mark Sellke. Chasing convex bodies optimally. In Proceedings of the Thirty-First Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2020), pages 1509–1518. SIAM, 2020. doi:10.1137/1.9781611975994.92.
  • [34] Mark Sellke. Chasing convex bodies optimally. In Geometric Aspects of Functional Analysis: Israel Seminar (GAFA) 2020-2022, pages 313–335. Springer, 2023. doi:10.1007/978-3-031-26300-2_12.
  • [35] Xuehou Tan and Tomio Hirata. Finding shortest safari routes in simple polygons. Information Processing Letters, 87(4):179–186, 2003. doi:10.1016/S0020-0190(03)00284-9.
  • [36] Christophe Weibel and Linqiao Zhang. Minimum perimeter convex hull of imprecise points in convex regions. In Proceedings of the Twenty-Seventh Annual Symposium on Computational Geometry (SoCG 2011), pages 293–294, New York, NY, USA, 2011. Association for Computing Machinery. doi:10.1145/1998196.1998243.