Covering a set of line segments with a few squares
Joachim Gudmundsson, Mees van de Kerkhof, André van Renssen, Frank Staals, Lionov Wiratma, Sampson Wong
CCovering a set of line segments with a few squares
Joachim Gudmundsson , Mees van de Kerkhof , Andr´e van Renssen , FrankStaals , Lionov Wiratma , and Sampson Wong University of Sydney, Australia, [email protected] Utrecht University, Netherlands, [email protected] University of Sydney, Australia, [email protected] Utrecht University, Netherlands, [email protected] Parahyangan Catholic University, Indonesia, [email protected] University of Sydney, Australia, [email protected]
Abstract
We study three covering problems in the plane. Our original motivation for theseproblems come from trajectory analysis. The first is to decide whether a given setof line segments can be covered by up to four unit-sized, axis-parallel squares. Thesecond is to build a data structure on a trajectory to efficiently answer whether anyquery subtrajectory is coverable by up to three unit-sized axis-parallel squares. Thethird problem is to compute a longest subtrajectory of a given trajectory that can becovered by up to two unit-sized axis-parallel squares.
Geometric covering problems are a classic area of research in computational geometry. Thetraditional geometric set cover problem is to decide whether one can place k axis-parallelunit-sized squares (or disks) to cover n given points in the plane. If k is part of the input,the problem is known to be NP-hard [7, 14]. Thus, efficient algorithms are known only forsmall values of k . For k = 2 or 3, there are linear time algorithms [6, 20], and for k = 4 or 5,there are O ( n log n ) time algorithms [15, 18]. For general k , the O ( n √ k ) time algorithm forunit-sized disks [12] most likely generalises to unit-sized axis-parallel squares [1].Motivated by trajectory analysis, we study a line segment variant of the geometric setcover problem where the input is a set of n line segments. Given a set of line segments, wesay it is k-coverable if there exist k unit-sized axis-parallel squares in the plane so that everyline segment is in the union of the k squares (we may write coverable to mean k -coverablewhen k is clear from the context). The first problem we study in this paper is: Problem 1.
Decide if a set of line segments is k -coverable, for k ∈ O (1) . A key difference in the line segment variant and the point variant is that each segmentneed not be covered by a single square, as long as each segment is covered by the union ofthe k squares. See Figure 1.Hoffmann [11] provides a linear time algorithm for k = 2 and 3, however, a proof wasnot included in his extended abstract. Sadhu et al. [17] provide a linear time algorithm for1 a r X i v : . [ c s . C G ] J a n igure 1: A set of 3-coverable segments. Figure 2: A 2-coverable subtrajectory. k = 2 using constant space. In Section 2, we provide a proof for a k = 3 algorithm and anew O ( n log n ) time algorithm for k = 4.Next, we study trajectory coverings. A trajectory T is a polygonal curve in the planeparametrised by time. A subtrajectory T [ s, t ] is the trajectory T restricted to a contiguoustime interval [ s, t ] ⊆ [0 , k -coverable trajectoriesfor k ≥
2. A k -coverable trajectory may, for example, model a commonly travelled route,and the squares could model a method of displaying the route (i.e. over multiple pages,or multiple screens), or alternatively, the location of several facilities. We build a datastructure that can efficiently decide whether a subtrajectory is k -coverable. Problem 2.
Construct a data structure on a trajectory, so that given any query subtrajec-tory, it can efficiently answer whether the subtrajectory is k -coverable, for k ∈ O (1) . For k = 2 and k = 3 we preprocess a trajectory T with n vertices in O ( n log n ) time, andstore it in a data structure of size O ( n log n ), so that we can test if an arbitrary subtrajectory(not necessarily restricted to vertices) T [ s, t ] can be k -covered.Finally, we consider a natural extension of Problem 2, that is, to calculate the longest k -coverable subtrajectory of any given trajectory. This problem is similar in spirit to theproblem of covering the maximum number of points by k unit-sized axis-parallel squares [2,16]. Problem 3.
Given a trajectory, compute its longest k -coverable subtrajectory, for k ∈ O (1) . Problem 3 is closely related to computing a trajectory hotspot , which is a small regionwhere a moving object spends a large amount of time. For k = 1 squares, the existingalgorithm by Gudmundsson et al. [9] computes longest 1-coverable subtrajectory of anygiven trajectory. We notice a missing case in their algorithm, and show how to resolvethis issue in the same running time of O ( n log n ). Finally, we show how to compute thelongest 2-coverable subtrajectory of any given trajectory in O ( nβ ( n ) log n ) time. Here, β ( n ) = λ ( n ) /n , and λ s ( n ) is the length of a Davenport-Schinzel sequence of order s on n symbols. Omitted proofs can be found in the Appendix.2 Problem 1: The Decision Problem
This section restates known results that will be useful for the recursive step in Section 2.2and for the data structure in Section 3.1. The first result relates the bounding box, whichis the smallest axis-aligned rectangle that contains all the segments, to a covering, which isa set of squares that covers all line segments.
Observation 1.
Every covering must touch all four sides of the bounding box.
The reasoning behind Observation 1 is simple: if the covering does not touch one of thefour sides, say the left side, then the covering could not have covered the leftmost vertex ofthe set of segments. An intuitive way for two squares to satisfy Observation 1 is to placethe two squares in opposite corners of the bounding box. This intuition is formalised inObservation 1.
Lemma 1 (Sadhu et al. [17]) . A set of segments is 2-coverable if and only if there is acovering with squares in opposite corners of the bounding box of the set of segments.
Lemma 1 is useful in that it narrows down our search for a 2-covering. It suffices tocheck the two configurations where squares are in opposite corners of the bounding box.For each of these two configurations, we simply check if each segment is in the union of thetwo squares, which takes linear time in total, leading to the following theorem:
Theorem 2.
One can decide if a set of n segments is 2-coverable in O ( n ) time. We notice that for a covering consisting of three squares, Lemma 1 and the pigeon-holeprinciple imply that there must be one square that touches at least two sides of the boundingbox. An intuitive way to achieve this is if one of the squares in the 3-covering is in a cornerof the bounding box. We formalise this intuition in Lemma 2.
Lemma 2.
A set of segments is 3-coverable if and only if there is a covering with a squarein a corner of the bounding box of the set of segments.
Again, this lemma allows us to narrow down our search for a 3-covering. We considerfour cases, one for each corner of the bounding box. After placing the first square in oneof the four corners, we would like to check whether two additional squares can be placed tocover the remaining segments. We start by computing the remaining segments that are notyet covered. We subdivide each segment into at most one subsegment that is covered bythe corner square, and up to two subsegments that are not yet covered. Then we can useTheorem 2 to (recursively) check whether two additional squares can be placed to cover allthe uncovered subsegments.The running time for subdividing each segment takes linear time in total. There areat most a linear number of remaining segments. Checking if the remaining segments are2-coverable takes linear time by Theorem 2. Hence, we have the following theorem:
Theorem 3.
One can decide if a set of n segments is 3-coverable in O ( n ) time. .3 Is a set of line segments 4-coverable? For a 4-covering, it remains true that any covering must touch all four sides of the boundingbox. Unlike the three squares case, we cannot use the pigeon-hole principle to deduce thatthere is a square touching at least two sides of the bounding box. Fortunately, we have onlytwo cases: either there exists a square which touches at least two sides of the bounding box,or each square touches exactly one side of the bounding box. This implies:
Lemma 3.
A set of segments is 4-coverable if and only if: (i) there is a covering with asquare in a corner of the bounding box, or (ii) there is a covering with each square touchingexactly one side of the bounding box.
In the first case we can use the same strategy as in the three squares case by placing thefirst square in a corner and then (recursively) checking if three additional squares can coverthe remaining subsegments. This gives a linear time algorithm for the first case.For the remainder of this section, we focus on solving the second case.
Definition 1.
Define L , B , T and R to be the square that touches the left, bottom, top andright sides of the bounding box respectively. See Figure 3. L T RB
Figure 3: The squares L , T , B and R . y L x T x B Figure 4: The variables y L , x T and x B .Without loss of generality, suppose that T is to the left of B . This implies that the leftto right order of the squares is L , T , B , R . Suppose for now there were a way to computethe initial placement of L . Then we can deduce the position of T in the following way. Lemma 4.
Given the position of L , if three additional squares can be placed to cover theremaining subsegments, then it can be done with T in the top-left corner of the boundingbox of the remaining subsegments. The intuition behind this lemma is that after placing the first square, T is the topmostand leftmost of the remaining squares. A formal proof for Lemma 4 is given in Appendix A.2.For an analogous reason, after placing the first two squares, we can place B in the bottom-left corner of the bounding box of the remaining segments. Finally, we cover the remainingsegments with R , if possible.We have therefore shown that the position of L along the left boundary uniquely deter-mines the positions of the squares T , B and R along their respective boundaries. Unfor-tunately, we do not know the position of L in advance, so instead we consider all possibleinitial positions of L via parametrisation. Let y L be the y -coordinate of the top side of L ,4nd similarly let x T , x B be the x -coordinates of the left side of T and B respectively. SeeFigure 4.Finally, we will try to cover all remaining subsegments with the square R . Define x R and x R to be the x -coordinates of the leftmost and rightmost uncovered points after thefirst three squares have been placed. Similarly, define y R and y R to be the y -coordinates ofthe topmost and bottommost uncovered points. Then it is possible to cover the remainingsegments with R if and only if x R − x R ≤ y R − y R ≤ L uniquely determines T , B and R , we can deduce that the variables x T , x B , x R , x R , y R and y R are all functions of y L . We will show that each of thesefunctions is piecewise linear and can be computed in O ( n log n ) time. We begin by computing x T as a function of variable y L . Lemma 5.
The variable x T as a function of variable y L is a piecewise linear function andcan be computed in O ( n log n ) time. Next, we show that x B is a piecewise linear function of y L , with complexity O ( n ), andcan be computed in O ( n log n ) time. Lemma 6.
The variable x B as a function of variable y L is a piecewise linear function andcan be computed in O ( n log n ) time. Then we compute x R , x R , y R and y R in a similar fashion. Lemma 7.
The variables x R , x R , y R , y R as functions of variable y L are piecewise linearfunctions and can be computed in O ( n log n ) time. Finally, we check if there exists a value of y L so that x R − x R ≤ y R − y R ≤ L , B , T and R that covers all the segments, otherwise, thereis no such position for L , T , B and R . This yields the following result: Theorem 4.
One can decide if a set of n segments is 4-coverable in O ( n log n ) time. In this section, we briefly describe some of the main ideas for building the data structuresthat can answer whether a subtrajectory is either 2-coverable or 3-coverable. Details of thedata structures can be found in Appendix B.We begin by building three preliminary data structures. Given a piecewise linear trajec-tory of complexity n , our preliminary data structures are: Tool 5.
A bounding box data structure that preprocesses a trajectory in O ( n ) time, so thatgiven a query subtrajectory, it returns the subtrajectory’s bounding box in O (log n ) time. Tool 6.
An upper envelope data structure that preprocesses a trajectory in O ( n log n ) time,so that given a query subtrajectory and a query vertical line, it returns the highest intersectionbetween the subtrajectory and the vertical line (if one exists) in O (log n ) time. See Figure 5. Tool 7.
A highest vertex data structure that preprocesses a trajectory in O ( n log n ) time,so that given a query subtrajectory and a query axis-parallel rectangle, it returns the highestvertex of the subtrajectory inside the rectangle (if one exists) in O (log n ) time. See Figure 6. Our construction procedure is to build Tool 5 and Tool 6. Our query procedure consistsof two steps. The first step is to narrow down the covering to one of two configurationsusing Lemma 1 and Tool 5. The second step is to check whether one of these configurationsindeed covers the subtrajectory. The key idea in the second step is to use Tool 6 alongthe boundary of the configuration to see if the subtrajectory passes through the boundary.Putting this together yields:
Theorem 8.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can be stored using O ( n log n ) space, so that deciding if a query subtrajectory T [ a, b ] is2-coverable takes O (log n ) time. Our construction procedure is to build Tools 5, 6, and 7. Our query procedure consists ofthree steps. The first step is to place the first square in a constant number of configurationsusing Lemma 2 and Tool 5. For each placement of the first square, the second step generatestwo configurations by placing the remaining two squares. The key idea in the second stepis to compute the bounding box of the uncovered subsegments by using a combination ofTools 6 and 7. The third step is to check if a configuration indeed covers the subtrajectory.The key idea in the third step is to use Tool 6 along the boundary of the configuration tosee if the subtrajectory passes through the boundary. We require an additional check usingTool 7 in one of the configurations. Putting this together yields:
Theorem 9.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can be stored using O ( n log n ) space, so that deciding if a query subtrajectory T [ a, b ] is3-coverable takes O (log n ) time. In this section we compute a longest k -coverable subtrajectory T [ p ∗ , q ∗ ] of a given trajectory T . Note that the start and end points p ∗ and q ∗ of such a subtrajectory need not be verticesof the original trajectory. Gudmundsson, van Kreveld, and Staals [9] presented an O ( n log n )time algorithm for the case k = 1. However, we note that there is a mistake in one of their6roofs, and hence their algorithm misses one of the possible scenarios. We correct thismistake, and using the insight gained, also solve the problem for k = 2. Figure 7: An optimal placementthat has no vertex on the bound-ary of the square.Gudmundsson, van Kreveld, and Staals state that thereexists an optimal placement of a unit square, i.e. one suchthat the square covers a longest 1-coverable subtrajectoryof T , and has a vertex of T on its boundary [9, Lemma 7].However, that is incorrect, as illustrated in Figure 7. Let p ( t ) be a parametrisation of the trajectory. Fix a corner c of the square and shift the square so that c follows p ( t ).Let q ( t ) be the point so that T [ p ( t ) , q ( t )] is the maximalsubtrajectory contained in the square, and let φ ( t ) be thelength of this subtrajectory. This function φ is piecewiselinear, with inflection points not only when a vertex of T lies on the boundary of the square, but also when p ( t ) or q ( t ) hits a corner of the square. The argument in [9] misses this last case. Instead, thecorrect characterization is: Lemma 8.
Given a trajectory T with vertices v , .., v n , there exists a square H covering alongest 1-coverable subtrajectory so that either: • there is a vertex v i of T on the boundary of H , or • there are two trajectory edges passing through opposite corners of H . We restate the full proof of this lemma in Appendix C. To compute a longest 1-coverablesubtrajectory we also have to consider this scenario. We use the existing algorithm to testall placements of the first type from Lemma 8 in O ( n log n ) time. Next, we briefly describehow we can also test all placements of the second type in O ( n log n ) time. Lemma 9.
Given a pair of non-parallel edges e i and e j of T , there is at most one unitsquare H such that the top left corner of H lies on e i , and the bottom right corner of H lieson e j . It follows that any pair of edges e i , e j of T generates at most a constant number ofadditional candidate placements that we have to consider. Let H ij denote this set. Next,we argue that there are only O ( n ) relevant pairs of edges that we have to consider.We define the reach of a vertex v i , denoted r ( v i ), as the vertex v j such that T [ v i , v j ]can be 1-covered, but T [ v i , v j +1 ] cannot. Let H i = H ( i − j denote the set of candidateplacements corresponding to v i and v j = r ( v i ). Analogously, we define the reverse reachrr ( v j ) of v j as the vertex v i such that T [ v i , v j ] can be 1-covered, but T [ v i − , v j ] cannot, andthe set H (cid:48) j = H ( i − j . Finally, let H = (cid:83) ni =1 H i ∪ H (cid:48) i be the set of placements contributedby all reach and reverse reach pairs. Observe that this set consists of O ( n ) placements, asall individual sets H i and H (cid:48) i have at most one element. Lemma 10.
Let p ∗ ∈ e i and q ∗ ∈ e j lie on edges of T , and let H be a unit square with p ∗ in one corner, and q ∗ in the opposite corner. We have that H ∈ H . Once we have the reach r ( v i ) and the reverse reach rr ( v i ) for every vertex v i we caneasily construct H in linear time (given a pair of edges e i , e j we can construct the unit7quares for which one corner lies on e i and the opposite corner lies on e j in constant time).We can use Tool 5 to test each candidate in O (log n ) time. So all that remains is to computethe reach of every vertex of T ; computing the reverse reach is analogous. Lemma 11.
We can compute r ( v i ) , for each vertex v i ∈ T , in O ( n log n ) time in total. Theorem 10.
Given a trajectory T with n vertices, there is an O ( n log n ) time algorithmto compute a longest 1-coverable subtrajectory of T . In this section we reuse some of the observations from Section 4.1 to develop an O ( nβ ( n ) log n )time algorithm for the k = 2 case. Here, β ( n ) = λ ( n ) /n , and λ s ( n ) is the length of aDavenport-Schinzel sequence of order s on n symbols.Our algorithm to compute a longest 2-coverable subtrajectory T [ p ∗ , q ∗ ] of T consists oftwo steps. In the first step we compute a set S of candidate starting points on T , so that p ∗ ∈ S . In the second step, we compute the longest 2-coverable subtrajectory T [ p, q ] foreach starting point p ∈ S , and report a longest such subtrajectory. With slight abuse/reuseof notation, for any point p ∈ S , we denote the endpoint q of this longest 2-coverablesubtrajectory T [ p, q ] by r ( p ). This generalizes our notion of reach from Section 4.1 toarbitrary points on T . We modify the data structure in Theorem 8, i.e. the data structure for answering whethera given subtrajectory is 2-coverable, to answer the reach queries. We do so by applyingparametric search to the query procedure. Note that applying a simple binary search willgive us only the edge containing r ( p ). Furthermore, even given this edge it is unclear howto find r ( p ) itself, as the squares may still shift, depending on the exact position of r ( p ). Lemma 12.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can be stored using O ( n log n ) space, so that given a query point p on T it can compute thereach r ( p ) of p in O (log n ) time. Corollary 1.
Given a trajectory T , and a set of m candidate starting points on T , we cancompute the longest 2-coverable subtrajectory that starts at one of those points in O ( n log n + m log n ) time. It remains only to construct a set S of candidate starting points with the property thatthe starting point of a longest 2-coverable subtrajectory is guaranteed to be in the set.Our construction consists of six types of starting points, which when grouped up into theirrespective types, we will call events . The six types of events are vertex events, reach events,bounding box events, bridge events, upper envelope events, and special configuration events.Figures 8, 9, and 10 illustrate these events, and show how a longest 2-coverable subtrajectorymay start at such an event. We then prove that it suffices to consider only these six typesof candidate starting points. Finally, we bound the number of events, and thus candidatestarting points, and describe how to compute them. Combining this with our result fromCorollary 1 gives us an efficient algorithm to compute a longest 2-coverable subtrajectory.8ote that in Definitions 2-7, for simplicity we define the events only in one of the fourcardinal directions. However, in our construction in Definition 8 we require all six eventsfor all four cardinal directions. Definition 2.
Given a trajectory T , p is a vertex event if p is a vertex of T . Definition 3.
Given a trajectory T , p is a reach event if r ( p ) is a vertex of T , and no point q < p satisfies r ( q ) = r ( p ) . Definition 4.
Given a trajectory T , p is a bounding box event if the topmost vertex of T within the subtrajectory T [ p, r ( p )] has the same y -coordinate as p . p pr ( p ) p Figure 8: A vertex event (left), a reach event (middle), and a bounding box event (right).
Definition 5.
Given a trajectory T , p is a bridge event if: • the point p is the leftmost point on T [ p, r ( p )] , and • the point p is one unit to the left of a point u ∈ T [ p, r ( p )] , and • the point u is one unit above the lowest vertex of T [ p, r ( p )] . Definition 6.
Given a trajectory T , p is an upper envelope event if: • the point p is the leftmost point on T [ p, r ( p )] , and • the point p is one unit to the left of a point u ∈ T [ p, r ( p )] , and • the point u is an intersection or vertex on the upper envelope of T [ p, r ( p )] . up p u Figure 9: Examples of a bridge event (left), and an upper envelope event box (right).9 efinition 7.
Given a trajectory T , p is a special configuration event if there is a coveringof squares H and H so that H contains the top-left corner of H , and either:1. point p is in the top-right corner of H and r ( p ) is in the bottom-left corner of H , or2. point p is in the top-left corner of H and the trajectory T passes through the bottom-right corner of H , or3. point p is in the top-left corner of H , r ( p ) is in the bottom-right corner of H , andthe trajectory T passes through the two intersections of H and H . p p p H H H H H H r ( p ) r ( p ) Figure 10: Examples of the three types of special configuration events.Using these definitions and their analogous versions in all four cardinal directions, wesubdivide the trajectory T to obtain a trajectory T that forms our set of candidate startingpoints. Definition 8.
Given a trajectory T , let T be a copy of T with these additional points addedto the set of vertices of T : • all the vertex, reach, bounding box, and bridge events of T for all four cardinal direc-tions.Next, let T be a copy of T with these additional points added to the set of vertices of T : • all the upper envelope events of T for all four cardinal directions.Finally, let T be a copy of T with these additional points added to the set of vertices of T : • all the special configuration events of T for all configurations of H and H . Next, we argue that the set of vertices of this trajectory T is a suitable set of candidatestarting points. Lemma 13.
The set T is guaranteed to contain the starting point of a longest coverablesubtrajectory of T . We now bound the number of candidate starting points.
Lemma 14.
Trajectory T has O ( nβ ( n )) vertices, and can be constructed in time O ( nβ ( n ) log n ) .More specifically, for each type of event, the number of such events and the time in whichwe can compute them is events computation timeVertex events O ( n ) O ( n ) Reach events O ( n ) O ( n log n ) Bounding box events O ( n ) O ( n log n ) Bridge events O ( n ) O ( n log n ) Upper envelope events O ( nβ ( n )) O ( nβ ( n ) log n ) Special configuration events O ( nβ ( n )) O ( nβ ( n ) log n ) .Proof. We briefly sketch the idea for only the upper envelope events. Refer to Appendix Efor the details, the proofs for the other events, and the description of the algorithms thatcompute these events.Consider the set V of vertices of T and intersections of T with itself, and observe thatevery point u ∈ V generates at most O (1) candidate starting points p that are upper-envelope events. However, there may be Θ( n ) such intersection points. We argue that notall of these intersection points generate valid starting points.Let p , .., p k be the upper envelope events of the trajectory, and let U = u , .., u k be theedge of T that contains the point u on T [ p, r ( p )] one unit to the right of p . We argue that U is a Davenport-Schinzel sequence of order 4 on n − k = O ( nβ ( n )). It follows that there are O ( nβ ( n )) upper envelope events.Since U is a Davenport-Schinzel sequence of order s = 4, it has no alternating (notnecessarily contiguous) subsequences of length s + 2 = 6. Our first step is to show that ifthe sequence of edges a, b, a occurs (not necessarily consecutively) then the starting pointscorresponding to the first two segments of the sequence must be x -monotone. Hence, an al-ternating sequence of edges of length six yields alternating, x -monotone sequence of startingpoints of length five. We then argue that this leads to a contradiction.By Lemma 14 we can compute m = O ( nβ ( n )) candidate starting times for a longest2-coverable subtrajectory of T in O ( nβ ( n ) log n ) time. Using Corollary 1 we can thuscompute this subtrajectory in O ( n log n + m log n ) = O ( nβ ( n ) log n ) time. Theorem 11.
Given a trajectory T with n vertices, there is an O ( nβ ( n ) log n ) timealgorithm to compute a longest 2-coverable subtrajectory of T . References [1] Pankaj K. Agarwal and Cecilia Magdalena Procopiuc. Exact and approximation algo-rithms for clustering.
Algorithmica , 33(2):201–226, 2002.[2] Sergey Bereg, Binay Bhattacharya, Sandip Das, Tsunehiko Kameda, Priya Ran-jan [Sinha Mahapatra], and Zhao Song. Optimizing squares covering a set of points.
Theoretical Computer Science , 729:68–83, 2018.[3] Bernard Chazelle and Leonidas J. Guibas. Fractional cascading: I. A data structuringtechnique.
Algorithmica , 1(2):133–162, 1986.[4] Maria Luisa Damiani, Hamza Issa, and Francesca Cagnacci. Extracting stay regionswith uncertain boundaries from GPS trajectories: A case study in animal ecology. In
Proceedings of the 22nd ACM SIGSPATIAL International Conference on Advances inGeographic Information Systems , pages 253–262, 2014.115] Mark de Berg, Otfried Cheong, Marc J. van Kreveld, and Mark H. Overmars.
Compu-tational geometry: algorithms and applications, 3rd Edition . Springer, 2008.[6] Zvi Drezner. On the rectangular p -center problem. Naval Research Logistics (NRL) ,34(2):229–234, 1987.[7] Robert J. Fowler, Mike Paterson, and Steven L. Tanimoto. Optimal packing andcovering in the plane are NP-complete.
Information Processing Letters , 12(3):133–137,1981.[8] Joachim Gudmundsson and Michael Horton. Spatio-temporal analysis of team sports.
ACM Computing Surveys (CSUR) , 50(2):22, 2017.[9] Joachim Gudmundsson, Marc van Kreveld, and Frank Staals. Algorithms for hotspotcomputation on trajectory data. In
Proceedings of the 21st ACM SIGSPATIAL Inter-national Conference on Advances in Geographic Information Systems , pages 134–143,2013.[10] John Hershberger. Finding the upper envelope of n line segments in O ( n log n ) time. Information Processing Letters , 33(4):169–174, 1989.[11] Michael Hoffmann. Covering polygons with few rectangles. In
Abstracts 17th EuropeanWorkshop Computational Geometry , pages 39–42, 2001.[12] R. Z. Hwang, Richard C. T. Lee, and R. C. Chang. The slab dividing approach to solvethe Euclidean p -center problem. Algorithmica , 9(1):1–22, 1993.[13] Nimrod Megiddo. Applying parallel computation algorithms in the design of serialalgorithms. In , pages 399–408. IEEE, 1981.[14] Nimrod Megiddo and Kenneth J. Supowit. On the complexity of some common geo-metric location problems.
SIAM Journal of Computing , 13(1):182–196, 1984.[15] Doron Nussbaum. Rectilinear p -piercing problems. In Proceedings of the 1997 Inter-national Symposium on Symbolic and Algebraic Computation, ISSAC , pages 316–323,1997.[16] S. Das P.R. Sinha Mahapatra, P.P. Goswami. Maximal covering by two isothetic unitsquares. In
Canadian Conference on Computational Geometry , pages 103–106, 2008.[17] Sanjib Sadhu, Sasanka Roy, Subhas C. Nandy, and Suchismita Roy. Linear time al-gorithm to cover and hit a set of line segments optimally by two axis-parallel squares.
Theoretical Computer Science , 769:63–74, 2019.[18] Michael Segal. On piercing sets of axis-parallel rectangles and rings.
InternationalJournal of Computional Geometry and Applications , 9(3):219–234, 1999.[19] Micha Sharir and Pankaj K. Agarwal.
Davenport-Schinzel sequences and their geometricapplications . Cambridge University Press, 1995.[20] Micha Sharir and Emo Welzl. Rectilinear and polygonal p -piercing and p -center prob-lems. In Proceedings of the 12th Annual Symposium on Computational Geometry , pages122–132, 1996. 1221] Andreas Stohl. Computation, accuracy and applications of trajectories—A review andbibliography.
Developments in Environmental Science , 1:615–654, 2002.13
Appendix to Section 2
A.1 Proof of Lemma 2
Lemma 2.
A set of segments is 3-coverable if and only if there is a covering with a squarein a corner of the bounding box of the set of segments.
Figure 11: A square of the 3-covering is in a corner of the bounding box.
Proof.
Any 3-covering touches all four sides of the bounding box, in fact, one square in the3-covering must touch at least two sides. If the two sides are opposite then the boundingbox has width less than or equal to one and there is a straightforward one-dimensionalalgorithm. Otherwise, without loss of generality let the adjacent sides be the top and leftsides. If the square is not already in the topleft corner of the bounding box, move thesquare to the corner position shown in Figure 11. The new square covers more than theinitial position, so the modified positions is 3-covering with a square in a corner.
A.2 Proof of Lemma 4
Lemma 4.
Given the position of L , if three additional squares can be placed to cover theremaining subsegments, then we can do so by placing T in the top-left corner of the boundingbox of the remaining subsegments.Proof. Recall that T is the square touching the top boundary of the bounding box, andthat we assumed without loss of generality that the left to right order of the squares are L, T, B, R . Hence, of the remaining squares, T is the leftmost.Consider the bounding box of the remaining subsegments, in particular, the left boundaryof said bounding box. This left boundary is the vertical dashed line shown in Figure 12. Bydefinition, there exists a left endpoint of a remaining subsegment that lies on this verticaldashed line. Suppose that the left side of T is to the right of this vertical dashed line: thenthe squares B and R would be even further right than T , and no square would cover this leftendpoint of a remaining subsegment. Hence, if a covering exists, the left side of T cannotbe to the right of the vertical dashed line.Suppose that there exists a covering where the left side of T is to the left of the verticaldashed line. Then we can improve the position of T so that its left side is aligned with thevertical dashed line. If the initial position of T was a covering, then the new position would14 L Figure 12: The best position for T is in the top left corner of the bounding box of theremaining subsegments.also be a covering, since the new position covers more of the area of inside the boundingbox of the remaining subsegments.Therefore, if three additional squares can be placed to cover the remaining subsegments,then it can be done by placing the left side of T in line with the vertical dashed line. Inother words, we can do so by placing T in the top left corner of the bounding box of theremaining subsegments. A.3 Proof of Lemma 5
Lemma 5.
The variable x T as a function of variable y L is a piecewise linear function andcan be computed in O ( n log n ) time. y L A CB
Figure 13: The regions A , B and C areabove, below, and to the left of the square L . y L x T Figure 14: The skyline (orange) is theleftmost point of region A as y L increases. Proof.
By Lemma 4, we know that x T is the x -coordinate of the leftmost uncovered pointafter placing L . Hence, we divide the uncovered region inside the bounding box into threesubregions: the region A above L , the region B below L and the region C to the right of L . See Figure 13. By definition, all these regions are uncovered. We compute the leftmostpoints of A , B , and C separately, and then return the overall leftmost point as the value of x T .As y L increases, the leftmost point of A moves monotonically to the right. This polygonalcurve is shown in Figure 14, and we call this curve the skyline of the set of segments.15n Appendix A.4 we show that, given n line segments, the skyline is a piecewise linearfunction and can be computed in O ( n log n ) time. The key idea is that we reduce theskyline computation to an upper envelope computation.As y L increases, the leftmost point of B moves monotonically to the left. This polygonalcurve is the skyline of the set of segments except that the skyline is taken in the downwarddirection instead. Finally, as y L increases, the leftmost point of C is a constant and can becomputed in linear time.Putting this altogether, the leftmost point of A , B , and C are all piecewise linear func-tions with complexity O ( n ), and all these functions can be computed in O ( n log n ) time.Hence, the value of x T is the minimum of these functions, so is piecewise linear and can becomputed in O ( n log n ) time. A.4 Algorithm for computing the skyline
Definition 9.
Given a set of segments S , for any horizontal line (cid:96) , define f ( (cid:96) ) to be theleftmost point of S on or above the line (cid:96) . Then as (cid:96) varies, f ( (cid:96) ) is the skyline of S . Lemma 15.
The skyline of a set of n segments is a piecewise linear function with O ( nα ( n )) pieces and can be computed in O ( n log n ) time, where α ( n ) is the inverse Ackermann func-tion.Proof. We first compute the skyline of each individual segments, then show how to combineseparate skylines into a single skyline for all the segments. For a single segment we havetwo cases: either the segment has positive or negative gradient.Figure 15: Skyline of a line segment withpositive gradient. Figure 16: Skyline of a line segment withnegative gradient.If the segment has positive gradient, then we can deduce from Definition 9 that its skylineconsists of three pieces. The first piece is a vertical line through the segments left endpoint.The second piece is simply the original segment. The third piece is a horizontal segmentthrough the right endpoint. See Figure 15. If the segment has negative gradient, then theskyline has two pieces. The first piece is a vertical line through the top-left endpoint. Thesecond piece is a horizontal line through the top-left endpoint. See Figure 16.Next, we show that the skyline for individual segments can be combined into an overallskyline for all the segments. In particular, we claim that the overall skyline is the “leftwards”envelope of the individual skylines. The leftwards envelope is simply the upper envelopeexcept in the leftwards cardinal direction rather than the upwards direction. The reason is16hat for any (cid:96) , the function f ( (cid:96) ) takes the value of the leftmost intersection of the individualskylines with (cid:96) , which by definition is the leftwards envelope. See Figure 17. From the figureit seems that the distinction between the upper and leftwards envelope do not matter forcomputing the skyline. The authors hypothesise that there is a simple proof as to why thetwo are equivalent in this case.Figure 17: The overall skyline is the “leftwards” envelope of the individual skylines.Given n segments, we can compute the individual skylines in O ( n ) time. Together, theindividual skylines consist of at most 3 n segments. The upper envelope of the individualskylines has at most O ( nα ( n )) pieces and can be computed in O ( n log n ) time [19]. A.5 Proof of Lemma 6
Lemma 6.
The variable x B as a function of variable y L is a piecewise linear function andcan be computed in O ( n log n ) time.Proof. For an analogous reason to Lemma 4, we can place B in the bottom-right cornerof the remaining segments after placing L and T . Therefore, x B is the x -coordinate of theleftmost uncovered point after placing L and T . Divide the remaining region into threesubregions: B below L , D to the right of T , and C to the right of L and below T . SeeFigure 18. We compute the leftmost points of B , D , and C separately, and then return theoverall leftmost point to be the value of x B . B ( S ) y L x T L T DC B Figure 18: The regions B , D and C as defined by L and T .As y L increases, the leftmost point of B moves monotonically to the left, and follows the17kyline of the set of segments, except that the skyline is taken in the downwards direction.See Appendix A.4 for the formal definition of a skyline. Hence, the leftmost point of B is apiecewise linear function in terms of y L and can be computed in O ( n log n ) time.As y L increases, the position of square T , given by the variable x T moves monotonicallyto the right, and follows a skyline of the segments. We have shown in Lemma 5 that x T is apiecewise linear function in terms of y L and can be computed in O ( n log n ) time. Similarly,the leftmost point of D is a piecewise linear function in terms of the position of T and canbe computed in O ( n log n ) time. We compose the leftmost point of D as a piecewise linearfunction of x T , and x T as a piecewise linear function of y L . By Appendix A.4, each of thesefunctions are monotonically increasing functions with complexity O ( nα ( n )). Composingtwo monotonic, piecewise linear functions requires a single simultaneous sweep of the twofunctions, which takes O ( nα ( n )) time. Hence, the leftmost point of D is a piecewise linearfunction in terms of y L and can be computed in O ( n log n ) time.As y L increases, the region C remains constant, so the leftmost point of C remainsconstant. This point can be computed in O ( n ) time.Putting this altogether, each of the leftmost points of B , D and C are piecewise linearfunctions in terms of y L and can be computed in O ( n log n ) time. Hence, their minimum x B is piecewise linear and can be computed in O ( n log n ) time. A.6 Proof of Lemma 7
Lemma 7.
The variables x R , x R , y R , y R as functions of variable y L are piecewiselinear functions and can be computed in O ( n log n ) time.Proof. We will show that y R as a function of y L is a piecewise linear function and can becomputed in O ( n log n ) time. The other variables follow analogously.Divide the region to the right of L , T and B into three subregions: D is to the right of L and above B , E to the right of B , and C below D and above B , if it exists. Note that C only exists in squares where the height of the bounding box is greater than two. Otherwise,only the regions D and E exist, as shown in Figure 19. We compute the topmost points of D , E and C separately, then return their overall topmost point to be the value of y R . B ( S ) y L x T x B L T BD ∪ E ∪ C Figure 19: The regions D ∪ E ∪ C as defined by L , T and B .As y L increases, the position of square T given by the variable x T moves monotonicallyto the right and follows the skyline of the segments. Similarly, as x T moves monotonicallyto the right, the topmost point of D moves monotonically to the right. We have shown in18ppendix A.4 that each of these monotonic functions are piecewise linear, have complexity O ( nα ( n )) and can be computed in O ( n log n ) time. Computing their composition of mono-tonic, piecewise linear functions requires a single simultaneous sweep of the two functions,which takes O ( nα ( n )). Hence, the overall function is piecewise linear and can be computedin O ( n log n ).As y L increases, the topmost point of E is similarly a composition of two skyline func-tions, which is piecewise linear and can be computed in O ( n log n ).Finally, as y L increases, the topmost point of C (if it exists) is constant and can becomputed in O ( n ) time.Putting this altogether, each of the leftmost points of D , E and C are piecewise linearfunctions in terms of y L and can be computed in O ( n log n ) time. Hence, their minimum y R is a piecewise linear function and can be computed in O ( n log n ) time.19 Appendix to Section 3
B.1 Proof of Tool 5
Tool 5.
A bounding box data structure that preprocesses a trajectory in O ( n ) time, so thatgiven a query subtrajectory, it returns the subtrajectory’s bounding box in O (log n ) time. Figure 20: The subtrajectory data structure that returns the bounding box.
Proof.
We construct four data structures, one for each cardinal direction. For the upwardsdirection, the bounding box data structure reduces to finding the vertex or endpoint inthe subtrajectory with the largest y -coordinate. We call the data structure for the upwardboundary of the bounding box a topmost-vertex data structure.The topmost-vertex data structure is a binary tree over the segments of the trajectorythe trajectory. Associated with each leaf node is a segment of the trajectory. Associatedwith each internal node are all its descendants, in particular, all the segments at leaf nodeswhich are descendants of the internal node. The binary tree is constructed in a way that thesegments associated with an internal node is a contiguous subtrajectory of the trajectory.This contiguous subtrajectory associated with an internal node is also known as a canonicalsubset of the trajectory. By construction, every subtrajectory the subtrajectory can bedecomposed into a union of O (log n ) canonical subsets.The data structure for the topmost-vertex is constructed in a bottom-up fashion. Webuild the topmost-vertex data structure for each leaf node. Then for each canonical subsetwe compute its topmost-vertex by taking the maximum of its left and right child. In totalthis takes linear time and space. In this way, we have a topmost-vertex data structure foreach internal node of the binary tree.Given a query subtrajectory, we decompose the subtrajectory into canonical subsets in O (log n ) time. At each internal node associated with each of the canonical subsets, we querythe topmost-vertex data structure at that internal vertex. Each query takes constant time,so computing all the topmost vertices takes O (log n ) time. Taking the maximum of thetopmost vertices also takes O (log n ) time, so the total query time is O (log n ). B.2 Proof of Tool 6
Tool 6.
An upper envelope data structure that preprocesses a trajectory in O ( n log n ) time, so that given a query subtrajectory and a query vertical line, it returns the highestintersection between the subtrajectory and the vertical line (if one exists) in O (log n ) time. Proof.
We use an approach similar to Appendix B.1. We build a binary search tree oversegments of T , and associate with each internal node the subset of all its descendants. Wecall this the canonical subset associated with this internal node. By construction, everysubtrajectory can be decomposed into a union of O (log n ) canonical subsets.At each internal node, we build an upper envelope data structure over the segments inthe canonical subset associated with that internal node. We build the upper envelope datastructure at each internal node in a bottom up fashion, starting from the leaf nodes. Weadapt the divide-and-conquery approach of Hershberger [10] to merge the upper envelopeof the left child and the right child to form the upper envelope of the parent. The totalconstruction time for the upper envelopes of all canonical subsets is O ( n log n ). For everycanonical subset, storing the upper envelope allows us to answer an upper envelope queryat any x -coordinate in O (log n ) time.Given a query subtrajectory and x -coordinate, we can naively answer the upper envelopequery by taking two steps. First, we decompose the subtrajectory into canonical subsets,and answer the upper envelope query at the given x -coordinate, for all O (log n ) canonicalsubsets. Second, we take the maximum of each of these upper envelope queries to obtainthe true upper envelope at the given x -coordinate. The overall query time for this approachwould be O (log n ) time. A standard application of fractional cascading [3] reduces the totalquery time to O (log n ). B.3 Proof of Tool 7
Tool 7.
A highest vertex data structure that preprocesses a trajectory in O ( n log n ) time,so that given a query subtrajectory and a query axis-parallel rectangle, it returns the highestvertex of the subtrajectory inside the rectangle (if one exists) in O (log n ) time.Proof. We use a similar approach to Appendix B.1 and B.2. We build a binary search treeover the vertices of T , so that associated with each leaf node is a vertex of T , and associatedwith each internal node is the canonical subset of all its descendants. Every subtrajectory,or rather, the set of vertices inside any subtrajectroy, can be decomposed into a union of O (log n ) canonical subsets.At each internal node, we build a highest vertex data structure over the vertices in itscanonical subset. To build the highest vertex data structure, we simply adapt the orthogonal21igure 22: The subtrajectory data structure that returns the highest subtrajectory vertexin a query rectangle.range searching data structure. Instead of counting the number of vertices in an orthogonalrange, we have the orthogonal range searching data structure return the highest vertexinside the orthogonal range, if one exists. The orthogonal range searching data structurecan be build in O ( n log n ) time, and orthogonal range queries can be answered in O (log n )time [5]. Finally, we decompose the subtrajectory query into canonical subsets and queryeach canonical subset. The overall query time is O (log n ). B.4 Proof of Theorem 8
Tool 8.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can bestored using O ( n log n ) space, so that deciding if a query subtrajectory T [ a, b ] is 2-coverabletakes O (log n ) time.Proof. Our construction procedure is to build Tools 5 and 6. We build four copies of Tool 6,one for each cardinal direction. Our query procedure consists of two steps. The first stepis to narrow down the position of the two squares to one of two configurations. The secondstep is to check whether a configuration covers the subtrajectory.In the first step we use Tool 5 to compute the bounding box of the subtrajectory. ByLemma 1 we only need to check squares that are in opposite corners of the bounding box.In the second step we start by checking if the starting point of the subtrajectory is insidethe union of the two squares. Then it remains only to check whether the subtrajectory everpasses through the boundary of the union. Consider the complement of the union, shown inFigure 23. For each boundary piece of the complement, we check whether the subtrajectorypasses through that piece by querying Tool 6 on the line through the piece. The query willreturn whether the subtrajectory intersects this piece, as shown in Figure 23. We repeatthis procedure for every boundary piece of the complement.The construction procedure takes O ( n log n ) time, and both steps of the query proceduretake O (log n ) time. B.5 Proof of Theorem 9
Theorem 9.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can be stored using O ( n log n ) space, so that deciding if a query subtrajectory T [ a, b ] is3-coverable takes O (log n ) time. Proof.
Our construction procedure is to build Tools 5, 6 and 7. We build four copies of eachof Tools 6 and 7, one for each of the four cardinal directions. Our query procedure consistsof three steps. The first step is to place the first of the three squares in a constant number ofconfigurations. The second step is to place the two remaining squares in a constant numberof configurations. The third step is to check if the configuration of three squares covers thesubtrajectory.In the first step, we use Tool 5 to compute the bounding box of the subtrajectory. ByLemma 2, we can place the first square in one of the four corners of the bounding box.In the second step, we compute the bounding box of the uncovered segments after placingthe first box. By Lemma 1, the final two squares must be in opposite corners of the boundingbox of the uncovered subsegments. See Figure 24.Figure 24: The two choices for the last two squares, as given by their bounding box (thingreen).Suppose we placed a square in the top-left corner in the first step. We have two cases forthe topmost uncovered point: it is either a vertex of the subtrajectory, or the intersectionof a subtrajectory edge with the left or bottom side of the top-left square. The first casecan handled by querying Tool 7 on the region outside the first square. The second case canbe handled by querying Tool 6 along the right or bottom boundaries of the top-left square.Taking the highest of these points yields the topmost uncovered point. Similarly we cancompute the bottommost, leftmost and rightmost uncovered point, giving us the boundingbox of the uncovered segments. With this bounding box we can compute two configurationsper placement in the first step, as shown in Figure 24.For the third step, we check if a configuration of three squares covers the subtrajectory.23he approach is similar to the two square case. First we check if the starting point of thesubtrajectory is inside the union of the three squares. Then we check if the subtrajectoryremains inside the union by checking if the subtrajectory ever passes through the boundaryof the union. We use a combination of Tools 6 and 7 to achieve this. For each boundary pieceof the union, we query one of the four copies of Tools 6 to compute the highest intersectionof the subtrajectory with a vertical line passing through the boundary piece. For example,if the boundary piece is the left side of a square, then we take either the highest intersectionof the subtrajectory through the vertical line through the left side of the square, or thelowest intersection of the subtrajectory through the left side of the square. We choose thehighest intersection data structure in the case that the boundary piece can be extendedupwards indefinitely without intersecting the union again, or the lowest intersection datastructure in the case where the boundary piece can be extended downwards indefinitelywithout intersecting the union again. See Figure 25. H ∪ H ∪ H B ( S ) B ( S ) H ∪ H ∪ H Figure 25: The boundary pieces of the union and the cardinal directions we can extend theboundary piece indefinitely.We notice in our two possible configurations, every boundary piece can be extendedindefinitely in one of the four cardinal directions, except one such boundary piece. Theboundary piece in question is the small piece in the middle of the “U” shape in the leftconfiguration of Figure 25. For this one boundary piece, where none of the four copies ofTool 6 can be used to check if there is a subtrajectory that intersects that boundary piece.Instead, we use a different approach: we first check that the subtrajectory does not exit theunion through any other boundary piece. Then, if the subtrajectory does exit the union,it must do so through the one small piece in the middle of the “U” shape. There are twocases. Either the subtrajectory exits through the small piece and never comes back into theunion, in which case we can check whether the endpoint of the subtrajectory is inside theunion or not. Otherwise, the subtrajectory does come back into the union, but it cannotintersect any of the other boundary pieces, so it must exit and re-enter through the samepiece. Therefore, there must be a turning point of the subtrajectory outside the union, inwhich case we can use Tool 7 to decide if there are any vertices of the trajectory outside theunion. This completes the check for whether our configuration covers the subtrajectory.The construction procedure takes O ( n log n ) time, and the query time is dominated byTool 7, which takes O (log n ) time. 24 Appendix to Section 4
C.1 Proof of Lemma 8
Lemma 8.
Given a trajectory T with vertices v , .., v n , there exists a square H covering alongest 1-coverable subtrajectory so that either: • there is a vertex v i of T on the boundary of H , • there are two trajectory edges passing through opposite corners of H .Proof. Figure 7 shows an example where the longest 1-coverable subtrajectory has two tra-jectory edges passing through the opposite corners of its square covering. In particular, theredoes not exist a square covering for a longest 1-coverable subtrajectory with a trajectoryvertex on the boundary of the square covering. This contradicts Lemma 7 of [9].Suppose we have a longest 1-coverable subtrajectory and a unit-sized, axis-parallel squarethat covers it. We call the side of a square empty if no part of the trajectory intersects it. Wefirst show that, if the square has at least one empty side, then we can modify the position ofthe square so that it still covers the longest 1-coverable subtrajectory, but there is a vertexon the boundary of that square.Without loss of generality assume that the left side of the square is empty. Shift thesquare to the right by an arbitrarily small amount. Since the left side of the square wasempty to begin with, there must exist a small amount that we could have moved so that nopart of the subtrajectory passes through the left boundary and exits the square. Therefore,there is an arbitrarily thin region to the left of the square which we used to cover, but nolonger cover, whereas there is an arbitrarily thin region to the right of the square whichwe now cover but did not used to cover. Since the subtrajectory is a longest 1-coverablesubtrajectory, we could not have lengthened our subtrajectory by including the thin regionto the right. In other words, the right side of the square (as well as the left side of thesquare) are now empty.Suppose in addition to the left and right sides, the top side is also empty. Then we canshift the square downwards until there is a vertex on the top boundary, and we are done.Similarly, we would be done if the bottom side were also empty. The only remaining case isif the top and bottom sides of the square have an edge passing through it.Consider the pair of edges passing through the top and bottom sides. There are threecases. The first case is if the gradients of these two edges have opposite sign, say positiveon the top edge and negative on the bottom edge. Then we can shift the square to theleft until there is a vertex on the left boundary. The second case is if the gradients of thepair of edges have the same sign but different magnitudes. Then we can shift the squaretowards the edge that has a smaller magnitude gradient and we will gain more edge on thisside than the other side, contradicting the fact that we started with the longest 1-coverablesutbrajectory. The third and final case is if the gradients of the pair of edges have the samesign and the same magnitude. We shift the square parallel to this pair of edges, and thiswill maintain optimality until a vertex hits one of the four sides of the square.Hence if our square covering for a longest 1-coverable subtrajectory has at least oneempty side, then we can construct a different square covering for a possibly different longest1-coverable subtrajectory, so that there is a trajectory vertex on the boundary of the squarecovering. The only remaining case is if our square covering has no empty sides. If the squarecovering has no empty sides but has a vertex on its boundary, we are again done. So theonly remaining case is if the square covering has no empty sides and no vertices on the25oundary of the square. The only way for there to be four non-empty sides without verticesis if two edges of the trajectory pass through opposite corners of the square, as shown inFigure 7. This completes the proof.
C.2 Proof of Observation 9
Observation 9.
Given a pair of non-parallel edges e i and e j of T , there is at most oneunit square H such that the top left corner of H lies on e i , and the bottom right corner of H lies on e j .Proof. Consider shifting a point p along e i or e j . The function g i ( p x ) = p y (respectively g j )expressing the y -coordinate of p as a function of its x -coordinate is linear. Let p be the topleftcorner of H , and shift it along e . Since g i and g j are linear, h ( p x ) = g i ( p x ) − g j ( p x + 1)is also linear, and thus there is only one value p x such that h ( p x ) = 1. The observationfollows. C.3 Proof of Lemma 10
Lemma 10.
Let p ∗ ∈ e i and q ∗ ∈ e j lie on edges of T , and let H be a unit square with p ∗ in one corner, and q ∗ in the opposite corner. We have that H ∈ H .Proof. Observe that vertices v i +1 and v j are inside H whereas v i and v j +1 are outside of H .See Figure 26. We now distinguish between two cases, depending on whether v j is reachablefrom v i or not. Hv i v i +1 v j v j +1 Figure 26: An optimal hotspot H .If v j is reachable from v i then v j +1 is not (otherwise T [ v i , v j +1 ] ⊃ T [ p ∗ , q ∗ ] is 1-coverable,and thus T [ p ∗ , q ∗ ] is not a longest 1-coverable subtrajectory). Hence, v j = r ( v i ) is the reachof v i , and thus H ∈ H i ⊆ H .If v j is not reachable from v i , then T [ v i , v j ] cannot be 1-covered. However, since v i +1 and v j are contained in H the subtrajectory T [ v i +1 , v j ] can be 1-covered. It follows that v i +1 is the reverse reach of v j , and thus H ∈ H (cid:48) j ⊆ H . C.4 Proof of Lemma 11
Lemma 11.
We can compute r ( v i ) , for each vertex v i ∈ T , in O ( n log n ) time in total. roof. We can compute the reach r ( v i ) for each vertex in O ( n log n ) time using a slidingwindow based approach. For v we just naively test the subtrajectories T [ v , v j ], startingwith j = 1 until we find a T [ v , v j +1 ] that we can no longer cover. Hence r ( v ) = v j . Tocompute the reach of v i +1 , we now simply continue this procedure starting with v j = r ( v i ).In total this requires O ( n ) calls to Tool 5, which take O (log n ) time each. It follows that wecan find a longest 1-coverable subtrajectory in O ( n log n ) time. C.5 Proof of Lemma 12
Lemma 12.
Let T be a trajectory with n vertices. After O ( n log n ) preprocessing time, T can be stored using O ( n log n ) space, so that given a query point p on T it can compute thereach r ( p ) of p in O (log n ) time.Proof. We would like to compute the maximum value q ∈ [0 ,
1] so that T [ p, q ] is 2-coverable.The decision version of this optimisation problem is to decide whether a given subtrajectory T [ p, q ] is 2-coverable. This decision version is monotone since for any q (cid:48) > q , the sub-trajectory T [ p, q (cid:48) ] contains the subtrajectory T [ p, q ]. After O ( n log n ) preprocessing timeTheorem 8 gives us a comparison-based algorithm, the query procedure, that solves thedecision problem in O (log n ) time. The sequential version of parametric search [13] statesthat if T is the running time of the sequential algorithm, the optimisation algorithm takes O ( T ) time. In our case, the reach can be answered in O (log n ) time as required.27 Proof of Lemma 13
In this Section we prove Lemma 13, which states that:
Lemma 13.
Given a trajectory T and the set of starting points T of T , the starting pointof a longest coverable subtrajectory is guaranteed to be a vertex of T . Recall the definitions of T , T , and T from Definition 8: Definition 8.
Given a trajectory T , let T be a copy of T with these additional pointsadded to the set of vertices of T : • all the vertex, reach, bounding box, and bridge events of T .Next, let T be a copy of T with these additional points added to the set of vertices of T : • all the upper envelope events of T .Finally, let T be a copy of T with these additional points added to the set of vertices of T : • all the special configuration events of T . We notice in Lemma 13 that we guarantee that the starting point of a longest coverablesubtrajectory is in the set of vertices of T . The statement of “a” longest coverable subtra-jectory is intentional here, as they many be multiple longest coverable subtrajectories. Wehandle multiple longest coverable subtrajectories in the following way. Definition 10.
Given a trajectory T , if there is a unique longest coverable subtrajectoryof T , then we say that this subtrajectory is optimal. If there are multiple longest coverablesubtrajectories, then we say that only the earliest of these is optimal. Given this definition of the optimal subtrajectory, which is now well defined even whenthere are multiple longest coverable subtrajectories. Lemma 13 now follows directly fromthe following result:
Lemma 16.
Given a trajectory T and the set of starting points T of T , the starting pointof the optimal subtrajectory is guaranteed to be a vertex of T . We now focus on proving Lemma 16. First, in Appendix D.1, we give some usefuldefinitions that will be used for the remainder of Appendix D, as well as for several of theproofs of the bounds on functions f ( n ) and g ( n ).Next, we define p to be the starting point of the optimal trajectory of T . If p was avertex of T , then clearly p is a vertex of T , which would satisfy Lemma 16. Hence, we canassume that p is not a vertex if T .Then, we prove a series of lemmas for the point p , with each lemma building from theprevious one. In Appendix D.2, we prove a relationship between the starting point p , theending point r ( p ), and a newly defined set of points called bridging points. We call thislemma the bridging lemma. In Appendix D.3 we show that if p is not a vertex of T , then p must be in a corner of one of the squares that cover T [ p, q ]. We call this lemma thecorner lemma. In Appendix D.4, we show that if p is not a vertex of T , then p is a specialconfiguration event. This shows that the starting point p of the optimal trajectory must be avertex of T . Finally, in Appendix D.5, we summarise and complete the proof of Lemma 16. D.1 Preliminaries for Appendix D
Recall that we defined p to be a starting point of the optimal trajectory of T . We assumedwithout loss of generality that p is not a vertex of T . We prove three properties of thetrajectory T . Each property in turn gives us some information about p , which we willbecome useful later in Appendix D.2, D.3 and D.4.28 roperty 1. Between any two consecutive vertices s i and s i +1 of T , the trajectory T isstraight segment.Proof. There are no vertices of T between s i and s i +1 , otherwise they would not be consec-utive vertices. Therefore, it must be straight. Property 2.
Let s i and s i +1 be consecutive vertices of T . For all points p ∈ [ s i , s i +1 ] ,their set of reaches { r ( p ) : p ∈ [ s i , s i +1 ] } is a straight segment.Proof. Suppose there were a vertex v in the set { r ( p ) : p ∈ [ s i , s i +1 ] } . Then the point p such that r ( p ) = v would be a reach event, which would contradict that fact that s i and s i +1 are consecutive vertices of T . Therefore, there are no vertices in { r ( p ) : p ∈ [ s i , s i +1 ] } so it must be straight. Property 3.
Let s i and s i +1 be consecutive vertices of T . For all points p ∈ [ s i , s i +1 ] , theset of points { u ( p ) : p ∈ [ s i , s i +1 ] } is a straight segment, where u ( p ) is the point on the upperenvelope of T [ p, r ( p )] that is one unit to the right of p .Proof. Suppose there were either a vertex of an intersection point u in the set { u ( p ) : p ∈ [ s i , s i +1 ] } . Then the point p so that u ( p ) = u would be an upper envelope event, whichwould contradict the fact that s i and s i +1 are consecutive vertices of T . Therefore, thereare no vertices in { u ( p ) : p ∈ [ s i , s i +1 ] } so it must be straight.Next we define bridging points, which are closely related to but not exactly the same asbridge events in Definition 8. Definition 11.
Given a point p , a point x is said to be a bridging point for point p if thereexists covering H ∪ H of T [ p, r ( p )] so that: • The point x lies on the boundary of both H and H , and • The point x lies on the subtrajectory T [ p, r ( p )] , and • The point x is on a side opposite to a side which contains p . H xp H Figure 27: An example of a bridging point x for the starting point p .See Figure 27 as an example. The bridging point x by definition will either be on boththe upper and right envelopes of the subtrajectory, or on both the lower and left envelopesof the subtrajectory. It is also one unit away from the starting point p in x -coordinate.The intuition behind bridging points is as follows. Suppose that the bridging point x were avertex of the trajectory T . The properties of x and p would immediately imply that p would29e an upper envelope event for the vertex x . Although the bridging point x is itself not astarting point of the algorithm, it can help us locate other starting points. We formalisethis relationship between the starting point and the bridging point in a lemma called thebridging lemma. Section D.2 will be dedicated to stating and proving the bridging lemma. D.2 The bridging lemma
We first define the terms p -side, b -side and q -side, which will be used to describe each of thefour boundary sides of the squares H and H . Recall that the squares H and H are thetwo squares that cover the optimal subtrajectory. Definition 12.
Let T [ p, q ] be a trajectory and let H ∪ H be a covering of T [ p, q ] . Thenany side of squares H and H that contains the point p is called a p -side, any side thatcontains the point q is called a q -side, and any side that contains a bridging point is calleda b -side. Now we can state the bridging lemma.
Lemma 17.
Suppose that T [ p, q ] is optimal and that p is not a vertex of T . Then thereexists a covering H ∪ H of the subtrajectory T [ p, q ] such that:1. Any side opposite a p -side is either a b -side or a q -side.2. Any side opposite a b -side is either a p -side or a q -side.Proof. We consider two cases. In the first case, there exists a covering H ∪ H where p isnot in one of the corners of H or H . In the second case, all coverings H ∪ H have p ina corner of H or H . Case 1: p is not in a corner. Consider the case that p lies on the left or right side of H . All other cases are symmetric. We consider when p is on the left side of H . It is easyto verify that the same argument works when p is on the right side H .If left side of H is a p -side, the statement of the bridging lemma requires us to provethat the right side of H is either a b -side or a q -side. Since p is not a vertex of T , it liesbetween two consecutive vertices e i and e i +1 of T , as shown in Figure 28. By Property 1 of T , the segment e i e i +1 is straight. Consider the situation if we moved H to the left by anarbitrarily small amount. We would cover additional length of e i e i +1 on the left side of H ,and since T [ p, q ] is optimal, we must have lost some edge on the right side of H . Hence,there must be a point on T [ p, q ] on the right edge of H which is lost even as we move leftby an arbitrarily small amount. pe i e i +1 pe i e i +1 pe i e i +1 v q H H H Figure 28: Moving H to the left in the case when p is on its left side.30here are three cases for what type of point we lost when moving the right edge of H left by an arbitrarily small amount, as shown in Figure 28. The point we lost must lie on the(blue) dashed segment since that is the only part of the right edge that becomes uncoveredwhen we move H left. The first case is if the point on the dashed segment is a vertex of thetrajectory. Refer to the leftmost diagram in Figure 28. By Definition 6, this would make p an upper envelope event for v , which would mean that p is a vertex of T , so the first caseyields a contradiction.The second case is if the point on the dashed segment is not a vertex and that T continuesto the right of H in such a way as to leave the covering H ∪H . Refer to the middle diagramin Figure 28. This the point on the dashed segment is the point q , in which case the rightside of H is a q -side. The third case is if the point on the dashed segment is not a vertex andthat T continues down into H . Refer to the right diagram in Figure 28. By Definition 11this would make the point on the dashed segment a bridging point, therefore the right sideof H is a b -side. Hence, we have that the right side of H is either a b -side or a q -side, asrequired.It remains to show that any side opposite a b -side is either a p -side or a q -side. Only inthe third case, where T continues from H down into H do we have a q -side. In particular,the right side of H is a q -side and the top side of H is a q -side. The side opposite to theright side of H is a p -side. To show the side opposite to the top side of H is a q -side, wemove H left by an arbitrarily small amount and then move H upwards by an arbitrarilysmall amount to cover the neighbourhood of the bridging point. By the same argument asabove, there must a point on T [ p, q ] that we lost on the bottom edge of H . There are twosubcases as shown in Figure 29. pe i e i +1 H pe i e i +1 H v q H H Figure 29: Cases when the point p is not in a corner and there is a bridging point.The first subcase is if the point on the bottom edge of H is a vertex. Refer to the leftdiagram in Figure 29. By Definition 5, this would make p a bridge event an thus a vertexof T ⊆ T , which would be a contradiction. Thus, the trajectory T must exit the covering H ∪ H on the bottom edge. The point on the bottom edge is q and so the bottom side of H is a q -side. Therefore, all sides that are opposite to a b -side, that is the left side of H and the bottom side of H , are either a p -side or a q -side, as required. Case 2: All coverings have p in a corner. Suppose for the sake of contradictionthat there exists a side opposite p that does not contain either q or a bridging point. For thesame reason as in Case 1 above, this side must not contain any points of the trajectory, andwe can shift the box an arbitrarily small amount without losing any of the trajectory. Thiswould mean we maintain the optimality of the covering in such a way that p is no longer in31 corner of the squares. This contradicts our assumption that all coverings H ∪ H have p in a corner. D.3 The corner lemma
Next we leverage the bridging lemma to show that either p or q is in a corner of H or H . Lemma 18.
Suppose that p is not a vertex of T , and there is a covering H ∪ H ofthe subtrajectory T [ p, q ] where neither of p nor q are in a corner of H or H . Then thesubtrajectory T [ p, q ] cannot be optimal.Proof. We have two cases. Either the point p lies on the left side of H or the right side of H . All other cases are symmetric. Case 1: p is on the left side of H . The left side of H is a p -side, so by Lemma 17,the right side of H is either a q -side or a b -side. We take two subcases. Case 1.1: p is on the left side of H and q is on the right side. See Figure 30. p q p q H H L H H R Figure 30: The new squares H L and H R are constructed to the left and right of H respec-tively.We show that T [ p, q ] cannot be optimal by constructing an earlier subtrajectory withthe same length as T [ p, q ]. We do this by constructing a subtrajectory covered by a squareslightly to the left of H , and another subtrajectory covered by a square slightly to the rightof H .If there is a vertex on the left side of H , then by Definition 4, that would make p abounding box event and a vertex of T . If there is a vertex on the right side of H , then byDefinition 6, that would make p an upper envelope event and vertex of T . Since p is not avertex of T , we must have that there are no vertices on the left side or the right side of H .Now, take H and move it left and right by the same arbitrarily small amount, andcall these new squares H L and H R respectively. For H L on the left diagram of Figure 30,because there are no vertices or bridge points on the right edge, we can choose the movementsmall enough so that the gray diagonally shaded region is empty. We can do the same for H R on the right diagram, because there are no vertices on the left edge, so we can choosethe movement small enough so that the gray diagonally shaded region is also empty. So theonly lengths gained or lost are those on the segment e p that contains p , or the segment e q that contains q .Suppose that T [ p, q ] has length L and by assumption is maximal. Let the length oftrajectory we gain with H L on segment e p be (cid:96) p and the length of trajectory we lose onsegment e q be (cid:96) q . By symmetry and the fact that p and q are not in corners of H , we32ave that H R loses the same amount (cid:96) p and gains the same amount (cid:96) q . Therefore, we havetrajectories close to T [ p, q ] with lengths L , L − (cid:96) p + (cid:96) q and L + (cid:96) p − (cid:96) q respectively. Since L is maximal, we must have (cid:96) p = (cid:96) q . But now we have an earlier trajectory with the samelength as T [ p, q ], so T [ p, q ] is not optimal. Case 1.2: p is on the left side of H and there is a bridging point on the rightside. See Figure 31. pe i e i +1 H q pe i e i +1 H qH L H L H R H R Figure 31: New hotspot positions for starting slightly before and after p .Our construction is extremely similar but slightly more involved as we need to constructnew positions for both H and H . The new positions obtained by moving H left to form H L , and H up to form H L and cover the part of the upper envelope left uncovered by H L . We apply the opposite movements to obtain H R and H R respectively.Again, the gray regions on the left and right sides of H are empty if we choose themovement small enough, otherwise p would be a vertex of T . For H we have an analogousreason but this time it would make q a vertex of T . Therefore, the only parts of thetrajectory gained or lost are those close to p or q . By the same argument as before, theselengths (cid:96) p and (cid:96) q are the same for H L ∪ H L and H R ∪ H R . Therefore, we again deducethat in order for T [ p, q ] to be optimal, (cid:96) p and (cid:96) q must be equal, but then T [ p, q ] is not theearliest optimal trajectory. Case 2: p is on the right side of H . By Lemma 17, the left side of H is a q -side,since it cannot be a b -side. The proof of this case is exactly the same as Case 1. We use thesame construction as the one shown in Figure 30. Summary.
In all cases, if p is not a vertex of T and p and q are not in corner positionsof H and H , then T [ p, q ] is not an optimal subtrajectory.The above Lemma yields the following corollary: Corollary 2.
Suppose p is not a vertex of T and T [ p, q ] is optimal. Then we have thateither p is in a corner of H or H or that q is in a corner of H or H . D.4 The point p must be a special configuration event Finally, we can show that not only is p in a corner of H or H , but p is in fact a specialconfiguration event. Lemma 19.
Suppose that T [ p, q ] is optimal and that p is not a vertex of T . Then p is aspecial configuration event. roof. By Lemma 18, we must have p or q be in a corner of H or H . Without loss ofgenerality, suppose that p is in a corner of H . Up to rotation this leaves only two cases,either p is in the top-left corner of H , or p is in the top-right corner of H . Case 1: p is in the top-left corner. Consider the edges opposite p on H . Thesewould be the bottom edge and right edge of H . Lemma 17 implies both these edges mustcontain either q or a bridging edge. However, it is impossible for both edges to contain q ,so therefore at least one of the two sides contains a bridging point. Moreover, applying thesecond part of Lemma 17 to the bridging point implies that q is in fact on the square H andnot H . Therefore, both sides opposite p contain a bridging edge, and q is on H . There aretwo subcases. Either there are two different bridging points on the bottom and right sidesof H , or there is a single bridging point in the bottom-right corner of H . See Figure 32. p pq q Figure 32: The special configuration events in Case 1.In the first subcase where there are two different bridging points on the bottom andright sides of H , we apply the second part of Lemma 17 on the two bridging points. Thisimplies that q is on H , moreover, it must be in the bottom-right corner of H so that it isopposite both the bridging points. In the second subcase, there is a single bridging pointin the bottom-right corner of H . See Figure 33. By Definition 7 this makes p a specialconfiguration event. Case 2: p is in the top-right corner. Lemma 17 implies that the left and bottomedges of H must contain either q or a bridging point. However, the left edge of H can onlycontain q , so q is on H . Supposing there was a bridging point on the bottom edge of H ,it would imply that q is on the right edge of H , contradicting the fact that q is on the leftedge of H . Therefore, there are no bridging points, p is in the top-right corner of H and q is on the bottom-left corner of H . See Figure 33. By Definition 7 this makes p a specialconfiguration event. D.5 Summary
Hence, by Lemma 19, we have that the starting point of the optimal trajectory is eithera vertex of T or a special configuration event. Hence, the starting point of the optimaltrajectory must be a vertex of T . This yields the following lemma. Lemma 13.
Given a trajectory T and the set of starting points T of T , the starting pointof a longest coverable subtrajectory is guaranteed to be a vertex of T . q Figure 33: The special configuration event in Case 2.
E Proof of Lemma 14
We separately bound the number of reach, bounding box, bridge, upper envelope, andspecial configuration events in each of the following subsections. Moreover, we present thealgorithms to compute these events efficiently.
E.1 Bounding the number of reach events
Lemma 20.
Given a trajectory with n vertices, there are at most O ( n ) reach events.Proof. Suppose p is reach event and r ( p ) is a vertex. The vertex r ( p ) uniquely defines p since it is the earliest point on the trajectory T that reach r ( p ). Since there are n vertices,there are at most O ( n ) reach events. E.2 Computing all reach events
Lemma 21.
Given a trajectory with n vertices, one can compute all reach events in O ( n log n ) time.Proof. This lemma is immediately implied by Corollary 1, as we are computing the reachesof all the vertices.
E.3 Bounding the number of bounding box events
Lemma 22.
Given a trajectory with n vertices, there are at most O ( n ) bounding box events.Proof. Suppose p is such a bounding box event. Let the first and last vertices of T in thesubtrajectory T [ p, r ( p )] be v i and v j . We prove that the pair of vertices v i and v j uniquelydetermines p . Then we prove that there are at most O ( n ) possible choices of the pair v i and v j . Suppose v i and v j are given. Let v i − be the vertex preceding v i , then p must lie on thesegment v i − v i . The vertex v L is the unique leftmost vertex between v i and v j . Now, v L determines the x -coordinate of p , and since p lies on v i − v i , we have the unique positionfor p . Therefore, the vertices v i and v j uniquely determine p .Notice that T [ v i , v j ] is coverable, since p < v i < v j < r ( p ), but T [ v i − , v j +1 ] is notcoverable. Hence it suffices to show that there are only O ( n ) pairs of vertices ( v i , v j ) suchthat T [ v i , v j ] is coverable but T [ v i − , v j +1 ] is not. We take two cases. Either T [ v i , v j +1 ] is35ot coverable, in which case T [ v i , v j ] is the longest coverable vertex-to-vertex subtrajectorystarting at v i . There are only O ( n ) of these choices for the pair ( v i , v j ) since there is onlyone longest coverable vertex-to-vertex subtrajectory for each starting point. Otherwise, T [ v i , v j +1 ] is coverable, in which case T [ v i , v j +1 ] is the longest coverable vertex-to-vertexsubtrajectory ending v j +1 , and we similarly have O ( n ) choices for the pair ( v i , v j ).Therefore, since there are O ( n ) possible choices for v i and v j , and each pair ( v i , v j )uniquely determines the bounding box event p , we have that there are at most O ( n ) boundingbox events. E.4 Computing all bounding box events
Lemma 23.
Given a trajectory with n vertices, one can compute all bounding box eventsin O ( n log n ) time.Proof. From the proof in Appendix E.3, we know that p can be determined by the pair( v i , v j ). We also proved the relationship between the pair ( v i , v j ) and the longest coverablevertex-to-vertex subtrajectory starting at either v i or ending at v j . As a consequence ofLemma 12, we can compute all longest coverable vertex-to-vertex subtrajectories startingat each vertex v i in O ( n log n ) time. Those ending at vertex v j can be handled analogously.For each of the O ( n ) pairs of vertices ( v i , v j ) we use the same method as in Appendix E.3to determine the bounding box event p . We use the bounding box data structure to query v L in O (log n ) time. This determines the x -coordinate of p . Then we compute p by computingthe intersection of the two lines: the vertical line through v L and the trajectory edges v i − v i . E.5 Bounding the number of bridge events
Lemma 24.
Given a trajectory with n vertices, there are at most O ( n ) bridge events.Proof. Let the first and last vertices in the subtrajectory T [ p, r ( p )] be v i and v j . By Ap-pendix E.3, there are O ( n ) pairs of vertices ( v i , v j ). It suffices to show that for each pair( v i , v j ) there are only a constant number of bridge events. The pair ( v i , v j ) determines theleftmost vertex v L on T [ v i , v j ]. If x is in T [ v i , v j ] then it is the unique point on the upperenvelope of T [ v i , v j ] one unit to the right of v L . Otherwise, x is on v i − v i or v j v j +1 andone unit to the right of v L . There are at most two possible positions for the bridge point x .Thus there are a constant number of bridge events for each of the O ( n ) pairs ( v i , v j ). E.6 Computing all bridge events
Lemma 25.
Given a trajectory with n vertices, one can compute all bridge events in O ( n log n ) time.Proof. In a similar manner to Lemma E.4, we begin by computing all pairs ( v i , v j ) in O ( n log n ) time. For each pair ( v i , v j ) we compute the vertex v L in O (log n ) time with thebounding box data structure. Consider two cases. If x is in T [ v i , v j ] we query the upperenvelope of T [ v, v j ] in O (log n ) time with the upper envelope data structure. Otherwise, if x is not in T [ v i , v j ], then x is on v i − v i or v j v j +1 and we can compute the intersection in O (1) time. Therefore, the running time is O ( n log n ) time in total.36 .7 Bounding the number of upper envelope events Lemma 26.
Given a trajectory with n vertices, there are O ( n α ( n ) ) upper envelope eventsof T , where α is the inverse Ackermann function.Proof. For each upper envelope event p of the trajectory T , let u ( p ) be the segment of T on the upper envelope of T [ p, r ( p )] that is one unit to the right of p . If there are multiplesuch segments take any of them. As p ranges from the earliest upper envelope event to thelast one, u ( p ) is a sequence of segments. It suffices to show that u ( p ) is bounded from aboveby O ( n α ( n ) ). We achieve this by showing that sequence of segments u ( p ) is a Davenport-Schinzel sequence of order s = 4 [19].Recall that a Davenport-Schinzel sequence of order s = 4 has no alternating subsequencesof length s + 2 = 6. The subsequence cannot occur anywhere in the sequence even for non-consecutive appearance of the terms. Our first step is to show that if the sequence a, b, a occurs (not necessarily consecutively) then the first two elements of the sequence must be x -monotone, in that the first element is to the left of the second element. Our second step isto deduce a contradiction from an alternating and x -monotone subsequence of length five.Suppose that a, b, a is a subsequence of u ( p ). Let x ≺ y denote that x precedes y alongthe trajectory T . Then there exists three upper envelope events p ≺ p ≺ p along thetrajectory T so that u ( p ) , u ( p ) , u ( p ) = a, b, a . In other words, segment a = u ( p ) = u ( p )whereas segment b = u ( p ). Suppose for the sake of contradiction that p is to the left of p .See Figure 34. p p p u ( p ) u ( p ) u ( p ) b a Figure 34: Three upper envelope events p , p , p so that u ( p ) , u ( p ) , u ( p ) are alternating.Recall from Definition 6 that since p is an upper envelope event, p is the leftmostpoint of T [ p , r ( p )]. But p is to the left of p , so we must have that p (cid:54)∈ T [ p , r ( p )], andtherefore r ( p ) ≺ p . Moreover, for any point p , we have p ≺ u ( p ) ≺ r ( p ). Combining these,we get: u ( p ) ≺ r ( p ) ≺ p ≺ p ≺ u ( p ) = u ( p ) . This is a contradiction, so p is to the left of p . Therefore, whenever the alternatingsubsequence u ( p ) , u ( p ) , u ( p ) = a, b, a occurs, the first two elements p and p are x -monotone.Now suppose we have an alternating subsequence a, b, a, b, a, b of length 6. Let thesubsequence be u ( p ) , u ( p ) , u ( p ) , g ( p ) , g ( p ) , g ( p ). By the property above, we have that37 , p , p , p and p are x -monotone. Since u ( p ) = g ( p ) = a , the segment a spans the entire x -interval from u ( p ) to g ( p ). But now u ( p ) = g ( p ) = b , which means that segment b is above segment a at u ( p ) and g ( p ). Since a and b are straight, this implies that b isalso above a at u ( p ). But u ( p ) = a , which is a contradiction. Therefore the alternatingsubsequence of length 6 does not occur and u ( p ) is a Davenport-Schinzel sequence of order s = 4. E.8 Computing all upper envelope events
Lemma 27.
Given a trajectory with n vertices, one can compute all upper envelope eventsin O ( nα ( n ) log n ) time.Proof. We begin with a preprocessing step. We compute a set S of all vertex events, reachevents, and bounding box events of T . Since there is one reach event per vertex there are O ( n ) reach events, and combined with Appendix E.7, this means that S has size O ( n ).The set S has three properties. The first property is that between any two consecutiveevents s i and s i +1 , the trajectory T is a straight segment, since all vertices of T are in S . The second property is that for the set of points p ∈ [ s i , s i +1 ], their set of reaches { r ( p ) : p ∈ [ s i , s i +1 ] } must lie on a straight segment of T . The reason for this is that ifthere were a vertex strictly between r ( s i ) and r ( s i +1 ), then there would be a (reach) eventbetween s i and s i +1 , contradicting the fact that s i and s i +1 are consecutive. Finally, thethird property is that, supposing s i is the leftmost point on the subtrajectory T [ s i , r ( s i )],then for any p ∈ [ s i , s i +1 ], p is the leftmost point on the subtrajectory T [ p, r ( p )]. The reasonfor this is that if there were p that had a vertex v to the left of p , then there would be abounding box event strictly between s i and s i +1 .Next, we extend these properties of S to properties of upper envelope events that arebetween s i and s i +1 . Let v i and v j be the first and last vertices of T [ p, r ( p )] for some point p ∈ [ s i , s i +1 ]. As a consequence of the first two properties of set S , the vertices v i and v j are the same regardless of our choice of point p . Now suppose that p is an upper envelopeevent. This means that p is to the left of all vertices on the subtrajectory T [ v i , v j ]. As aconsequence of the third property of set S , both s i and s i +1 have x -coordinate less than orequal to the x -coordinate of all vertices of the subtrajectory T [ v i , v j ].Now the algorithm is to take each pair of consecutive events ( s i , s i +1 ) and compute theupper envelope events that occur between s i and s i +1 . We decide on a subset of thesepairs ( s i , s i +1 ) to skip, since they will have no upper envelope events. For each pair ofconsecutive events ( s i , s i +1 ), compute the vertices v i and v j (which are the first and lastvertices of T [ p, r ( p )] for any point p ∈ [ s i , s i +1 ]). From Definition 6, the first requirement onan upper envelope p implies that p is to the left of the entire subtrajectory T [ v i , v j ]. Thisimplies that if the segment s i s i +1 is not entirely to the left of T [ v i , v j ], we can skip the pair( s i , s i +1 ).The second requirement in Definition 6 is that p is one unit to the right of an inflectionpoint u on the upper envelope of T [ v i , v j ]. In particular, if x i and x i +1 are the x -coordinatesof s i and s i +1 , then computing the upper envelope events p in the vertical strip [ x i , x i +1 ] isequivalent to computing the inflection points u in the vertical strip V = [ x i + 1 , x i +1 + 1].Our problem is now to compute the upper envelope of T [ v i , v j ] in the vertical strip V .For each of the O (log n ) canonical subsets of the subtrajectory T [ v p , v q ], we compute theupper envelope Γ i for that canonical subset. The upper envelope of T [ v i , v j ] is simply theupper envelope of the O (log n ) upper envelopes Γ i . In order to argue amortised complexityfor computing the upper envelope of the Γ i ’s, we proceed with a sweepline algorithm.38uppose our vertical sweepline is (cid:96) . Let its initial state (cid:96) start be the left boundary of V ,and its ending state (cid:96) end be the right boundary of V . We maintain three invariants for thesweepline (cid:96) . First, we maintain pointers p i to mark the positions and directions of each ofthe Γ i . Second, we maintain the currently highest of the pointers p i , which we will call p max .Finally, we maintain possible intersections where p max may change, as such we maintainthe intersection of p max with each other p i . See Figure 35. Vp = p max p p Γ Γ Γ (cid:96) start (cid:96) end Figure 35: Sweepline maintains pointers p i . Solid dots: p i changes. Hollow dots: p max swaps.There are two types of sweepline events. The first type of sweepline event occurs whena pointer p i changes. These sweepline events are marked with solid dots in Figure 35,and are the inflection points of Γ i . In our update step, we update the pointer p i andthe intersection(s) between p max and p i . The second type of sweepline event occurs p max changes, in particular when it swaps with some other pointer p i . These intersection pointsare marked with hollow dots in Figure 35. In our update step, we update p max and allintersections between p max and p i .Once the sweepline algorithm terminates, the segments traced by the pointer p max cor-responds to the upper envelope of T [ v i , v j ]. We compute the inflection points along p max and our algorithm return all upper envelope events p on s i s i +1 which are one unit to theleft of an inflection point.It remains to analyse the amortised running time of this algorithm. By Corollary 1 wecan compute a reach event for each vertex in O ( n log n ) time. By Appendix E.4 we cancompute all bounding box events in O ( n log n ). We construct the upper envelope of allcanonical subsets of T in O ( n log n ) time [10]. We initialise the sweepline algorithm andcompute all O (log n ) pointers in O (log n ) time. When the direction of a pointer changes,we update the pointer in constant time, and calculate the new intersections between p max and p i . Since each new intersection can be computed in constant time, and there are O (log n )intersections to calculate, this step takes O (log n ) time. When the highest pointer p max changes, we update p max in constant time, and calculate new intersections in O (log n ) time.Therefore, the amortised running time of the sweepline algorithm is O (log n ) per sweeplineevent. Hence, it suffices to count the number of sweepline events.The first type of sweepline event is when the direction of the pointer p i changes. Thenumber of times a pointer p i changes is equal to the number of inflection points of Γ i in thevertical strip V . Suppose that we charge the sweepline event to that inflection point on Γ i .39f we show that each inflection point on Γ i gets charged at most once, not just during a singlesweepline algorithm but in total across all pairs ( s i , s i +1 ), then the total number of sweeplineevents of this type is bounded by the total complexity of all the Γ i ’s. The total complexityof all upper envelopes of all canonical subsets of the trajectory is O ( nα ( n ) log n ) [10].Suppose for a sake of contradiction that two sweepline events charge to the same inflectionpoint u . Since the sweepline algorithm sweeps from left to right without backtracking, thesetwo sweepline events must have originated from two different pairs. s a s a +1 s b s b +1 ux u − x u Figure 36: If s b is after s a +1 , then s b contradicts the leftmost point property of s a +1 .Suppose that the inflection point u is charged by sweepline events originating frompairs ( s a , s a +1 ) and ( s b , s b +1 ). Without loss of generality let s a ≺ s a +1 ≺ s b along thetrajectory T . Refer to Figure 36. We will show that this contradicts the third property ofthe set S , which states that s a +1 is the leftmost point on the subtrajectory T [ s a +1 , r ( s a +1 )].To this end we will show that s b is between s a +1 and r ( s a +1 ) along the trajectory T , andthat s b is to the left of s a +1 .Note that u occurs as a sweepline event for s b so s a +1 ≺ s b ≺ u . Therefore s a +1 ≺ s b ≺ u ≺ r ( s a +1 ). It remains to show that s b is to the left of s a +1 . Let the x -coordinate of u be x u and consider the vertical line at x -coordinate x u −
1, one unit to the left of u . Sinceboth sweepline algorithms for s a and s b visited the inflection point u , we must have thatthe vertical line cuts s a s a +1 and s b s b +1 in such a way that s a and s b are to the left of thevertical line, whereas s a +1 and s b +1 are to the right of the vertical line. Therefore, s b is tothe left of s a +1 , completing our proof by contradiction. Hence, no inflection point u can becharged twice for the first type of sweepline event.The second type of sweepline event is when the highest pointer p max changes. Every timethe second type of sweepline event occurs, there is a new upper envelope event. Therefore,the number of events of the second type is bounded by the number of upper envelope events,which by Appendix E.7 is at most O ( n α ( n ) ). Therefore, the number of sweepline events isdominated by the first type.The total running time of the sweepline algorithm is O (log n ) time per sweepline event,which leads to O ( nα ( n ) log n ) time in total. Therefore overall running time of this algorithm O ( nα ( n ) log n ). 40 .9 Bounding the number of special configuration events Lemma 28.
Given a trajectory with n vertices, there are at most O ( n α ( n ) ) special config-uration events.Proof. We show the bound by showing that between any two elements of T , there either aunique special configuration event, or if there are multiple they are equivalent and we needonly compute one of them. We show this by using Property 1, 2 and 2 of the trajectory T ,which we proved in Appendix D.1. We require a rotated version of the Property 3 to holdfor the left cardinal direction as well as the upward cardinal direction to bound the numberof occurrences of special configuration 3. Now we consider three cases. Special Configuration 1.
We use Property 1 and Property 2 of T to bound thenumber of special configuration events. We show that between consecutive events s i and s i +1 , there is either a unique instance of special configuration 1, or there are multipleinstances of special configuration 1 which are all equivalent and we only need to computeone of them.Let e p be the segment of T containing p and let e q be the segment containing q . ByProperty 1 of T , the segment s i s i +1 is a subset of e p , and by the second property of T , theset of reaches { r ( p ) : p ∈ [ s i , s i +1 ] } is a subset of e q . Special configuration 1 states that thetop-right corner of H lies on e p and the bottom-left corner of H lies on e q .Let p ( t ) be a function that slides the starting point p from s i to s i +1 . Formally, let p : [0 , → [ s i , s i +1 ] be a linear function so that p (0) = s i and p (1) = s i +1 . Let H ( t ) be theunit sized square with its top-right corner at p ( t ) ∈ e p . See Figure 37. If p ( t ) is in specialconfiguration 1, then H ( t ) would also have its bottom-left corner on e q . e p e p e q e q Figure 37: The square H ( t ) with top-right corner p ( t ) on segment e p .There are two cases. In the first case, e p and e q are not parallel. Then since H ( t )moves parallel to p ( t ) = e p , the bottom-left corner of H ( t ) moves parallel to e p with time.Therefore, the bottom-left corner of H ( t ) can only intersect e q once, and we have thatbetween s i and s i +1 there is a unique instance of special configuration 1.Otherwise, e p and e q are parallel. Therefore, if it is true that H ( t ) has its bottom-leftcorner on e q for some value of t , then it is true for all values of t ∈ [0 , p ( t )and r ( p ( t )) move along e p and e q at the same rate since they are opposite corners of a fixedsized square. We can deduce that T [ p ( t ) , r ( p ( t ))] have the same length for all t ∈ [0 , p ( t ). Special Configuration 2.
We use Property 1 and Property 3 of T to show that itsuffices to consider a unique instance of special configuration 2 between s i and s i +1 . Let e p be the segment of T containing p and passing through the top-left corner of H . Let e b be41he segment of T that passes through the bottom-right corner of H . By Property 1, thesegment s i s i +1 is a subset of e p . By Property 3, the set of points { u ( p ) : p ∈ [ s i , s i +1 ] } is asubset of e b . Let p : [0 , → [ s i , s i +1 ] be a linear function so that p (0) = s i and p (1) = s i +1 .Let H ( t ) be the unit sized square with its top-left corner at p ( t ) ∈ e p . See Figure 38. e p e b e p e b Figure 38: The square H ( t ) with top-left corner p ( t ) on the segment e p .If p ( t ) were a special configuration event, then the bottom-right corner of H ( t ) is requiredto be on e b . By the same reasoning as in special configuration 1, if e p and e b are not parallel,then there is at most one value of t where this can hold. If e p and e b are parallel, thencomputing any candidate would suffice. Hence it suffices to consider a unique instance ofspecial configuration 2 between s i and s i +1 . Special Configuration 3.
We use all Properties 1, 2 and 2 of T to show that it sufficesto consider a unique instance of special configuration 3 between s i and s i +1 . We use theProperty 3 for both the upward and leftward cardinal directions.Let e p be the segment of T that contains p and passes through the top-left corner of H .Let e q be the segment of T that contains q and passes through the bottom-right corner of H . Of the two distinct intersections of H and H , let e b be the segment of T that passesthrough the intersection of the left edge of H with the top edge of H , and let e b be thesegment of T that passes through the intersection of the bottom edge of H with the leftedge of H . See Figure 39.By Property 1, s i s i +1 is a subset of e p . By Property 2, { r ( p ) : p ∈ [ s i , s i +1 ] } is a subsetof e q . By Property 3 in the upward direction, { u ( p ) : p ∈ [ s i , s i +1 ] } is a subset of e b . If l ( p ) is the point one unit below p on the left envelope of T [ p, r ( p )], then by Property 3 inthe left direction, { l ( p ) : p ∈ [ s i , s i +1 ] } is a subset of e b .Now let p : [0 , → [ s i , s i +1 ] be a linear function so that p (0) = s i and p (1) = s i +1 . Let H ( t ) be the unit sized square with its top-left corner at p ( t ) ∈ e p . By Definition 6, u ( p ( t ))is one unit to the right of p ( t ), and therefore u ( p ( t )) is the intersection of the right edge of H ( t ) and e b . Similarly, l ( p ( t )) is the intersection of the bottom edge of H ( t ) and e b .If p ( t ) were a special configuration event, then there would exist a square H so that u ( p ( t )) is on the top edge of H , l ( p ( t )) is on the left edge of H , and r ( p ( t )) is in the bottomright corner of H . Define H ( t ) to be the square with u ( p ( t )) on its top edge and l ( p ( t ))on its left edge. Then as t varies linearly, H ( t ) moves linearly in the plane and therefore u ( p ( t )) and l ( p ( t )) move linearly along the segments e b and e b . See Figure 39. Therefore, H ( t ) moves linearly in the plane. For the same reason as in special configuration 1 and 2,it suffices to consider a unique position where the bottom-right corner of H ( t ) is on thesegment e q . Summary.
In all special configurations there is a constant number of events between any42 p e b e b e p e b e b Figure 39: Sliding H and H along e p , e b and e b .two vertices of T . Therefore, the number of vertices of T is an upper bound on the numberof special configuration events up to a constant factor. By Appendix E.7, the number ofvertices of T is at most O ( n α ( n ) ), so there are at most O ( n α ( n ) ) special configurationevents in total. E.10 Computing all special configuration events
Lemma 29.
Given a trajectory with n vertices, one can compute all special configurationevents in O ( n log n ) time.Proof. We use the same notation as in Appendix E.9. We compute the set T . We take apair of consecutive elements s i and s i +1 . We compute the segment e p that contains [ s i , s i +1 ].We use the reach data structure from Lemma 12 to compute the reach of p and thereforecompute the segment e q . We use the upper envelope data structure in Tool 6 to query e b (or both e b and e b ). We let p : [0 , → e p be the linear function defined in Appendix E.9.If we are in special configuration 1 or 2, we check if the translation is parallel to e q or e b respectively, in which case we can return any p ∈ [ s i , s i +1 ]. Otherwise, we compute thefunction H ( t ) of squares parametrised by t . The square H ( t ) has its top-right, or top-leftcorner at p ( t ) for special configurations 1 and 2 respectively. Then we track the segmentformed by the bottom-right corner of H ( t ) as we vary t . We return the value of t where thebottom-right corner of H ( t ) lies on e q .If we are in special configuration 3, we compute the function H ( t ) of a square with itstop-right corner on p ( t ). Then we compute the intersections u ( p ( t )) and l ( p ( t )) of H ( t )with e b and e b respectively. We let H ( t ) be the square with its top edge of u ( p ( t )) andits left edge of l ( p ( t )). We track the segment formed by the bottom-right corner of H ( t ) aswe vary t . We return the value of t where the bottom-right corner of H ( t ) lies on e q .Now we analyse the running time of this algorithm. Computing the set T takes O ( nα ( n ) log n ), by Corollary 1 and Appendix E.7. Between each pair ( s i , s i +1 ), we querythe reach data structure and the upper envelope data structure, which takes O (log n )and O (log n ) time respectively. Constructing the functions p ( t ), H ( t ), u ( p ( t )), l ( p ( t )) and H ( t ) are constant sized problems and only takes constant time. Therefore, the time tocompute T is O ( nα ( n ) log n ) we spend O (log n ) query time for each element of T . Sincethe size of T is O ( n α ( n ) ) by Appendix E.9, the total running time of this algorithm is O ( n α ( n ) log n ). 43 .11 Summary Lemma 30.
Trajectory T has O ( nβ ( n )) vertices, and can be constructed in time O ( nβ ( n ) log n ) .More specifically, for each type of event, the number of such events and the time in whichwe can compute them is O ( n ) O ( n ) Reach events O ( n ) O ( n log n ) Bounding box events O ( n ) O ( n log n ) Bridge events O ( n ) O ( n log n ) Upper envelope events O ( nβ ( n )) O ( nβ ( n ) log n ) Special configuration events O ( nβ ( n )) O ( nβ ( n ) log n ) .Proof. Recall that β s ( n ) = λ s ( n ) /n , and that λ ( n ) = O ( nα ( n )) and λ ( n ) = O ( n α ( n ) ),where α ( n ) is the extremely slow growing inverse Ackermann function. O ( n ) - O ( n ) -Reach events O ( n ) Appendix E.1 O ( n log n ) Appendix E.2Bounding box events O ( n ) Appendix E.3 O ( n log n ) Appendix E.4Bridge events O ( n ) Appendix E.5 O ( n log n ) Appendix E.6Upper envelope events O ( n α ( n ) ) Appendix E.7 O ( nα ( n ) log n ) Appendix E.8Special conf. events O ( n α ( n )) Appendix E.9 O ( n α ( n ) log nn