Memory-Constrained Algorithms for Simple Polygons∗
Total Page:16
File Type:pdf, Size:1020Kb
EuroCG 2012, Assisi, Italy, March 19{21, 2012 Memory-Constrained Algorithms for Simple Polygons∗ Tetsuo Asanoy Kevin Buchinz Maike Buchinz Matias Kormanx Wolfgang Mulzer{ G¨unter Rote{ Andr´eSchulzk Abstract we can obtain the (clockwise and counterclockwise) neighbor vertex in constant time. We count the stor- A constant-work-space algorithm has read-only access age in terms of the additional number s of cells or to an input array and may use only O(1) additional words that an algorithm uses. As usual, a word is words of O(log n) bits, where n is the input size. We large enough to contain either an input item (such as show how to triangulate a plane straight-line graph a point coordinate) or an index into the data (of log n with n vertices in O(n2) time and constant work- bits). We also assume that basic operations on the space. We also consider the problem of preprocess- input (such as determining if a point is above a given ing a simple n-gon P for shortest path queries, where line) take constant time. P given by the ordered sequence of its vertices. For this, we relax the space constraint to allow s words of work-space. After quadratic preprocessing, the short- Our Results. First, we show how to triangulate a plane straight-line graph (and hence a simple poly- est path between any two points inside P can be found 2 in O(n2=s) time. gon) with constant work-space in O(n ) time (Sec- tion3). Then, in Section4, we apply this result to the construction of memory-adjustable data structures for 1 Introduction shortest path queries. That is, given a polygon P and a parameter s, we construct a data structure of size In algorithm development and computer technology, O(s) for P . We then use this structure to compute we observe two opposing trends: On the one hand, the shortest path between any two points inside P in there are vast amounts of computational resources at O(n2=s) time using O(s) work-space. our fingertips. On the other hand, more and more specialized tiny devices with limited memory or power supply become available. The first trend leads to soft- Related Work. Given their many applications, a sig- ware that is written without regard to resources; with nificant amount of research has been dedicated to this approach, today's latest equipment, be it work- memory-constrained algorithms, even as early as in stations or hand-held devices, will soon appear unac- the 1980s [6]. A classic example with a geometric fla- ceptably slow. It is the second trend on which we will vor is the well-known gift-wrapping algorithm (also focus here: we want to process data with a limited known as Jarvis march [7]). It computes the con- amount of memory. In particular, we consider the vex hull of a planar n-point set in O(nh) time and setting where the input data is given in a read-only O(1) work-space, where h is the number of convex hull data structure and we have only s words of memory vertices. The systematic study of constrained mem- at our disposal, for a parameter s = o(n). ory in a geometric context was initiated by Asano The input of our problem is a polygon P of n ver- et al. [2]. Among other results, they describe how to tices in a read-only data structure. We assume that construct well-known geometric structures (such as we can access the x- and y-coordinates of any poly- Delaunay triangulations, the Voronoi diagrams and gon vertex in constant time. We also assume that minimum spanning trees) with a constant number of variables. Recently, Barba et al. [3] gave a constant- ∗This work was initiated at the Dagstuhl Workshop on Memory-Constrained Algorithms and Applications, November work-space algorithm for computing the visibility re- 21{23, 2011. We are deeply grateful to the organizers as well as gion of a point inside a simple polygon. the participants of the workshop for helpful discussions during Although we know of no algorithm that triangulates the meeting. a simple polygon with o(n) work-space, it is known yJAIST, Japan, [email protected] zTU Eindhoven, Netherlands, fk.a.buchin,m.e.buching how to find an ear of a given simple polygon P in @tue.nl MB is supported by the Netherlands Organisation for linear time and with constantly many variables [5]. Scientific Research (NWO) under project no. 612.001.106. However, since the input cannot be modified, there x ULB Brussels, Belgium, [email protected] seems to be no easy way to extended this method in {Freie Universit¨atBerlin, Germany, fmulzer,roteg@inf. fu-berlin.de order to obtain a complete triangulation of P . We kWWU M¨unster,Germany, andre.schulz@uni-muenster. also note that there exists a method for triangulating de planar point sets [2]. The same paper also contains an 28th European Workshop on Computational Geometry, 2012 e the case where the tour moves from a node to its sib- e = e0 uv = e0 ling in SPT). We call a vertex finished if it has been a3 a 2 u0v0 visited by the traversal and will not be visited again. u0v0 unfinished uv Otherwise, the vertex is . In an Eulerian traversal of SPT, the vertices of H become finished in a1 ak order from right to left. Our algorithm maintains two edges: (i) the cur- rent edge of the tour uv, with v lying to the right Figure 1: The shortest path tree SPT from a1 to all of u; and (ii) the edge e = aiai+1 of H such that other vertices (in purple). Additional triangulation fai+1; ai+2 : : : ; akg are the finished vertices of the edges generated in our algorithm are dotted. The fig- tour. In each step we distinguish three different cases, ure illustrates a forward step (right shaded area) and and we accordingly perform a step as follows. a backward step (middle area). Case 1: v is not incident to e. We perform a forward step into the subtree rooted at v. Case 2: v = ai, but uv is a chord of H. We per- algorithm for finding the shortest path between any form a sideways step to the next child of u that follows two points inside a simple polygon. This algorithm v in counterclockwise order. uses constant work-space and runs in quadratic time. Case 3: v = ai, and uv is an edge ai 1ai of H. For space reasons, we can only give a sketchy idea We do a backward step and return to the parent− of u. of the algorithms here. A more complete description We start the algorithm with a sideways step from is available in the full version [1]. uv := e := a1ak (as an exception to the above rules). The algorithm continues until all vertices are finished 2 Triangulating a Mountain and it tries to make a backward step from e = a1a2. The implementation of the three steps is straightfor- A monotone mountain (or mountain for short) is a ward. The only information about H that is required polygon H whose vertices a1, a2, ::: , ak have increas- by the algorithm is one sequential scan of the se- ing x-coordinates. The edge a a is called the base of 1 k quence of vertices a1; ak; ak 1; : : : ; a2; a1. Thus, the H. In this section, we describe how to triangulate an algorithm can also be applied− if H is given implicitly explicitly given mountain, while using only one scan and if it takes O(n) time to advance from one edge to over the boundary of H. This will allow us to extend the next, as in the next section. the algorithm in the next section in order to triangu- late a mountain that is provided implicitly as part of Theorem 2 Let H be a mountain with k vertices a decomposition of a plane straight-line graph. given as part of a larger plane straight-line graph with For the algorithm, we need the shortest-path tree n vertices. Then we can output the triangles of a SPT from a1 to all other vertices of H. We make the triangulation of H in time O(nk) and with constant following observations, see Figure1. work-space. Proposition 1 SPT has the following properties: For an explicitly given mountain of k vertices, we get 2 (i) SPT makes only upward bends. a running time of O(k ) as a special case. (ii) Each face f of SPT is bounded by the shortest paths from a1 to two consecutive vertices ai and ai+1. 3 Triangulating a Plane Straight-Line Graph (This holds in any simple polygon.) (iii) Each face f of SPT is a pseudotriangle, bounded Let G be a plane straight-line graph. In order to ap- ply Theorem2 to the problem at hand, we decom- from below by an SPT edge uai+1, from the right by pose the convex hull of G into mountains by com- an edge aiai+1 of H, and from above by a concave chain of SPT edges (as seen from inside). puting the vertical decomposition (or trapezoidation) (iv) The face f can be triangulated uniquely by con- of G and by inserting a chord between any two non- adjacent vertices of G contained in the same trapezoid necting the rightmost vertex ai+1 with the reflex ver- tices on the upper boundary.