Linear-Time Triangulation of a Simple Made Easier Via Randomization

Nancy M. Amato * Michael T. Goodrich t Edgar A. Ramos ~

Abstract

We describe a randomized algorithm for computing the trapezoidal decomposition of a simple polygon. Its expected running time is linear in the size of the polygon. By a well-known and simple linear time re- duction, this implies a linear time algorithm for trian- Figure 1: A triangulated simple polygon gulating a simple polygon. Our algorithm is consid- erably simpler than Chazelle's (1991) celebrated op- timal deterministic algorithm and, hence, positively answers his question of whether a simpler random- eral other problems in computational deal- ized algorithm for the problem exists. The new algo- ing with that have efficient solutions that rithm can be viewed as a combination of Chazelle's begin with as a preprocessing algorithm and of non-optimal randomized algorithms step (e.g., see [18, 20]). Thus, there has been consid- due to Clarkson et al. (1991) and to Seidel (1991), erable interest in finding efficient algorithms for this with the essential innovation that sampling is per- problem. formed on subchains of the initial , rather than on its edges. It is also essential, as in Chazelle's algorithm, to include a bottom-up prepro- 1.1 Related Prior Work cessing phase previous to the top-down construction Garey et al. [15] were the first to provide a non- phase. trivial algorithm for the polygon triangulation prob- lem. Their algorithm runs in O(nlogn) time and is based on an elegant -sweeping paradigm. Asano 1 Introduction et al. [2] show that this bound is in fact optimal for Polygon triangulation is a classic problem in compu- polygons that may contain holes. For simple poly- tational geometry, as it was one of the first problems gons without holes, the lower bound of Asano et al. studied in the field [15]. Furthermore, there are sev- does not hold, however. This fact, and the impor- tance of the polygon triangulation problem, in turn *Texas A&M University, College Station, TX. E-mail: prompted several researchers to work on methods for amat o@cs. tamu. edu beating O(n log n) time for this problem. tThe Johns Hopkins University, Baltimore, MD. E-mail: goodrich@jhu, edu Fournier and Montuno [14] and Chazelle and In- SMax-Planck-Institut fiir Informatik, Saarbriicken, Ger- cerpi [6] showed, even prior to the Asano et al. lower many. E-mail: ramos~mpi-sb.mpg.de bound result, that to triangulate a simple polygon in linear time it is sufficient to produce a trapezoidal de- composition (trapezoidation) of a simple polygon. In Pelmission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies addition, Yap [31] showed that a similar result holds are not made or distributed for profit or commercial advantage and that in a parallel computing model. A trapezoidation is copies bear this notice and the lull citation on the first page. To copy formed by shooting a vertical ray through each vertex otherwise, to republish, to post on servers or to redistribute to lists, of the polygon, stopping each ray as soon as it hits an- requires prior specific permission and/or a fee. 2000 Hong Kong China other segment on the polygon. Since this early work Copyright ACM 2000 1-58113-224-7/00/6...$5.00

201 showing the importance of trapezoidation for trian- edge conflicts for the trapezoidation of the sample is gulation, every published triangulation algorithm has doomed to spend at least linear time per round. To concentrated on improving the running time of pro- avoid this, we decompose the original polygonal chain ducing a trapezoidation of a simple polygon. For ex- into smaller subchains, sample from the resulting set ample, Tarjan and Van Wyk [30] and Kirkpatrick et of subchains and, taking advantage of the coherence al. [21] showed that the trapezoidation step can be between edges in the polygonal chain, maintain lists performed in O(n log log n) time, resulting in a similar of subchain conflicts for the resulting subproblems, running time for the polygon triangulation problem. rather than edge conflicts. Using randomization, Clarkson et al. [10], Clarkson A technical difficulty in this approach is the defini- et al. [8, 7], and Seidel [28] gave simple randomized tion of the subproblems defined by a set of subchains. algorithms that run in O(n log* n) expected time. Fi- For the approach to work, one needs a decomposi- nally, in a much celebrated and anticipated result, tion with a size that is proportional to the number Chazelle [4] showed that one could, in fact, triangu- of subchains involved, and with faces (subproblems) late a polygon in linear time. Goodrich [16] subse- of bounded complexity. The later requirement is orig- quently showed that a similar result can be proven inated in the need to be able to derive appropriate for a parallel computation model. Unfortunately, the bounds for the sizes of the conflict lists, and in the trapezoidation methods utilized by these optimal de- need to have a decomposition that can be traversed ef- terministic algorithms are quite complex. Indeed, ficiently as one walks along the polygonal chain. This this conceptual complexity has led many researchers, concept also appears in Chazelle's algorithm; follow- including Chazelle [4] himself, to ask whether there ing him, we call this bounded-complexity property is a simple randomized algorithm for triangulating a conformality. Fortunately, our problem is simpler; polygon in linear time. To our knowledge, no simple we describe a simple procedure that computes a con- linear-time randomized algorithm has been presented formal decomposition in time linear in the number of previously. edges in the set of subchalns. This is actually sub- linear in the size of the input chain because it is per- 1.2 Our Results formed for a small sample. In order to traverse the decomposition efficiently, we need a data structure We describe a randomized algorithm for computing for each subchain that answers intersection queries the trapezoidation of a simple polygon. The ex- between a vertical edge, called a portal, and the sub- pected running time of our algorithm is linear in the chain. Thus, as in Chazelle's algorithm, we need a size of the polygon. As already mentioned, from the preprocessing phase that constructs these data struc- trapezoidation, a triangulation of the polygon can tures prior to the actual construction phase. These be obtained in linear time using well-known meth- phases proceed bottom-up and top-down respectively. ods [6, 14]. Thus, our algorithm provides a random- Randomization also plays an important role in the ized algorithm for polygon triangulation that runs in preprocessing phase. Chazelle has argued that such a linear expected time. In addition, our algorithm is combination of bottom-up and top-down approaches considerably simpler than Chazelle's celebrated opti- is indispensable. mal deterministic algorithm; hence, it addresses the A final technicality is the proof of appropriate sam- open problem posed by Chazelle and others as to the pling bounds for the sizes of the chain-conflict lists of existence of a simple randomized triangulation algo- our conformal decomposition: such bounds are known rithm that runs in linear expected time. under locality or monotonicity properties that our de- The general approach of our algorithm for comput- composition does not satisfy [1, 9, 11, 22, 24]. For- ing a trapezoidation of a simple polygon P follows tunately, we can prove appropriate bounds using the that of the non-optimal randomized algorithms by fact that, although the faces in the decomposition do Clarkson et al. [8, 7] and Seidel [28]. That is, we com- not satisfy a locality property, they are chosen from pute the trapezoidation of a successively finer sample a relatively small "pool" of candidates that satisfy a from P, using an algorithm for arbitrary edges (thus locality property. with nonlinear running time), in O(log* n) rounds. This paper is organized as follows. First, for com- The fact that the edges come from a simple polygo- parison purposes, we present a detailed outline of a nal chain is used to efficiently perform the compu- non-optimal randomized algorithm (Sec. 2). We then tation of the conflict lists of the trapezoidation of describe our procedure to compute a conformal de- the sample, once in each round, by walking along the composition for a set of chains (Sec. 3) and our linear original polygonal chain in the trapezoidation. Un- time algorithm (Sec. 4). Finally, we obtain appropri- fortunately, an approach that maintains the lists of ate sampling bounds (Sec. 5) for analyzing our algo-

202 rithm (Sec. 6). We conclude with some remarks and Non-Optimal-Trapezoidation (i-th round) state some open problems (Sec. 7). Input: T(R+_I) and its conflicts w.r.t. S Output: T(R +) and its conflicts w.r.t. S 2 A Non-optimal Algorithm 1. For each A 6 T(R+_I)

For the purpose of comparison with our algorithm, a. Determine R/IA and as a warm-up, we outline a non-optimal random- T(Riv, U {el, e2}) restricted to A, ized algorithm which is an adaptation from those in b. T~ ~ { where el,e2 are the edges that [8, 7] and [28]. Let go be a simple polygonal chain, bound A S be the corresponding set of polygon edges, and let 2. Merge all the TA, A 6 T(R+_I), into T(R +) n = ]S[. We make the nondegeneracy assumption 3. Compute Sla for all A 6 T(R+), by "walking" that no two vertices have the same horizontal coordi- along to in Ti nate; this can be simulated symbolically [13, 32, 33], e.g., through lexicographic ordering. For R C_ S, let Figure 3: Non-optimal trapezoidation procedure. T(R) denote the usual (vertical) trapezoidal decom- position or trapezoidation of the plane induced by R (obtained by introducing vertical visibility rays from ].]...... : : : i the endpoints of edges in R). i i i ii !i>i ii i! i ! !!ii ii ii! i i li.i i'

(a) (b)

Figure 4: The three dotted edges are added to the trapezoidation determined by the two other edges: (a) Local trapezoidations after Step 1, and (b) trape- Figure 2: The trapezoidation of a simple polygon. zoidation after merging in Step 2. For A 6 T(R), let SIa denote the conflict list of A, that is, the set of those edges in S that intersect of the conflict list and hence takes time O(nA).l Step (the interior of) A, and let nA = ISIAI. We adopt the 1.b computes T(RiIAU{el, e2}) restricted to A, where following sampling model: For p with 0 <_ p < 1, a el, e~ are the (non-vertical) edges bounding A. This p-sample R from S is obtained by taking each s 6 S takes time O(rA logrA), where rA = [RilA[, using one into R with probability p independently. of several algorithms for computing a trapezoidation with this complexity, e.g., either the randomized algo- 2.1 Algorithm Outline rithm by Clarkson and Shor [9] or the one by Mulmu- ley [23]. Step 2 involves "stitching" together pieces of The algorithm constructs the trapezoidation of a suc- in T(R +) that are "chopped" by vertical- cessively finer random sample in O(log* n) rounds. rays in T(R+I). In other words, vertical-rays that Formally, let us define a global probability pl = are no longer necessary are removed. See Fig. 4. It 1/log (i) n for round i in the computation, and let Ri takes total time linear in the sizes of the TA's, and be a pi-sample from S chosen in this round (so each hence, the time required is dominated by that of Step s 6 S is taken with probability Pi independently). 1. Since each in T(R +) has at most four Furthermore, let R + = [.Jj<~ Rj. Note that R + is a neighbors, then, assuming that an appropriate data p+-sample from S where p~ < ~j

203 2.2 Sampling Bound and Analysis The algorithm can be analyzed with the use of the fol- lowing sampling bound. Let R be a p-sample from S. Then, for any function f such that f(x) = O(eX/2),

E[ ~AeT(R) f(pnA)] =O(r), (1) (a) (b) where r = pn is the expected size of R (see [9, 24] or Section 5). Using f(x) = x in Eqn. (1), the expected Figure 5: (a) Subdivision after Step 2, and (b) sub- total size of the conflict lists is O(n). This implies division after Step 3. a bound of O(n) for the expected time required by all steps in a round, except Step 1.b. Denoting the O(1) chains in K and at most O(1) vertical rays deter- expectation with respect to the first i samples by E

204 conformal (K, T(K)) Input: A set of chains K and the trapezoidation T(K) of its edges. Output: Conformal decomposition T(K), and its d adjacency graph. 1. Obtain the augmented adjacency graph ~(K) from T(K). Figure 6: Some examples of chain-trapezoids. A chain-trapezoid is determined by up to four distinct 2. Select the extreme ray-pairs of each chain. Let chains, but can be determined by a single one as in the be the planar subdivision (which is simply con- nected) induced by the chains in K and these bottom-left example. Also, becuase ray-pairs from selected ray-pairs. (See Fig. 5(a).) endpoints are not necessarily selected, the situation in the bottom-right example can happen. 3. For each face f of T, do the following: (a) Let the tree r/ be the subgraph of ~(K) corresponding to f (it includes leaves corre- sponding to ray-pairs that bound f). (See See Fig. 6. Fig. 8.) This algorithm clearly runs in O([R]) time: given input T(K), all steps can be performed by simple (b) Let the real-degree of a vertex in TI be the number of incident edges corresponding to traversals of 6(K), ~(K), and the Tf'S. Moreover, branches that contain already selected ray- the number of selected ray-pairs is O(]KI). It is clear pairs as leaves. that T has O([K]) selected ray-pairs; furthermore, (c) Select any ray-pair with real-degree 3. since we select only ray-pairs with real-degree 3 in each tree 7-f, this in turn implies that at most O([K]) 4. Construct T(K), the decomposition induced by additional rays are selected in Step 3. all the selected ray-pairs, and its adjacency Let T(K) be the collection of all the conformal graph. (See Fig. 5(b).) faces. Therefore, we have the following:

Lemma 3.1 Let K be a set of chains and let R C_ S Figure 7: Conformal decomposition procedure. be the corresponding set of edges, and suppose that we are given a planar subdivision representation of the trapezoidation T(R) of the edges in R. Then we can construct in O(IRI) time a conformal subdivision 7-(g) containing o(Igl) faces. '1 ..... o ...... i '~

We refer to the selected (single) rays as portals, , ! .... " i , to the conformal faces as chain-trapezoids (as they are defined by chains rather than by edges), and to the conformal decomposition 7"(K) as the chain- trapezoidal decomposition or chain-trapezoidation.

4 The Linear-Time Algorithm

Our new algorithm can be viewed as a refinement of the non-optimal algorithm of the previous section, in Figure 8: The tree 7i for the upper middle face in which sampling is applied to subchains of the orig- Fig. 5. The nodes corresponding to chain-trapezoids inal chain *0 rather than to edges. More precisely, are represented by small thick , and the nodes the chain ~0 is divided into a set L of subchains of corresponding to ray-pairs are represented by black length ,~, and then a p-sample K C_ L is obtained by circles at the corresponding locally extreme vertices. taking each e 6 L into K with probability p inde- pendently. For each chain-trapezoid A in the chain-

205 trapezoidation "F(K), let LI~ denote the set of sub- chains in L that intersect (the interior of) A. Let Lli ~ .I I -. I I I I I n = ILl, nT, = ILI£1. In analogy with Eqn. (1), one L2 "'" " /: :...... I I i'"l would conjecture a bound L3 f::::"'l

(2) Figure 9: Gradation of subchains. ET(K)

In particular, the expected total chain-conflict size Ki using an inefficient algorithm [9, 15, 23]. Specif- would be O(~t) = O(n/A); thus, it can be made ap- ically, for each i > 1, we choose a global probability propriately sublinear by choosing )~ sufficiently large. Pi = 1/log 3 )~-1, and let Ki be a pi-sample from Li. This is a first step in obtaining a linear time algo- In the i-th round, it is more convenient to deal with rithm. Unfortunately, we cannot proof such a bound; the set of subchains K + that consists of the subchains however, in Sect. 5, we proof a bound that is sufficient in Ki and the subchains in Li contained in all the pre- for our purpose. vious samples Kj, j < i. That is, K + = KiU{glg ELi At the same time, our algorithm can also be and g C g~ where g~ E Kj,j < i}. Note that the ex- viewed as a simplification of Chazelle's algorithm, pected number of the later subchains is as it considers a subdivision of the input chain into Aj successively finer subchains, which we call a grada- tion. However, while Chazelle's algorithm computes j 1, obtained by decomposing each T(K+), and computes the new chain-conflict lists by chain g E Li-1 into a set L~ of subchains each of size following the chain e0 without actually scanning every Ai = log2 Ai-1, and ending with k = O(log* n) so that edge. In a preprocessing bottom-up phase, the algo- )~k = O(1). Thus, the subchains in the i-th gradation rithm constructs for each chain g ELi, i = 1,..., k, a are Li = UteL~_~ Lt. We denote the total number of data structure T)(g) that supports portal-chain inter- subchains in Li by ni = ILil = n/)~i. section queries: given a portal p, determine whether Instead of attempting to compute 7-(Li) directly the chain g intersects p. These queries are needed for (the analog of what Chazelle's algorithm does), our the efficient computation of chain-conflict lists during algorithm further simplifies the problem by taking a the construction phase. These data structures also random sample Ki of subchains from Li of a size such support ray-shooting queries (given a point x, deter- that one can afford to compute the trapezoidation of mine the lowest point in g hit by a vertical ray upward

206 sal of all the T~'s, "stitches" together trapezoids of Top-Down (i-th round) T(K~-) "chopped" by the portals of T(K~-_i); this Input: T(Ki+_i) and its conflicts w.r.t. Li-1 takes time linear in the total size of the T~. The Output: T(K~) and its conflicts w.r.t. Li procedure con:formal in Step 3 was described in Sec- tion 3; it takes time linear in the size of T(K~-) and 1. For each ~ e T(K/+_i) returns the (conformal) chain-trapezoidation 'T(K~-) a. Determine Kil ~ (including its adjacency graph). In Step 4, the con- { T(Kil S U {el, (z}) restricted to ~, flict lists Lil ~ for A e T(K~) are found chain by b. T£ ~ where gl, ~2 are the chains that chain, using the adjacency graph of T(K~) and the bound data structures D(g) to "hop" along Li in T(K~-), as 2. Merge all the T£, ~ e T(K~+_i), into T(Ki+) described next. 3. Obtain T(K~-) using conformal(K~+, T(Ki+)) Hopping. If a chain is already in K~-, then it is 4. Compute LilsS for all A E T(K~-), by "hopping" part of the boundary for some chain-trapezoids and along ni in T(K/+) it can automatically be recorded as part of their con- flict lists. So, consider some g E Li \ K~- and sup- pose that we know a chain trapezoid ~0 E T(K~-) Figure 10: Top-down phase procedure. that contains the first endpoint e of g. Note that the chain-trapezoids in Ti that conflict with g are connected. Thus, weperform a breadth-first-search from x) which can then be used for testing whether a traversal of the adjacency graph of T(K~-), starting query point is contained in a chain-trapezoid (perform with A0. When a chain-trapezoid ~ E T(K~') is vis- ray-shooting queries on the two bounding chains and ited, it is labeled as a conflict and each of the portals determine if the result corresponds to hitting them that s e.parates A from an unvisited chain-trapezoid from inside the chain-trapezoid). ~' E T(K~-) is tested for conflict with g using D(g). If g conflicts with the portal, the traversal visits A ~. 4.3 Top-Down Construction Phase Note that ~ can zig-zag arbitrarily within the set of chain-trapezoids that it intersects. See Fig. 11. Let us now formally describe how our algorithm per- forms the top-down constructionphase. In the i-th round, given the decomposition T(K~') and its con- flict lists with respect to Li-x, the algorithm adds the subchains in K~- to T(K~-_i) as summarized, in Fig. 10. Step 1.a determines the conflict list Kil ~ by check- ing for each g E L~_ll ~ and ~ E L~ n K~, whether g~ intersects A: if so either g~ intersects one of the portals of ~, or its endpoints are inside ~. Both queries are solved by the same data structures 79 constructed during the preprocessing phase. How- ever, note that the query is on chains in Li-1 and, consequently, it is more expensive (we Figure 11: Computing the chain-conflicts for a chain. could afford to construct a faster standard point lo- Note that only one conflict per portal is found, and cation data structure for ~, but it is not necessary). that the order the conflicts are discovered (indicated Let r'~,~ = IKil~[. Step 1.b computes the trapezoi- by numbers) does not necessarily reflect their occur- rences on the chain., The portals not queried are dation T(Kit ~ U {gl,g2}) restricted to ~, where gl shown lighter. and g2 are the two chains bounding z~. This uses a simple algorithm with running time O(ri,~ log ri,~) This procedure performs 0(1) portal-chain conflict [9, 15, 23], where r~,~ = O((~i, ~ + 1)Ai) is the num- queries per conflict actually found. The location Of ber of edges involved in all these chains (the plus 1 the first endpoint e is given by the location of the accounts for gl and g2. Step 2, with a simple traver- second endpoint of the preceding chain g~ (known al-

207 ready if g~ E K+). The location of g's second endpoint e ~ can be determined by performing a point location conflict?(p, g, i - 1) query for each chain-trapezoid found to be in con- Input: A portal p and a chain g in Li-1. flict with g. This is necessary since the conflicts were Output: Yes or No computed not by a linear scan of g, but rather by 1. Determine ~, ~' • T[ which contain the end- "hopping" between portals. points of p 2. If ~ and ~ are different then return Yes Running Time. In Sec. 6, using the sampling 3. For each g' that bounds ~ or in L l ~ do bounds obtained in the next section, we show that il A given the data structures D(g) with query time if conflict?(p, E~, i) = Yes then return Yes O(log 3+~ ,ki), for g E Li, the top-down construction 4. Return No phase is completed in expected time O(n).

Figure 12: Portal-chain query procedure. 4.4 Bottom-Up Preprocessing Phase

9 In the preprocessing phase, the algorithm constructs data structures for portal-chain conflict queries, to be used to hop along the chains in the top-down phase.

Recall the gradation of subchains Li, i = O,...,k, • • . defined above and that for g E Li-1, L~ is the set ofsubchains of gin Li. Let K[ = L~AKi. Note that since Ki is a pi-sample from Li, then K[ is a pi-sample from L~. 3 Figure 13: Two cases in the portal-chain conflict For each g in Li-t, i = 1,...,k, we construct a query: The portal endpoints are in different or in data structure D(E) that consists of: the same chain-trapezoid.

(i) T(K/t) and a corresponding point location struc- The computation of conflict lists for 7-(K[) dur- ture with query time O(logAi_l); ing the construction of D(g) also uses "hopping" and, hence, conflict? inductively. The bottom-up pre- (ii) for each ~ e T(K[), the chain-conflict list L il~x" processing phase is summarized in Fig. 14.

We can use for the construction of 7-(K[) either Running Time. In Sec. 6, using the sampling the randomized algorithm by Clarkson and Shor [9] bounds obtained in the next section, we show that or the one by Mulmuley [23], which also result in point the construction of the data structures D(g) is com- location data structures with logarithmic query time pleted in expected O(n) time. Moreover, we show as needed in (i). Alternatively, other planar point that, even though we recurse on each subchain in location data structures can be used [12, 17, 25, 27, a conflict list, the expected query time for a chain 29]. g ELi is O(log 3+~ )~i), where e > 0 is an arbitrary A portal-chain conflict query for an arbitrary por- small fraction. Thus, we can summarize our results tal p and chain g • Li-1 first uses D(g)'s point loca- in the following. tion data structure T(K[) to locate the endpoints of p. If p's endpoints are contained in different chain- Theorem 4.1 Our randomized two-phase algorithm trapezoids in 7"(K[), then p must intersect g, and constructs the trapezoidation o/ a simple polygon of a conflict if reported. Otherwise, p is entirely con- size n in expected O(n) time. tained in some A E T(K[), and the query continues recursively in the data structures D(gl), for each and 5 Sampling Bounds every subchain g' that bounds ~ or in ~'s conflict list L~]£, which includes the subchains that bound ~. To analyze the running time of our algorithm, we need See Fig. 13. This query procedure is summarized in bounds on the sizes of the subproblems resulting by Fig. 12. The query procedure for ray-shooting, which taking a random sample from a set of chains and then determines the lowest intersection point, is similar 3This phase could use a sampling independent of that in and we omit it. the construction phase, but this is not necessary.

208 Though our chain-trapezoidation lacks locality, or Bottom-Up (i-th round) even monotonicity, the following lemma states that Input: :D(~) for each ~ E Lj-1, j > i we choose it out of a relatively small "pool" of can- Output: T)(~) for each ~ E Li-1 didates that satisfy the locality property. For each ~ E Li-1 do Lemma 5.1 Let K be a set of chains each of length 1. Compute T(K~) and a corresponding point loca- at most A. Then, ]Tc(g)l = o(Iglx2). tion structure 2. Compute T(K~) using conformal(K~, T(K~)) Proof. In T(K), let a region be the union of the 3. Compute Lil ~ for all ~, e T(K[) by "hopping" trapezoids corresponding to a connected subgraph of along L~ in T(K[) 6(K). For each A e T(K) consider the maximum region R$ of T(K) that contains & and is bounded by the same one or two chains that bound &. Note Figure 14: Bottom-up phase procedure. that R$ may not be conformal. Any candidate chain- trapezoid is a subregion of R£ for some &. Since clearly the number of subregions of any R$ is O($2), constructing its chaln-trapezoidation. Let K be a p- and the size of T(K) is O(]K]), then it follows that sample from L, and recall that for a chain-trapezoid the size of TC(K) is o(Igl~2). [] A E T(K), L17~ denotes the list of conflicts of A in L, and that ~ = ILls ]. Unfortunately, we cannot prove We use this result now to prove bounds for the the bound in Eqn. (2). Such a bound can be proved in chain-conflict list sizes in the chain-trapezoidal de: the framework of configuration spaces, when certain composition of a random sample of chains. locality [9, 24] or monotonicity [11, 1] properties hold for the decomposition induced by the sample (see [22] Lemma 5.2 Let L be a set of F~ chains of length $, for a survey), but neither of these properties hold for and let n = A~ be the total number of edges. Let our chain-trapezoidation. Fortunately, we can prove a K C L be a p-sample, F = p~ its expected size, and weaker bound that is only a factor O(f(log A)) larger, let T(K) be its chain-trapezoidal decomposition. For and that suffices to verify that our algorithm has ex- E T(K), we write ~7, = ILI~I. Let f be a positive pected linear running time. The proof of the bound nondecreasing function such that f ( O(x) ) = O( f (x) ). uses a standard trick [9, 5]: one obtains a nontrivial Then bound for a p-sample in terms of a trivial bound for a (p/2)-sample. First, we need a fact about the chain- trapezoidation that limits the amount of non-locality E[G~(K)Z f(Pna)] = O(F-f(log~k)) (4) in the definition of the chaln-trapezoidation. Recall that a chain-trapezoid is bounded by at most two chains and at most two ray-pairs, each one orig- Proof. Let K ~ C_ L be a (p/2)-sample. Recall that inating from another chain (but possibly a bounding TC(K) is the set of candidate chain-trapezoids for K, chain). We say that these at most four chains deter- and that for these chain-trapezoids the locality prop- mine the chain-trapezoid. Let T*(L) be the set of erty in Eqn. (3) holds. Thus, all chain-trapezoids determined by L, that is, those chain-trapezoids determined by a subset of at most Prob{& e CO(K)} four chains in L (but note that some other chains in _- p~(7,)(1 - p)~a L can conflict with such trapezoids). Let 7-C(K) be the set of all candidate chain-trapezoids determined 1 - p (p/2) ~(7') (1 - p/2) ~z~ by K and with empty conflict list with respect to K. Note that 7"C(K) is bigger than 7"(K) as there < 16. e -pnz'/2. Prob(& e 7-c(g')), are candidate chain-trapezoids determinedby K that were not chosen in our construction of T(K). For using 5(&) <_ 4 and (1 -p)/(1 -p/2) < 1 -p/2 < E T* (L), let 5(&) C_ L denote the set of those up e -p/2. Using this upper bound, we obtain to four chains that determine ~. For A E T* (L), we have the locality property:

ZET"C(K) iff 6(Z)_CKandLIzAK=0. (3)

209 = Z f(J~N)" Prob{A e CO(K)} Lemma 5.3 Let K C_ L be a p-sample, and ;~or a AeT*(L) fixed point x, let Ax be the chain-trapezoid in T(K) that contains x. Then

=o o

= O(E[I¢~(K')I]) Proof. A similar proof as for the previous lemma ap- = O(F~2), plies. Only note that the number of candidate chain- using Lemma 5.1. Let T > 0 be a parameter. Then, trapezoids in TC(K) that contain x is O(A2), and so using again the upper bound above, Z Prob{A e CO(K)} 7,~$-* (L) E [ _ ~_ /(p~) xe~

[] = Z I(N~)" Prob{X e ¢C(K)} ~E¢*(L) ~£>2(log r)/p _< 16-~ f(pgN), e-Pra/2.Prob{A e TC(K')} 6 Running Time Analysis First, we note that the sampling bound of Lemma 5.2 holds for K + even though it contains, in addition _< 16. ~ f(p~x).Prob{A ~ T~(K')} to the true random pi-sample Ki, all the subchains /,eT*(L) of previous samples Kj, j < i. This is because, as noted in Section 4, the size is dominated by Ki and so, from the proof of the lemma, the right hand side of Eqn. (4) is not affected. ~e~°(g ) In the analysis below, two specific sums appear that T can be bounded using Eqn. (4): where K" is a (p/4)-sample. Finally, using r = A2, [ E[ Z nT,] =O(~.logA), (5) ~(g) and for any a > O,

f(p~) £e$-(K) E [~e~(~) ~ l°g(a~) ] L~> 20? ~) L~z-<2{ l°lal~~')

: (6) f(pgy,) +/(2log r)- E[IT(K)I] ~eCe(K) 6.1 Preprocessing Phase First, we verify the query time. The expected query O (F" ~-fi~) + O(f(21og r) " ~ = O(f(log A) " ?). time Q(Ai) is the sum of the time needed for a point [] location query, plus the expected time needed for all the recursive queries. Thus, we have For the analysis of the query time of the ray- shooting data structure, we also need a bound for Q(~-I) = O(log Ai-1) + O((1/pi)logAi). Q(Ai) the expectation of the conflict list size of the chain- = O(logAi_l) + O((logAi_l) 3 logAi)- Q(Ai) trapezoid that contains a fixed point x. = O(log 3+e )~i--1),

210 where e is any positive fraction. We have used Lemma Eqn. (6), the total expected time is big-O of (to ab- 5.3 to bound the expected number of chain-conflicts breviate, we are dropping the 1 in the bound for ri,~; as O((1/pi)loghi). Note that it is valid to use the a more complete calculation leads to the same result) bound for a fixed point, as the random choices in the i-th and later rounds are independent of the random choices in earlier rounds. Next, we estimate the ex- E_

O (pi • hi-1 • ~i-1 • log hi-1 • = 0 \log ~Ai_~ log \log ~Ai_l + hi-x log( piAi-~ log Ai-1)) • log(log 2 Ai-~) • log3+~ (log e Ai-l)) \ Pi-1 log~ Ai-~ log-Ai-1 " = o I hi- ) = O(n'pi'l°g2hi-1)=O The conformal decomposition in Step 3 is constructed where the first term accounts for the construction of as described in Section 3 and requires expected time T(K[), and the second term accounts for O(1) portal- big-O of chain intersection queries per chain-conflict. Adding over all g ~ Li-~, the construction time in the (i - 1)- st level is O(n/logAi_~), and adding over all i, the = O(pi. i- h0 = O log3-~i_l . total construction time is O(n). In Step 4, the conflict lists for regions z~ E "T(K~-) 6.2 Construction Phase with subchains in Li are found using the data struc- tures 73, O(1) queries per conflict determined, so the Consider the i-th round, and let ~ E "T(K+). For expected time is the purpose of analysis, let us write ni,~ = ILilsI and r~,~ = IKil~l. Recall that ni = ILil = n/hi. O(~i.logAi'Q(Ai))=O (n~-~i • log hi • Ai) Note that the expected value of r~,~ is bounded by

Pi " ni_l,X " ~-~)~ • In Step 1.a, for each g E Li_ll ~, ( o ) = O n- hi logAi_l " checking whether g' E L~ n Ki intersects ~ takes ex- pected time is O(log 3+e hi-l), using the data struc- The sum of all these contributions over all the rounds ture 7) for the chains bounding A. Thus, using is O(n). Eqn. (5), the total expected time for this step is big-O of 7 Concluding Remarks

Ai-1 . log3+~ ,~i-1] We have presented a randomized algorithm for com- E

211 possible to combine our polygon trapezoidation algo- [17] M. T. Goodrich, M. Orletsky, and K. Ramaiyer. Meth- rithm with a segment intersections algorithm to ob- ods for achieving fast query times in point location data tain an algorithm that can report the k intersections structures. In Proc. 8th ACM-SIAM Sympos. Discrete Algorithms, pages 757-766, 1997. of a chain of n segments in time O(n + k)? Can our linear time algorithm be parallelized? Can the [18] L. J. Guibas, J. Hershberger, D. Leven, M. Sharir, and R. E. Tarjan. Linear-time algorithms for visibility and approach of sampling on subchains lead to efficient shortest path problems inside triangulated simple poly- algorithms for other problems on simple polygons ? gons. Algorithmica, 2:209-233, 1987. Finally, does a deterministic algorithm simpler than [19] L.J. Guibas and J. Stolfi. Primitives for the manipulation Chazelle's exist? of general subdivisions and the computation of Voronoi diagrams. ACM Trans. Graph., 4(2):74-123, Apr. 1985. [20] J. Hershberger. Optimal parallel algorithms for triangu- References latedsimple polygons. Internat. J. Comput. Geom. Appl., 5:145-170, 1995. [1] P. K. Agarwal, M. de Berg, J. Matougek, and O. Schwarzkopf. Constructing levels in arrangements [21] D. G. Kirkpatrick, M. M. Klawe, and R. E. Tarjan. Poly- and higher order Voronoi diagrams. SIAM J. Comput., gon triangulation in O(n log log n) time with simple data 27:654-667, 1998. structures. In Proc. 6th Annu. ACM Sympos. Comput. Geom., pages 34-43, 1990. [2] T. Asano, T. Asano, and R. Y. Pinter. Polygon triangula- tion: Efficiency and minimality. J. Algorithms, 7:221-231, [22] J. Matou~ek. Derandomization in computational geome- 1986. try. J. Algorithms, 20:545-580, 1996. [3] B. G. Baumgart. A representation for com- [23] K. Mulmuley. A fast planar partition algorithm, I. J. puter vision. In Proc. AFIPS Natl. Comput. Conf., vol- Symbolic Comput., 10(3-4):253-280, 1990. ume 44, pages 589-596. AFIPS Press, Alrington, Va., [24] K. Mulmuley. Computational Geometry: An Introduction 1975. Through Randomized Algorithms. Prentice Hall, Engle- [4] B. Chazelle. Triangulating a simple polygon in linear wood Cliffs, N J, 1993. time. Discrete Comput. Geom., 6(5):485-524, 1991. [25] F.P. Preparata. A new approach to planar point location. [5] B. Chazelle and J. Friedman. A deterministic view of SIAM J. Comput., 10(3):473-482, 1981. random sampling and its use in geometry. Combinatorica, [26] F.P. Preparata and M. I. Shamos. Computational Geom- 10(3):229-249, 1990. etry: An Introduction. Springer-Verlag, New York, NY, [6] B. Chazelle and J. Incerpi. Triangulation and - 1985. complexity. ACM Trans. Graph., 3(2):135-152, 1984. [27] N. Sarnak and R. E. Tarjan. Planar point location using [7] K. L. Clarkson, R. Cole, and R. E. Tarjan. Erratum: persistent search trees. Commun. ACM, 29(7):669-679, Randomized parallel algorithms for trapezoidal diagrams. July 1986. lnternat. J. Comput. Geom. Appl., 2(3):341-343, 1992. [28] R. Seidel. A simple and fast incremental randomized algo- [8] K. L. Clarkson, R. Cole, and R. E. Tarjan. Randomized rithm for computing trapezoidal decompositions and for parallel algorithms for trapezoidal diagrams. Internat. J. triangulating polygons. Comput. Geom. Theory Appl., Comput. Geom. Appl., 2(2):117-133, 1992. 1(1):51-64, 1991. [9] K. L. Clarkson and P. W. Shor. Applications of random [29] R. Seidel. On the exact query complexity of planar point sampling in computational geometry, II. Discrete Corn- location. In Abstracts 14th European Workshop Comput. put. Geom., 4:387-421, 1989. Geom., pages 7-8, 1998. [10] K. L. Clarkson, R. E. Tarjan, and C. J. Van Wyk. A fast [30] R. E. Tarjan and C. J. Van Wyk. An O(n loglog n)-time Las Vegas algorithm for triangulating a simple polygon. algorithm for triangulating a simple polygon. SIAM J. Discrete Comput. Geom., 4:423-432, 1989. Comput., 17:143-178, 1988. Erratum in 17 (1988), 106. [11] M. de Berg, K. Dobrindt, and O. Schwarzkopfi On lazy [31] C. K. Yap. Parallel triangulation of a polygon in two calls randomized incremental construction. Discrete Comput. to the trapezoidal map. Algorithmica, 3:279-288, 1988. Geom., 14:261-286, 1995. [32] C. K. Yap. A geometric consistency theorem for a [12] H. Edelsbrunner, L. J. Guibas, and J. Stolfi. Optimal symbolic perturbation scheme. J. Comput. Syst. Sci., point location in a monotone subdivision. SIAM J. Corn- 40(1):2-18, 1990. put., 15(2):317-340, 1986. [33] C. K. Yap. Symbolic treatment of geometric degeneracies. [13] H. Edelsbrunner and E. P. Mficke. Simulation of simplic- J. Symbolic Comput., 10:349-370, 1990. ity: A technique to cope with degenerate cases in geomet- ric algorithms. ACM Trans. Graph., 9(1):66-104, 1990. [14] A. Fournier and D. Y. Montuno. Triangulating simple polygons and equivalent problems. ACM Trans. Graph., 3(2):153-174, 1984. [15] M. R. Garey, D. S. Johnson, F. P. Preparata, and R. E. Tarjan. Triangulating a simple polygon. Inform. Process. Lett., 7(4):175-179, 1978. [16] M. T. Goodrich. Planar separators and parallel polygon triangulation. J. Comput. Syst. Sci., 51(3):374-389, 1995.

212