Fast computation of the modality of polygons

13
JOURNAL OF ALGORITHMS 7.369-381 (1986) Fast Computation of the Modality of Polygons* ALOKAGGARWALANDROBERTC.MELVILLE Electrical Engineering and Computer Science, The John Hopkins University, Baltimore, Maryland 21218 Received June X,1984 The moaizlity of a vertex of a polygon is the number of minima or maxima in the distance function from the vertex under consideration to each of the other vertices taken in order around the polygon. Modality was defined by Avis, Toussaint, and Bhattacharya (Comput. Math Appl. 8 (1982), 153-156) and has been further studied by Toussaint and Bhattacharya (Technical Report, No. SOCS-81.3, School of Computer Science, McGill University, January 1981). These authors have defined modality for polygons, both convex and nonconvex, but have not given an algorithm to compute the modality of a polygon, other than the obvious algorithm derived from the definition, which is quadratic in the number of vertices of the polygon. Our paper gives a modality-determination algorithm for convex polygons whose running time is linear in the sum of the number of vertices and the total modality of the polygon. As a special case, we can test if a convex polygon is unimodal (a term introduced by Avis et a/.) in time O(n) for a polygon with n vertices. This latter result is shown to be optimal to within a constant factor. We then extend our technique to nonconvex polygons and derive a modality-determination algorithm which is better than the obvious algorithm, but probably not optimal. We conclude by posing some open problems and indicating a connection between modality determination and a range query problem which has received some attention in the Computational Geometry literature. 0 1986 Academic Press. Inc. I. INTRODUCTION Research concerning the modality of a polygon in the plane has been stimulated by the work of Toussaint [9, lo], Avis [l] and Bhattacharya and Toussaint [2]. Interest in this subject began when Snyder and Tang [7] proposed an algorithm to compute the diameter of a convex polygon in the plane; that is, the furthest distance between two nonadjacent vertices. Their algorithm had running time O(n), where n is the number of vertices of the polygon. However, Bhattacharya and Toussaint [2] observed that the *This research was supported by NSF Grant 820-5167. 369 Ol%-6774/86 $3.00 Copyright 0 1986 by Academic Press. Inc. All rights of reproduction in any form reserved.

Transcript of Fast computation of the modality of polygons

Page 1: Fast computation of the modality of polygons

JOURNAL OF ALGORITHMS 7.369-381 (1986)

Fast Computation of the Modality of Polygons*

ALOKAGGARWALANDROBERTC.MELVILLE

Electrical Engineering and Computer Science, The John Hopkins University, Baltimore, Maryland 21218

Received June X,1984

The moaizlity of a vertex of a polygon is the number of minima or maxima in the distance function from the vertex under consideration to each of the other vertices taken in order around the polygon. Modality was defined by Avis, Toussaint, and Bhattacharya (Comput. Math Appl. 8 (1982), 153-156) and has been further studied by Toussaint and Bhattacharya (Technical Report, No. SOCS-81.3, School of Computer Science, McGill University, January 1981). These authors have defined modality for polygons, both convex and nonconvex, but have not given an algorithm to compute the modality of a polygon, other than the obvious algorithm derived from the definition, which is quadratic in the number of vertices of the polygon. Our paper gives a modality-determination algorithm for convex polygons whose running time is linear in the sum of the number of vertices and the total modality of the polygon. As a special case, we can test if a convex polygon is unimodal (a term introduced by Avis et a/.) in time O(n) for a polygon with n vertices. This latter result is shown to be optimal to within a constant factor. We then extend our technique to nonconvex polygons and derive a modality-determination algorithm which is better than the obvious algorithm, but probably not optimal. We conclude by posing some open problems and indicating a connection between modality determination and a range query problem which has received some attention in the Computational Geometry literature. 0 1986 Academic Press. Inc.

I. INTRODUCTION

Research concerning the modality of a polygon in the plane has been stimulated by the work of Toussaint [9, lo], Avis [l] and Bhattacharya and Toussaint [2]. Interest in this subject began when Snyder and Tang [7] proposed an algorithm to compute the diameter of a convex polygon in the plane; that is, the furthest distance between two nonadjacent vertices. Their algorithm had running time O(n), where n is the number of vertices of the polygon. However, Bhattacharya and Toussaint [2] observed that the

*This research was supported by NSF Grant 820-5167.

369 Ol%-6774/86 $3.00

Copyright 0 1986 by Academic Press. Inc. All rights of reproduction in any form reserved.

Page 2: Fast computation of the modality of polygons

370 AGGARWAL AND MELVILLE

Snyder-Tang algorithm makes an assumption about the polygon which is satisfied by most, but not all, convex polygons in the plane. Avis et al. [l] defined the modality of a polygon and showed that the Snyder-Tang algorithm, as well as a class of algorithms introduced by Dobkin and Snyder [4] may fail for polygons which are not unimodul, a term also introduced in [l]. Later, Toussaint [9] showed that the Dobkin-Snyder algorithm works only for convex unimodal polygons. Briefly, the modality of a vertex is the number of local maxima of the distance from that vertex to all the other vertices taken successively around the polygon. A polygon is unimodal if this sequence of distances has only one maximum for each vertex of the polygon. The study of modality has become a subject of considerable interest in Computational Geometry and shows that even convex polygons in the plane can exhibit some surprising and counter-intui- tive properties.

Toussaint [9] has given an O(n) algorithm for the all-furthest-neighbors problem for convex, unimodal polygons. In a separate paper [lo], he has also given an O(n) algorithm for solving the all symmetric furthest neigh- bor problem for unimodal (but not necessarily convex) polygons. The best known algorithms for these furthest neighbor problems take O(n log n) even for convex polygons. Thus, these results show that modality is an important property of polygons; in particular, faster and simpler algorithms can be obtained for unimodal polygons. The aforementioned articles define modality for polygons in the plane, both convex and nonconvex, but give no algorithm to compute modality, other than the brute-force algorithm derived from the definition, which is quadratic in the number of vertices. In [9], Toussaint leaves the development of an efficient algorithm for modality determination as an open problem.

Our paper resolves the t&modality problem completely for convex polygons, as posed by Toussaint [9]. We present an algorithm to determine the modality of a convex polygon in time O(n + m), where n is the number of vertices of the polygon and m is the total modality of the polygon. As a special case, we can test whether a convex n-gon is unimodal in Q(n) time; this bound is shown to be the best possible.

We then extend our basic technique to simple polygons. Using a recent result of Edelsbrtmner and Welzl [5], we are able to compute the modality of an n-vertex simple polygon in 0(n1.695) time.

In practice, the Dobkin-Snyder algorithm computes the diameter of convex, unimodal polygons very quickly and this algorithm is also rather simple to implement. Likewise, Toussaint’s furthest-neighbor algorithm for unimodal polygons is simpler than that given by Toussaint and Bhattacharya [ll] for general convex polygons. One application of our algorithm for convex polygons, then, is acting as a “filter.” If an input polygon is unimodal, then one of the simpler algorithms could be confidently used to

Page 3: Fast computation of the modality of polygons

MODALITY OF POLYGONS 371

find the diameter or to find all-furthest-neighbors. If not, a more sophisti- cated algorithm would be necessary. It seems, empirically, that “most” convex polygons are &modal, so, this two-stage approach would be faster than always applying the more complicated algorithm.

This paper has six sections. In Section II, we summarize the notational conventions that we follow in the remaining paper. We review the defini- tions of the modality of a vertex and also the overall modality, m, of the polygon itself. Section III presents an algorithm to determine the modality of the vertices of a convex polygon. Simple modifications to the algorithm allow us to determine whether or not a convex polygon is unimodal in O(n) time (shown optimal) and also solve the all furthest neighbor problem in O(m + n) time for an m-modal convex polygon. Section IV develops an algorithm for the case of simple polygons with vertices in general position. Section V demonstrates, briefly, the modification of this algorithm neces- sary to handle vertices in special position. Finally, Section VI poses some open problems.

We admit that portions of our presentation are tedious. The Computa- tional Geometry literature seems more error-prone than other Computer Science research, probably because of the large number of special or degenerate cases which must be considered. In fact, our first attempt at a modality-determination algorithm benefited from an informal review by Toussaint [12] who uncovered a case we had omitted. For this reason, we have tried to consider all the cases which can arise for each of our algorithms.

II. NOTATION AND DEFINITIONS

A polygon, P, is a sequence of n straight edges joining vertices. P is said to be simple and in standard form if no two edges intersect and no three consecutive vertices are collinear. We ignore the degenerate cases of n I 2. For edge i, s(i) and p(i) are, respectively, the succeeding and the preced- ing edges in a clockwise traversal of the polygon; s’(i) and p’(i) represent the I th succeeding and the Ith preceding edges, where 1 is taken modulo n throughout. Each edge has two endpoints su(i) and p(i). Vertex su(i) is common with edge s(i) [i.e., su(i) = pv(s(i))] and p(i) is common with edge p(i) [i.e., pu(i) = su(p(i))]. The perpendicular bisector of edge i, P&i), is the line through the midpoint of edge i and perpendicular to it. In a convex polygon, PB(i) intersects one edge j, other than i, or a vertex common to two edges j and s(j) [see Lemma 11. We define the “edge opposite edge i” written as OP(i), to be the edge j in either case. Figure 1 summarizes these notational conventions.

Page 4: Fast computation of the modality of polygons

372 AGGARWAL AND MELVILLE

PB(i) sv(i)=pvMN

pv (i)p t , , I I , ,

FIGURE 1

We write d[u, u] for the Euclidean distance between two vertices u and u. Suppose that edge i # s(j). We say that su(j) is an extremum vertex with respect to p(i) if either of the double inequalities hold:

4AiL PJWI < 4p409 431 > 4diL 44.M or

4dih dA1 > ~b4ih 4)l < 4~4iL44d)l. The modality of vertex p(i) is the number of extremum vertices in the

sequence

pu(s(i)), pu(s’(i)), pu(s3(i)), . . . , pu(s”-l(i)).

P is m-modal overall if the sum of the modalities of the vertices equals m. As a special case we define P to be unimodal if, with respect to every vertex, P is at most one-modal. Note that unimodal and one-modal polygons are different because the former could be one-modal with respect to every vertex and, hence, n-modal overall. Avis et al. [l] have given examples of convex polygons that are B(n2)-modal.

Note that degenerate cases can occur when the distances of many consecutive vertices from a given vertex are all equal. In view of this, we also define extremum vertex sets. A vertex sequence [SW), su(s(.m, - * * 9 su(s’(j))] with i # j or s(j) is said to be an extremum vertex set if the double inequalities hold:

G-4 4pu(i), dj)l = 4pu(i), su(s(j))l = . . . = d[pu(i), su(s’(j))] and

(b) 4pu(i), PUWI < 4pu(O, M.dl ad 4pu(i), m(.d(j)>l > d[pu(i), su(s’+‘(j))] or

Page 5: Fast computation of the modality of polygons

MODALITY OF POLYGONS 313

and

d [ puti), su(s’(j))] < d[ puti>, su(s’+l(j))].

An extremum is an extremum vertex or an extremum vertex set.

III. THE VERTEX MODALITY DETERMINATION ALGORITHM FOR CONVEX POLYGONS

We present an algorithm VALGMODAL that computes the modality of each vertex of a convex polygon. In this section, we assume that there are no extremum vertex sets for any vertex of the polygon. This restriction will be removed in Section V. The key idea in our algorithm is to consider “wedge shaped” regions of the plane that are formed by the intersection of two perpendicular bisectors, PB(k) and PB(k + 1). Under certain condi- tions the vertex common to edges k and (k + l), i.e., w(k) = pu(k + l), will be an extremum for any vertex in the wedge containing su(k) or for any vertex in the opposite wedge. The modality of all such vertices should be incremented. Certain special cases arise when the angle formed by edges k and k + 1 is acute. These cases can be handled without affecting the running time of the algorithm.

Algorithm VALGMODAL

Step 1. Array entry V(i) stores the modality of vertex pu(i) for every edge i of the polygon. Initialize V to zero in O(n) time steps.

Step 2. Compute PB(0) and OP(0) in time O(n). OP(0) is found by scanning at most n - 1 edges to see which one intersects PB(0).

Step 3 (General step). To simplify notation we define edge number k to be the edge ~~(0). For 0 I k I n - 1 compute PB(k) and the intersection of PB(k) with PB(k + 1). Note that two bisectors must intersect since the polygon is in a given standard form. Determine OP(k + 1) by dis- tinguishing between the two cases:

Cu.se 1. The intersection point lies inside the polygon; i.e., PB(k) n PB( k + 1) is in-between the midpoint of edge k and PB( k) n OP( k). This is shown in Fig. 2a. Traverse clockwise and check if OP(k), s(OP(k)), . . . , sj(OP( k)) intersect PB(k + 1). Let sj(OP(k)) intersect PB(k + 1). Then increment the modality of the following vertices:

su(OP(k)),su(s(OP(k))),su(s2(0P(k))),...,su(s’-‘(OP(k)))

Page 6: Fast computation of the modality of polygons

374 AGGARWAL AND MELVILLE

PB(k*l)

FIGURE 2

not including

su(OP( k)) if it is the intersection point of PB( k) and OP( k).

Case 2. The intersection of PB( k) and PB( k + 1) lies outside the polygon. Here we distinguish between the following subcases:

Case 2.1. PB(k) intersects edge k + 1 between the midpoint of edge (k + 1) and pu( k + 1) as shown in Fig. 2b. Traverse clockwise from k + 1 to OP( k + 1) and increase the modality of all the encountered vertices that are not adjacent to su(k); i.e., su(k + 2), . . . , pu(OP(k + 1)) but not counting this last vertex if OP(k + 1) is edge k.

Case 2.2. PB(k + 1) intersects edge k between the midpoint of edge k and su( k) as shown in Fig. 2c. Traverse clockwise from OP( k) to edge k and increase the modality of all vertices that are not adjacent to m(k); viz. su(OP(k)), . . . , pu(k - 1) but not counting the first vertex if OP(k) equals edge (k + 1) or if it is the intersection point of OP(k) and PB(k).

Case 2.3. Neither PB(k + 1) nor PB(k) intersect edge k or edge (k + l), respectively, as shown in Fig. 2d. Traverse counterclockwise and check if PB( k + 1) intersects any of OP(k), p(OP(k)), . . . , pj(OP(k)) and let pj(OP(k)) be OP(k + 1). Then as in Case 1, we increment the modality of the vertices:

but not including the last vertex if it is the intersection of PB(k + 1) and OP(k + 1).

Since the two intersection points of PB( k) are known at the beginning of the k th iteration, the intersection points of PB( k + 1) can be calculated in

Page 7: Fast computation of the modality of polygons

MODALITY OF POLYGONS 375

time O(1). Also for Case 2 whether or not PB(k + 1) or PB(L) intersect edge k or (k + l), respectively, can be determined in time O(1). Thus every iteration of step 3 takes time proportional to the number of vertices whose modality has been incremented. The overall time for all iterations of step 3 for an m-modal polygon is, therefore, O(m + n).

We now argue that the above algorithm correctly computes the modality of a convex polygon in time O(n + m).

In Case 1, there are several vertices in the “wedge” opposite vertex su( k). Let PB(k) partition the plane into two half-planes, iYi and H,. Similarly, let PB(k + 1) partition the plane into H3 and H4. Finally, define HA to be the quarter-plane HI n H4 and Hs = H2 n Hj. Consider a vertex, x, inside HA (i.e., not on either of the boundary lines). This vertex is further from xv(k) than from pu(k) because PB(k) is the locus of points equidistant from su(k) and pu(k). Likewise, x is further from pu(k + 1) than from su( k + 1). In other words, vertex su( k) = pu( k + 1) is an extremum point for any vertex inside HA which is not adjacent to su(k). Note that the algorithm does not increment the modality of a vertex if it falls on the boundary of HA.

In Cases 2.1 and 2.2 a wedge HA is formed, just as above. By similar reasoning, vertex su( k) is an extremum point for any vertex in HA which is not adjacent to w(k).

Case 2.3 is a bit different. Here the inspected vertices are in the quarter- plane HB. Vertex w(k) is now a minimum extremum point for a vertex inside HB, because for any such vertex, x:

d [x, pu(k)l ’ d [x, su(k)l and d[x,su(k)] < d[x,su(k + l)].

Again, the modality of each vertex inside Hs, but not adjacent to su(k), is incremented.

We make a few observations about the algorithm. Cases 2.1 and 2.2 occur only when the angle formed by edges k and (k + 1) is acute (less than 90) and hence these cases occur at most three times for any convex polygon. Also, if the angle formed by the edges k and (k + 1) is acute and if w(k) is an extremum vertex for some other vertex, then it can only be a maximum vertex.

Next, we discuss some simple variations to the above algorithm. VALGMODAL can be modified to determine if a convex polygon is unimodal in time O(n). Assume, again, that there are no extremum vertex sets. Then we modify VALGMODAL so that it simply stops if any V(i) is ever incremented past one, since this would indicate that some vertex has modality two or more and the polygon is not unimodal. If the polygon is unimodal, then m I n and the total time of this algorithm is O(n). Later we show that any algorithm which determines whether or not a convex polygon

Page 8: Fast computation of the modality of polygons

376 AGGARWAL AND MELVILLE

pvtn-I)

FIGURE 3

is unimodal requires Q(n) time, thereby establishing the optimality of VALGMODAL within a constant factor for the determination of unimodal- ity. The assumption about extremum sets is removed in Section V.

A variation of VALGMODAL solves the all furthest neighbor problem for an m-modal convex polygon in O(m + n) time. We change the interpre- tion of V(i). Now V(i) is a real number which is the maximum distance from p(i) to the furthest extremum encountered so far. The initialization is V(i) = 0 for i between 0 and n - 1 and when a maximum extremum is encountered during the perimeter traversal in step 3, we compare the distance from pu(i) to the new extremum against the value stored in V(i) and keep the larger of the two. Finally, compare V(i) against d[ pu( i), SU( i)] and d[ pu(i), pu( p(i))] and keep the largest of the three.

To conclude our discussion of VALGMODAL, we demonstrate that its running time is optimal to within a constant factor, for determining uni- modality, using an adversary argument. Consider the polygon shown in Fig. 3. For any edge i, 1 I i 2 n - 1, the vertex p(i) is located on their periphery of a circle with radius R. Vertex pu(0) is located at the center of this circle. Finally, displace pu(2) in slightly towards pu(O), but not inside the chord from pu(1) to pu(3). The polygon is unimodal; in particular, the modality of pu(0) is 1.

Now, we can displace any pu(i + 1) for 2 I i I n - 1 from its present position to a new position (denoted by p(i + 1)) and still maintain the convexity of P as long as &i + 1) lies in the region bounded by the arc and the segment formed by pu(i) and pu(i + 2). However, the displace- ment results in the P being nonunimodal since the modality of pu(0) increases to 2.

Now suppose that a unimodality-test algorithm inspects less than n/6 of the edges of the polygon. Then there is a sequence of six consecutive edges which it did not inspect. Even if three of these inspected edges are 0, 1, and 2, there will always be a vertex common to two uninspected edges, say j and j + 1, which can be displaced to a new position F(j + 1) to increase the modality of pu(0). In other words, unless a modality-determination al- gorithm inspects at least O(n) edges of the polygon, an adversary could

Page 9: Fast computation of the modality of polygons

MODALITY OF POLYGONS 377

construct a polygon for which the algorithm would report the modality incorrectly.

IV. MODALITY DETERMINATION ALGORITHM FOR SIMPLE POLYGONS

Let HA and HB be the wedges defined in Section III. Then these wedges form a wedge pair, the wedge pair is said to be induced by the vertex pu( k + l), and a simple polygon with n vertices has n induced wedge pairs. The algorithm GENMODAL given below computes the modality of a simple polygon. As in Section III, we assume that there are no extremum vertex sets for any vertex of the polygon. The main idea used here is the same as in VALGMODAL. Except in a few cases, if a vertex lies in a wedge pair, then it increases the modality of the polygon. The only exceptions to this are the following:

(i) pu(i) lies in its own wedge pair but does not increase its modality.

(ii) d[pu(i), pu(i + l)] > d[pu(i + l), po(i + 2)]. Then, pu(i) lies in the wedge pair induced by pu(i + 1). However, since pa(i) and pu(i + 1) are neighbors, pu(i) cannot be modality increasing vertex for pu(i + 1). Similarly, if pu(i) is further from pu(i - 1) than pu(i - 2), then it lies in the wedge pair induced by pu(i - 1) but does not increase its modality.

In view of this, GENMODAL computes the number of vertices that lie in each wedge pair and stores the total number of vertices that lie in the n wedges of the polygon, in Q. It also calculates and stores in S, the number of those vertices that do not contribute to the modality because of the aforementioned exceptions but have been counted in Q. Finally, it com- putes the modality by subtracting S from Q. Though the main idea used here is same as in VALGMODAL, the number of vertices that lie in a wedge can no longer be calculated as simply or quickly as in the previous algorithm.

Algorithm GENMODAL

Step 1. Location M stores the modality of the polygon and two other registers Q and S keep other counts. Initialize M, Q and S to zero.

Step 2. For 0 I i 5 n - 1, determine the number of vertices that lie in each of the two wedges induced by pu(i) and denote this by m(i). Calculate m(i) and let Q + Q + m(i).

Step 3. Let Condition A be true when d[pu(i + l), pu(i)] > d[pu(i + 1). pu(i + 2)], and similarly, let Condition B hold when d[ po(i - l), pu(i)] > d[pu(i - l), pu(i - 2)].

Page 10: Fast computation of the modality of polygons

378 AGGARWAL AND MELVILLE

For 0 I i I n - 1 do if Conditions A and B hold then S +- S + 3 else if either Condition A or Condition B holds then S +- S + 2 else S +- S + 1.

Step 4. M + Q - S. Output M.

The following observations allow us to conclude the correctness of the algorithm.

Any vertex pv( i) increases the modality of m( pv( i)) other vertices if and only if one of the following is true:

(a) pv(i) lies in the intersection region of [m(pv(i)) + 31 wedges and the distances of pv( i + 1) and pv(i - 1) from pv(i) are greater than their corresponding distances from pv(i + 2) and pv(i - 2) respectively.

(b) pv(i) lies in the intersection of [m( pv(i)) + 21 wedges and either

d[pv(i + l), pv(i)] > d[pv(i + l), pv(i + 2)]

or

d[pv(i - l),pv(i)] > d[pv(i - l),pv(i - 2)].

(c) pv(i) lies in the intersection of [m( pv(i)) + l] wedges and neither (a) nor (b) is true.

Let S be a set of n points in the plane and let T be a set of m wedge pairs. Then an n-wedge problem R(n, n) requires the determination of the number of points that lie in each of these wedge pairs. It is easy to see that if some algorithm 0 solves R(n, n) in T time steps then GENMODAL computes the modality of the polygon in O(T + n) time steps. This is so because steps 1 and 4 can be implemented in O(1) time. Step 3 can be executed in O(n) time steps since each of its substeps takes a constant time. And using the algorithm ‘P, step 2 can be executed in T time steps resulting in an overall O(T + n) runing time for GENMODAL.

Edelsbrunner and Welzl [5] demonstrate a data structure (called the Conjugation tree) that occupies O(n) space and can be constructed in O(@log*n) preprocessing time. Then, using this data structure, they show that the half place query problem can be solved in 0( n’O&fi + ‘)- ‘) time steps, that is, O(n0.695) time steps. The extension of their algorithm and data structure to the problem of determining the number of points lying in an arbitrary wedge pair is straightforward and can be achieved in the same order of time and space. Thus, the modality of the polygon can be computed in 0(n’.695) time. Note that the algorithm in [5] can be modified to output the points that lie in the given half plane in 0(n0.695 + s) time

Page 11: Fast computation of the modality of polygons

MODALITY OF POLYGONS 379

(a)

steps where s is the number of points that lie in the given query. Conse- quently, GENMODAL can also be modified to determine the modality of each vertex of an m-modal polygon in 0(n’.69s + m) time.

V. INCORPORATING EXTREMLJM VERTEX SETS

Let PB(j) partition the plane into two half-planes, HI and H,; let PB(s ‘+l( j)) partition the plane into H, and H6; and let H, and Hd be the quarter planes HI n H, and H, fl H6, respectively. Then, a vertex set [Nj), M&O), . . . , su(s’( j))] is a maximum extremum for a vertex pu(i), if and only if

(i) PB[su(s( j))], PB[su(s2( j))], . . . , PB[su(s’( j))] intersect at p(i) and

(ii) p(i) lies in H,. See Fig. 4a.

Similarly, the vertex set is a minimum extremum if and only if (i) holds and pu(i) lies in Hd. See Fig. 4b. Thus, in either case, pu(i) lies on many perpendicular bisectors, simultaneously. Let wi be the number of perpendic- ular bisectors on which pu(i) lies, and let W = C;=rw,. Then, for any

Page 12: Fast computation of the modality of polygons

380 AGGARWAL AND MELVILLE

convex n-gon, every perpendicular bisector intersects the n-gon in at most one vertex so that W I n. Consequently, it is easy to modify VALGMODAL without any increase in its time complexity and this modification is omitted for the sake of brevity.

For the case of nonconvex polygons, GENMODAL computes all the points that lie in each of the n wedge pairs (including their boundary). Hence at most 0( W + n1.a95) time steps can be spent when some vertices lie on the perpendicular bisectors but do not contribute to the modality of the polygon. To bound from above, we note the following from Szemiredi and Trotter [8]:

For any set of n distinct lines and n distinct points in the Euclidean plane, and for 1 I i I n, if the weight of the line b, is the number of points that lie on it, then Cy-tb; = 0(n413). Clearly, W = X:-tb, so that W = 0( n413) for any n-sided polygon. Thus, at most O(n413) time can be spent in determining vertices that do not contribute to the modality of the polygon. Consequently, the complexity of the resulting algorithm is O(n 4/3 + n1.695), that is, O(n’,695).

VI. CONCLUSION

Our main contributions are to present algorithms that determine the modality of simple and convex m-modal plygons in O(n1.695 + m) and 0( n + m) time steps, respectively. We also present an optimal algorithm to determine whether or not a convex polygon is unimodal. However, the following questions remain open:

(i) Given a “random” convex n-gon. What is the probability that such a polygon is unimodal? We believe that this probability tends to one as n approaches infinity for any reasonable definition of “random” convex polygons.

(ii) Is VALGMODAL optimal for the vertex modality determination problem for convex polygons?

(iii) How quickly can the modality of a simple polygon be determined when its vertices are in general position? Our approach yields an 0(n’.695) algorithm for determining the modality of a polygon but it is likely that this can be improved. We have a preliminary result that an algorithm to compute the modality of each vertex of an n-vertex simple polygon in time T(n) would automatically yield an O(T(n) + n) algorithm for the n-wedge range problem R(n, n). This implies that the research on the modality determination problem is closely related to the research on the wedge range problem; giving fast algorithms for the wedge range problem has been open for quite some time. Recent work by Chazelle et al. [3] has given an

Page 13: Fast computation of the modality of polygons

MODALITY OF POLYGONS 381

efficient algorithm for the half-plane range problem; unfortunately their technique is very restricted and is not directly applicable to the wedge range problem.

REFERENCES

1. D. Avrs, G. T. TOUSSAINT, AND B. K. BHA’~-TACHARYA, On the multimoclality of distance in convex polygons, Comput. Math. Appl. !?(2) (1982), 153-156.

2. B. K. BHATTACHAR~A AND G. T. TOUSSAINT, A CounterexRmple to a diameter algorithm for convex polygons, IEEE Trans. Pattern Anal. Mach. Intel. (May 1982), 306-309.

3. B. CHAZELLE, L. J. GUIBAS, AND D. T. LEE, “The Power of Geometric Duality,” Proc. 24th Annual Symposium on Foundations of Computer Science, pp. 217-225,1983.

4. D. P. DOBKIN AND L. SNYDER, “On a General Method for Maximizing and MinimZng among Geometric Problems,” Proc. 20th Annual Symposium on the Foundations of Computer Science; pp. 7-19, October 1979.

5. H. EDELSBRUNNER AND H. WELZL., “Half Planar Range Search in Linear Space and O( xt’-‘s(fi+ ‘l-l) Query Time,” Bericht 111, Institute for Information Processing, Technical University of Graz, Austria.

6. M. I. SHAMOS, “Problems in Computational Geometry,” Ph.D. thesis, Carnegie-Mellon Univ. Pittsburgh, 1977.

7. W. E. SNYDER AND D. A. TANG, Finding the extrema of a region, IEEE Trans. Pattern Analy. Mach. Intell. (May 1980).

8. E. SZEMIRRDI AND W. T. TROmR, Private comnumktion. 9. G. T. TOUSSAINT, “Complexity, Convexity and Unimodality,” Proc. Second World Con-

ference on Mathematics. Las Palmas, Spain, 1982; Internat. J. Comput. Inform. Sci., in press.

10. G. T. TOUSSAINT, The symmetric all-furthest neighbor problem, Comput. Mafh. Appl. 9(6), (1983) 747-754.

11. G. T. TOUSSAINT AND B. K. BHAT~ACHARYA, “On Geometric Algorithms that Use the Furthest-Neighbor Pairs of a Finite Planar Set,” Technical Report, No. SOCS-81.3, School of Computer Science, McGill Univ., Montreal, January 1981.

12. G. T. TOUSSAINT, Private communication.