Geometric Applications of A Matrix Se~ching Algorithm Alok Aggarwal 1 Maria M. Klawe 2 Shlomo Moran 1'4 Peter Shor 3 Robert WIlber 2 1. IBM T. J. Watson Center, Yorktown Heights 2. IBM Almaden Research Center, San Jose 3. Math. Sciences Research Institute, Berkeley 4. On leave from The Technion, Haifa, Israel. I. Introduction points in the plane. In fact, using some geometric properties of a convex polygon and the fact that any point can be the nearest neighbor of at most six The all-farthest neighbor problem for a set of n points in the plane, P, is to find for each point Pie P, other points in the plane, Lee and Preparata (LP78) another point pj~ P with j # i such that obtained a O(n) algorithm for the all-nearest neighbor problem on a convex polygon. However, since d(Pi, pj) - max l<_k<n d(p i, Pk) a single point could be the farthest point for all n-1 other points even if the points form the where d(Pi, Pj) denotes the Euclidean distance be- vertices of a convex polygon, the algorithm pro- tween Pi and pj. The all-nearest neighbor problem posed by Lee and Preparata cannot be extended to consists of finding the nearest point for every point solve the all-farthest neighbor problem in linear in the set. Shamos and Hoey (SH75) have shown time. that O(n log n) is the optimal bound for the allnearest neighbor problem, and Toussaint and A simple polygon is unimodal if for every vertex Bhattacharya (TB81) as well as Preparata (Pr77) have shown that 0(n log n) is also an optimal bound Pk the function defined by the Euclidean distance between Pk and the remaining vertices (traversed in for the all-farthest neighbor problem. clockwise order) contains only one local maximum. For any m _> 1, this definition of unimodal polygons The fl(n log n) bounds given in (SH76, TB81, can be extended to m-modal polygons, in a natural Pr77) do not apply when the input set forms the manner. Somewhat contrary to one's intuition, vertices of a convex polygon (say, given in clock- Avis, Toussaint and Bhattacharya (ATB82) have provided examples of convex polygons in which wise order) rather than being an arbitrary set of n/2 vertices have n/4 local maxima in each of their Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice "s given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee a n d / o r specific permission. © 1986 ACM 0-89791-194-6/86/0600/0285 distance functions. The counter intuitive fact that the distance functions can be multimodal has often resulted either in incorrect algorithms or in increased time complexities for some of them. Aggarwal and Melville (AM83) have shown that $00.75 whether a convex polygon is m-modal can be deter- 285 mined in O(n x m) time and Toussaint (To82) has problem are distinct. These restrictions can be re- provided a very simple and intuitive algorithm for moved; we impose t h e m to simplify the definitions solving the all-farthest neighbor problem for a con- and algorithms. Let A j denote the j - t h column of A vex unimodal polygon in O(n) time. Here we show and that the all-farthest neighbor problem can be solved A [i 1. . . . . for a c o n v e x polygon in O(n) time, regardless of its modallty. We use the same m e t h o d to speed up several other geometric algorithms by a factor of log n. Ai denote the i-th row of A. ik ; Jl . . . . Jk ] denotes the s u b m a t r i x of ik and columns Jl . . . . . Jk • Given a m a t r i x A, the maximum problem is to d e t e r m i n e for each i, the c o l u m n j(i) at which A that is f o r m e d of rows i 1. . . . . This paper is divided into five sections. Section A i has its m a x i m u m value. The m a t r i x A is monotone if for 1 < i 1 < i2 < n, j(il) < j(i2)- A is totally monotone if e v e r y s u b m a t r i x of A is m o n o t o n e . It is II discusses a combinatorial problem for matrices easy to verify that this is equivalent to having e v e r y under two kinds of constraints -- a " w e a k " con- 2 x 2 s u b m a t r i x of A be m o n o t o n e . straint and a " s t r o n g " constraint. We show that each instance of the all-farthest neighbor problem We n o w show that an instance of the all-farthest for c o n v e x polygons is an instance of the m a t r i x neighbor problem on a c o n v e x polygon with n problem under the strong constraint -- and thus also vertices can be regarded as an instance of the maxi- an instance of the matrix problem u n d e r the weak m u m problem on an n x 2 n - 1 totally m o n o t o n e constraint. Section HI demonstrates that there is an matrix. ~2(m log n) lower b o u n d for solving the problem on c o n v e x polygon in clockwise order. n x rn matrices subject only to the w e a k constraint. n x 2n - 1 m a t r i x A as follows. F o r a n y integer u Consequently, if one only makes w e of the weak let constraint in solving the all-farthest neighbor p r o b - i<j<i+n-- lem (in the m a n n e r used by researchers in the past), then then one c a n n o t hope to achieve a linear time sol- A (i,j) = --j. (The non-positive entries are set so as ution. Section IV shows that the m a t r i x problem Let Pl . . . . ou ,Pn denote the vertices of a denote Define an ((u - 1) m o d n) + 1. 1 then A ( i , j ) = d ( P i , A(i,j)=j-n, and if poj). If j < i j_>i+n to m a k e e v e r y value in a r o w distinct.) If then N o w sup- with the strong constraint can be solved in O ( m ) pose the 2 x 2 s u b m a t r i x A [4 J" ; k, l], with i < j and time when m _> n. This yields a linear time solution k < 1, has only positive entries. Then we must have for the all-farthest neighbor problem on c o n v e x i < j < k < I < i + n. In this case the vertices Pi, Pj, polygons. Section V summarizes the i m p r o v e m e n t s P*k , and Pot are in clockwise order a r o u n d the that can be obtained over previous algorithms for polygon. F r o m the triangle inequality one can show solving geometric optimization and c o m p u t e r aided design problems. Because of the space constraint, that d(Pi, P . k ) >_.d(pi, p ° 1) or d(pj, Pel) > d(pj, Pok), or both. Since the distances are distinct the a b o v e we only discuss the all-farthest neighbor problem inequalities here and provide the details for the other problems m o n o t o n e . The non-positive entries ensure that all / in the final version of the paper. are strict. Thus A [i, j ; k, 1] is other 2 x 2 submatrices of A are also m o n o t o n e . Thus A is totally m o n o t o n e , and b y solving the II. The Matrix Problem m a x i m u m problem on A we can solve the allfarthest neighbor problem for the polygon. Let A be an n x m m a t r i x with real entries. We will assume that all entries within a r o w of A are IIl. An fl(m log n) Lower Bound for the Maximum distinct. Similarly, we assume that all distances be- Problem on Arbitrary Monotone Matrices tween pairs of vertices in the farthest neighbor 286 T h e m a x i m u m p r o b l e m on a m o n o t o n e n x m assigns a value subject to the condition that it m u s t m a t r i x A can be solved by the following straightfor- be possible to position the m a x i m a of the rows in a w a r d divide and conquer algorithm. Let i = I"n/2"1 w a y consistent with the values fixed so far and the and in O ( m ) time find the column j at which h i has rnonotonicity condition. its m a x i m u m value. Recursively solve the m a x i - mum problem on All ..... i - - 1; 1 . . . . . j'] (when i > 1 and j > and . 4 I ' i + 1 . . . . . the n;j, .... m] T h e o r e m 3.1: Let A be an n x m m a t r i x , w h e r e n is submatrices (when i < n a p o w e r of 2. 1) e= 1 orm. and L e t h be a positive integer and let Setf=m+ 1-e. Suppose that up to m a x ( m -- 2, 0) cells h a v e already been queried (i.e., j < m). T h e time required b y this algorithm is given h a v e been assigned fixed values). by the r e c u r r e n c e Also, suppose that no cells h a v e been queried in A f, that a n y cells f(n,m) < m + max that h a v e been queried in A e h a v e been set to h, and If(rn/21 - l,j) + 1)}, l<_/<_m f ( L n / 2 J , m - j + that all other queried cells h a v e been set to values less t h a n 1. with f ( 0 , m) = f ( n , l ) = 0. Solving the recurrence, T h e n an a d v e r s a r y c a n a n s w e r a n y queries for the remaining cells, in a w a y consistent we h a v e f ( n , m) = O ( m log n) . (All logarithms in with the m o n o t o n i c i t y condition, so that in o r d e r to this section are base 2.) The best previously k n o w n d e t e r m i n e the positions of the m a x i m a in each r o w algorithms for the all-farthest neighbor p r o b l e m on a total of at least ( 1 / 4 ) ( m - 1)(1 + log n) cells m u s t c o n v e x polygons and for the problems described in be queried (including those that w e r e initially que- section V all contain a step that is essentially this ried), and so that the m a x i m u m value in each r o w divide and conquer procedure. N o t e that this algo- is at least h. r i t h m w o r k s for a r b i t r a r y m o n o t o n e matrices; the m u c h stronger p r o p e r t y of total m o n o t o n i c i t y is not Proof: t a k e n a d v a n t a g e of. w h e n m = 1 the claimed lower b o u n d is 0 a n d there In this section we show that a n y algorithm that solves the m a x i m u m p r o b l e m We will a s s u m e t h r o u g h o u t that rn > 2, for is nothing to prove. W h e n we say that the a d v e r - for a r b i t r a r y m o n o t o n e matrices must have a worst sary sets a cell to a low value that m e a n s that the case time of fl(m log n). So a n y i m p r o v e m e n t on the cell is set to s o m e previously unused positive value simple divide and conquer algorithm for the m a t r i - less t h a n 1. N o t e that if m - 2 or f e w e r queries ces corresponding to the applications m u s t m a k e es- h a v e been m a d e t h e n there are at least t w o columns sential use of the fact that these matrices are totally with no queries, say A "il a n d A h. The a d v e r s a r y can monotone. a n s w e r future queries in these columns either b y setting all cells in A "il to h + 1 and all cells in A h to T h e lower bound is on the n u m b e r of cells of the low values or b y setting all cells in A la to low values m a t r i x t h a t m u s t be queried b y a n y algorithm for and all ceils in A N to h + 1. Either the m a x i m a will the m a x i m u m matrices. all be in A jl or t h e y will all be in A h, and in either Thus the b o u n d applies even if all additional oper- case the m a x i m u m value in each r o w will be greater ations (such as comparisons) are free. than h . Thus w h e n m - 2 or f e w e r queries h a v e that when (1/4)(m- problem n is a on m o n o t o n e power 1)(1 + Iog n) queries of 2 must We p r o v e at been m a d e the positions of the m a x i m a have not yet least been d e t e r m i n e d . be made, f r o m which it follows that for a r b i t r a r y n at least ( 1 / 4 ) ( m - 1) log n queries are required. T h e proof We use induction on n. uses an a d v e r s a r y a r g u m e n t . The value of each cell of the m a t r i x is regarded as being i n d e t e r m i n a t e Basis step: Suppose n < 4. By the observation unt~ it is first queried, at which point an a d v e r s a r y above, at least r n - 287 1 queries m u s t be m a d e , and when n < 4, ( 1 / 4 ) ( m - 1)(1 + log n) < m - 1. So t h e c l a i m is t r u e in this case. Induction step: c o l u m n s of .4 c o n t a i n c - 1 q u e r i e d cells, a n d t h e last m - c c o l u m n s c o n t a i n m - c q u e r i e d cells. L e t n b e a p o w e r of 2 g r e a t e r Let L be one of the two submatrices t h a n o r e q u a l to 4 a n d a s s u m e t h a t t h e t h e o r e m is All ..... r 1 -- 1; 1 . . . . . c] t r u e f o r all p o w e r s of 2 less t h a n n. W e s h o w t h a t A[rl,...,r 2- c] t h e t h e o r e m is t r u e f o r n. T h e s e q u e n c e of q u e r i e s f e w e s t q u e r i e d cells. L h a s c c o l u m n s a n d a t m o s t 1; 1 . . . . . or , whichever has the is d i v i d e d i n t o t w o stages. T h e first s t a g e lasts until /(c - l)/2J a t o t a l of m - 1 cells h a v e b e e n q u e r i e d ( i n c l u d i n g b e t h e i n d e x of t h e r o w of A c o n t a i n i n g t h e first r o w t h o s e cells t h a t h a d b e e n q u e r i e d at t h e s t a r t ) . S i n c e of L (i.e., k 1 is e q u a l to e i t h e r 1 o r r l ) , a n d let k 2 b e a t least m - I q u e r i e s m u s t b e m a d e , w e d o r e a c h t h e i n d e x of t h e r o w of A c o n t a i n i n g t h e last r o w of 5 m a x ( c - 2, 0) q u e r i e d cells. L e t k 1 t h e e n d of t h e first s t a g e . A n y q u e r y m a d e a f t e r t h e L (i.e., k 2 is e q u a l t o e i t h e r r 1 - 1 o r r 2 - 1 ). S i m i - (m-l)th larly, query is in the second stage. For let submatrix R be either 1 < i < 3, let r~ = (in~4) + 1. T h e rules f o r a n s w e r - Aft, ing a q u e r y t o cell A ( i , j ) d u r i n g t h e first s t a g e a r e A [r3,..., as f o l l o w s . q u e r i e d cells. L e t k 3 b e t h e i n d e x of t h e r o w of A . . . , r 3 -- 1; c . . . . . n; c . . . . . rn] or m ] , whichever has the fewest c o n t a i n i n g t h e first r o w of R, a n d let k 4 b e t h e i n d e x la) If i < r 2 a n d j = 1 t h e n if e = 1 set A ( i , j ) t o h, of t h e r o w of A c o n t a i n i n g t h e l a s t r o w of R. R h a s m - c + 1 o t h e r w i s e set A (i, j ) t o h + 1. columns and contains at most L (m - c ) / 2 J _< m a x ( m - c - 1, 0) q u e r i e d cells. m t h e n if e = m s e t A ( i , j ) t o h, l b ) If i _> r 2 a n d j = • o t h e r w i s e set A (i, j ) t o h + 1. 2) If i < r 2 a n d j# N o t e t h a t L satisfies t h e c o n d i t i o n s of t h e t h e o - 1 o r if i > r 2 a n d j # m , set r e m , w i t h p a r a m e t e r s h t a n d e t, w h e r e e ~ = 1 a n d hr=hife= A (i, l ) t o a l o w v a l u e . landh'-h+ life=m. Similarly, R satisfies t h e c o n d i t i o n s of t h e t h e o r e m , w i t h p a r a m W h e n t h e first s t a g e e n d s , e x a c t l y m - 1 cells of A have been queried and the values fixed are cons i s t e n t w i t h all m a x i m a b e i n g in c o l u m n 1 and in r o w s 1 t h r o u g h r 2 - 1 all m a x i m a in r o w s r 2 t h r o u g h n b e i n g in c o l u m n m. Q u e r i e d cells in c o l umns 2 through m - e t e r s h " a n d e", w h e r e e " = m - c + 1 a n d h " = h if e=mandh'=h+ queries life= of cells w i t h i n 1. I n t h e s e c o n d s t a g e L or R are handled by recursively applying the adversary strategy to the t w o s u b m a t r i c e s , a n d q u e r i e s t o cells o u t s i d e of L a n d R a r e a n s w e r e d in s u c h a w a y t h a t t h e y i m p o s e 1 all h a v e v a l u e s less t h a n 1. n o c o n s t r a i n t s u p o n t h e p o s i t i o n s of t h e m a x i m a w i t h i n L o r R. A f t e r t h e first s t a g e is c o m p l e t e d a c o l u m n c a n d t w o s u b m a t r i c e s L a n d R a r e s e l e c t e d as f o l l o w s . T h e r u l e s f o r a n s w e r i n g a q u e r y of cell A (id) a r e F o r 0 _< j < m, let sj b e t h e n u m b e r of q u e r i e d cells in c o l u m n s 1 t h r o u g h j of A (s o = 0). Let c be the as f o l l o w s . s m a l l e s t i n t e g e r in [ 1, m ] s u c h t h a t sc = c - 1 ( t h e r e is s u c h a n i n t e g e r b e c a u s e S,n = m - 1 ). U s i n g t h e 1) If i < k 1 a n d j = 1, o r if i > k 4 a n d j = m, t h e n s e t A ( i , j ) t o h + 1. a c t t h a t t h e sj's a r e a n o n d e c r e a s i n g s e q u e n c e of int e g e r s it is e a s y t o s h o w b y i n d u c t i o n t h a t f o r a l l j in 2) I f k 2 < i < k 3andj=cthensetA(i,j) toh+2. [0, c - 1 ], sj > j. I n p a r t i c u l a r , s c_ 1 > c - 1. S i n c e Sc-1 <so, we conclude that Sc-l = sc = c - T h e r e f o r e A c h a s n o q u e r i e d cells, t h e first c - 1. 3 a ) If A (i, j ) is in s u b m a t r i x L t h e n fix t h e v a l u e f o r 1 t h a t cell b y a p p l y i n g t h e a d v e r s a r y s t r a t e g y 288 recursively to L, using the p a r a m e t e r s e' and Also, the m a x i m u m value in each r o w is at least h. h'. [] 3b) If ,4 (i, j ) is in s u b m a t r i x R then fix the value for that cell b y applying the a d v e r s a r y strategy W h e n A has no initial queries the conditions of recursively to R , using the p a r a m e t e r s e" and the t h e o r e m are obviously m e t for a n y h > 1 a n d e hH . equal to either 1 or m, so w e h a v e the desired fl(m log n) l o w e r bound. 4) For all other queries set `4 (i, j) to a low value. IV. A Linear T i m e Algorithm for The M a x i m u m Rule 1 ensures that the m a x i m a in rows 1 Problem on Totally Monotone Matrices through k 1 - 1 are in .41 and that the m a x i m a in r o w s k 4 + 1 through n are in A m . Rules 2 ensures that the m a x i m a in rows k 2 + 1 through k 3 - 1 are in .4 c. `4[k I . . . . . and The k2; c + 1. . . . . the `4[k3 . . . . . values cells in m ] are all less than h', values k4; 1 . . . . . of of c- cells in 1] are all less t h a n h". By a s s u m p t i o n the recursively applied strategy will result in a m a x i m u m value of at least h p in each r o w of L a n d of at least h" in each r o w of R. Thus the m a x i m a for rows k 1 through k 2 of A will all be in s u b m a t r i x L, and the m a x i m a for rows k 3 through k 4 will all be in s u b m a t r i x R. Thus, as claimed, no e x t e r n a l constraints a r e placed upon the positions of the m a x i m a within L and R, so the recursive use H e r e we s h o w that b y m a k i n g use of the strict constraints imposed b y total m o n o t o n i c i t y we can solve the m a x i m u m p r o b l e m in linear time. For each i, let j(i) be such that A(i, j(i)) is the m a x i m u m e l e m e n t in A i. T h e k e y c o m p o n e n t of the algorithm is the subroutine REDUCE . It takes as input a n n x m totally m o n o t o n e m a t r i x A, with m > n. T h e value r e t u r n e d b y REDUCE is an n x n s u b m a t r i x of A, C, with the p r o p e r t y that, for 1 _< i __. n, subm a t r i x C contains c o l u m n A Ai). R E D U C E does a constant a m o u n t of w o r k per c o m p a r i s o n , a n d does at m o s t 2 m O(m) n- 1 comparisons, so runs in t i m e . of the a d v e r s a r y strategy in rules (3a) and (3b) is Say t h a t an e l e m e n t A (i, j) is killed if, using the valid. results of a n y c o m p a r i s o n s m a d e so far a n d the total S u b m a t r i c e s L and R each h a v e n[4 rows. assumption, at least (1/4)(c- By 1)(I + l o g ( n / 4 ) ) queries are needed to l o c a t e the m a x i m a within L m o n o t o n i c i t y of A, it can be s h o w n that A(i, j) is not the m a x i m u m e l e m e n t in Ai, i.e., j ~ j(i). A c o l u m n is killed if all of its elements are killed. and at least ( 1 / 4 ) ( , , - c)(1 + l o g ( n / 4 ) ) queries are L e m m a 4.1: L e t A be a totally m o n o t o n e m a t r i x . If needed to locate the m a x i m a within R. In addition, A (r, Jl) > A (r, J2) at the end of the first stage t h e r e are at least |A(i, j2): 1 < i < r } are killed. On the other hand, if A ( r , A ) < A(r, j2) then the entries in {A(i, jl): r _< i < n } are killed. (m - 1 ) / 2 queries in .4 outside of L and R . So the total n u m b e r of queries needed to find the m a x i m a then the entries in in A is at least Proof: T h e first claim follows f r o m the fact that (m - 1 1) 1 n + ~ - ( c -- 1)(1 + log -~--) + n 1 - ~ ( m -- c)(1 + log -~-) - ~ - ( m -- 1)(1 + log n). A [i, r ; Jl, J2 ] is m o n o t o n e for all I < i < r . Simi- larly, the second claim follows f r o m the fact that A [r, i ; Jl, J2 ] is m o n o t o n e for all r < i _< n . [] 289 L e t t h e index of C b e t h e l a r g e s t k s u c h t h a t f o r b r a n c h e s of t h e c a s e s t a t e m e n t a r e e x e c u t e d . A all 1 < j < k a n d 1 < i < j , e l e m e n t C(i, j ) is killed. c o l u m n is d e l e t e d o n l y in t h e last t w o cases, a n d N o t e t h a t e v e r y m a t r i x has i n d e x a t least 1. s i n c e a t o t a l of m - n c o l u m n s a r e d e l e t e d w e h a v e b + c = m - n. T h e i n d e x i n c r e a s e s in t h e first c a s e a n d d e c r e a s e s in t h e last case, a n d is u n c h a n g e d in T h e a l g o r i t h m R E D U C E is as f o l l o w s . t h e s e c o n d case. S i n c e t h e i n d e x s t a r t s a t 1 a n d e n d s R E D UCE(A) n o h i g h e r t h a n n t h e net i n c r e a s e in t h e i n d e x is C ,~--A ; k.,--1 a -- c < n -- 1. C o m b i n i n g t h e s e t w o f a c t s , w e h a v e ~ h i l e C has m o r e t h a n n c o l u m n s do timet=a + b + c < a + 2b + c < 2 m - n - 1 . [] case C(k, k) > C(k, k + 1) a n d k < n: We k ~ - - k + 1. now describe solves the maximum C(k, k) > C(k, k + 1) a n d k = n: MAXCOMPUTE, which problem on an n x m totally m o n o t o n e m a t r i x , w h e r e m >_ n. D e l e t e c o l u m n C k +l . C ( k , k ) < C ( k , k + 1): M A X C O M P UTE(A ) D e l e t e c o l u m n Ck; k,~- k - 1 . B~-- R E D U C E ( A ) endcase if n = return(C) 1 lhenreturn C.-- B[2, 4 . . . . . 2 L n / 2 j ; 1,2 . . . . . n ] MAXCOMPUTE(C) T h e i n v a r i a n t m a i n t a i n e d is t h a t k is t h e i n d e x of C. Also, only killed columns are deleted. Using the bounds due to the known positions It is e a s y t o of t h e m a x i m a in t h e e v e n r o w s of B, f i n d t h e see t h a t t h e s e c o n d i t i o n s h o l d . T h e i n v a r i a n t h o l d s m a x i m a in t h e o d d r o w s of B. i n i t i a l l y b e c a u s e t h e i n d e x of C a t t h e s t a r t is 1. If C ( k , k ) > C ( k , k + 1) t h e n b y L e m m a 4.1 all ele- T h e o r e m 4.3: W h e n n < m M A X C O M P U T E m e n t s of C k'+l in r o w s 1 t h r o u g h k a r e k i l l e d . T h u s the if k < n t h e i n d e x of C i n c r e a s e s b y 1, a n d if k = n n x m m a t r i x in t i m e O(m). maximum problem on a totally solves monotone c o l u m n C k + l is killed, a n d t h e i n d e x of C r e m a i n s the same. Proof: If C(k, k ) < C ( k , k + 1) t h e n b y L e m m a Let f(n,m) be the time taken by 4.1 all e l e m e n t s of C k in c o l u m n s k t h r o u g h n a r e MAXCOMPUTE k i l l e d , a n d s i n c e t h e e l e m e n t s of C k in c o l u m n s 1 r e m 4.2 w e k n o w t h a t t h e c a l l t o R E D U C E t h r o u g h k - 1 w e r e a l r e a d y k i l l e d , C k is k i l l e d . t i m e O(m) a n d t h a t b y f i n d i n g t h e m a x i m a in t h e In t h a t c a s e t h e i n d e x of C d e c r e a s e s b y 1. T h e o r e m 4.2: I n O(m) c o m p a r i s o n s , a l g o r i t h m RE- on a n n x m m a t r i x . From Theotakes r o w s of t h e n x n m a t r i x B we have found the m a x i m a in t h e r o w s of A. T h e a s s i g n m e n t of t h e e v e n r o w s of B t o C is r e a l l y j u s t t h e m a n i p u l a t i o n D UCE r e d u c e s t h e m a x i m u m p r o b l e m f o r a n n x m of a list of r o w s , a n d c a n b e d o n e in O(n) t i m e . C is totally monotone matrix to the maximum an n/2 x n totally monotone matrix so the recur- problem for a n n x n t o t a l l y m o n o t o n e m a t r i x . sive call t o M A X C O M P U T E Proof: REDUCE terminates when C has n columns, so t h e o u t p u t is a n n x n s u b m a t r i x of A. That C t a k e s t i m e f ( n / 2 , n) . T h e last s t e p c a n b e d o n e in O(n) t i m e . T h u s , for s u i t a b l e c o n s t a n t s c 1 a n d c2, t h e t i m e is c o n t a i n s all c o l u m n s of A t h a t h a v e a m a x i m u m f ( n , m) < cln + c2m + f(--~, n), v a l u e for s o m e r o w of A f o l l o w s f r o m t h e a b o v e d i s c u s s i o n . F o r t h e t i m e a n a l y s i s , let a, b, a n d c d e note, respectively, the number w h i c h h a s t h e s o l u t i o n f(n, m) < 2 ( c 1 + c2)n + c2m. of t i m e s t h e t h r e e S i n c e m >_ n. this is O(m). [] 290 We have also obtained tight bounds for the Finally, we discuss an application of our m a t r i x m a x i m u m problem on totally m o n o t o n e matrices in search algorithm to a wire routing problem. Con- the case w h e r e m < n, which we state here without sider the problem of connecting n corresponding proof. terminals {Pi} and {Qi} with wires. The P/s are arranged in order b y index along a horizontal row, Theorem 4.4: When n > m the necessary and suffi- and the Qi's are also arranged in order along a lower cient time required to solve the m a x i m u m problem horizontal row. The connecting wires must be sep- on arated by some m i n i m u m distance, and often there a totally monotone n × m matrix is O(m(1 + log(n/m))) . are other constraints. For example, the wires m a y be constrained to lie on a rectilinear grid or m a y be V. Applications of the Matrix Searching Algorithm constrained to consist of horizontal, vertical, or 45 degree angle segments. Lee and Preparata have shown (LP78) that the Assume that the Qi's are along the x axis with Q1 at the origin. Define the they offset to be the x coordinate of P1 and call the y coordinate of the Pi's the separation. Given the design crucially use the fact that any point in the plane can rules, the separation problem is t o find, for some be the nearest neighbor of at most six other points. fixed offset, the m i n i m u m separation that permits a Like the all-farthest neighbor problem, we can also legal wiring. The optimal offset problem is to find solve the all-nearest neighbor in linear time without the offset that allows the m i n i m u m separation. even using this fact. F u r t h e r m o r e , we can solve the Dolce et al. (DKSSU81) found a linear time algo- following problem in linear time. Given t w o c o n v e x polygons, for every vertex in one polygon, find its r i t h m for the m i n i m u m separation problem in the farthest (or its nearest) vertex in the other polygon. rectilinear integer grid. Our algorithm improves the previous best k n o w n s h o w e a that for a very general class of design rules solution for this problem by a factor of log n . the m i n i m u m separation problem can be solved in all-nearest neighbor problem for a c o n v e x polygon can be solved in linear time. However, case where the wires are constrained to lie on a Seigel and Dolev (SDS1) O(n log n) time. T h e y also obtained linear bounds Boyce et al. (BDDG82) have shown that given a c o n v e x n-gon, the m a x i m u m area (or m a x i m u m perimeter) inscribed k-gon O(kn log n + n log2n) time. can be found in Since the diameter problem for a c o n v e x polygon can be regarded as finding the m a x i m u m perimeter k-gon when k = 2, it is not surprising that our linear time solution for the m a t r i x problem can be used to r e d u c e the time complexity of Boyce et al.'s algorithm to O(kn + n log n). In particular, we can find a maximum area (or m a x i m u m perimeter) inscribed quadrilateral in O(n log n) time. In a similar manner, Aggarwal, Chang and Yap ( A C Y 8 5 ) have shown that the minimum area circumscribing k-gon can be found in O(n 2 log k log n) time and we can reduce the time c o m p l e x i t y of their algorithm to O(n 2 log k). for m o r e general constraints than those used by Dolev et al. (DKSSU81), such as w h e r e the wires lie on a quarter integer grid and consist of segments at angles that are multiples of 45 degrees. However, for some natural design rules, such as a wiring scheme that permits arbitrarily shaped wires, with a m i n i m u m separation of 1 unit, Seigel and Dolev w e r e not able to do any b e t t e r than their generic O(n log n) algorithm. The O(n log n) algorithm was based upon a certain matrix being totally m o n o t o n e , so we can provide a linear time algorithm for all design rules in the class they defined, in particular for the case w h e r e the wires can have arbitrary shapes. Also, they showed that in such schemes the optimal offset problem can always be solved in O(n log2n) time, and we can r e m o v e one of the log n factors in that algorithm. 291 Acknowledgements: The authors thank Ashok K. Chandra, Don Coppersmith, S. Rao Kosaraju, Ravi Nair, and Martin Tompa for stimulating discussions. References (ACY85) A. Aggarwal, J. S. Chang and C. K. Yap, "Minimum Area Circumscribing Polygons," Technical Report, Courant Inst. of Math. Sciences, NYU, 1985. To appear in The Visual Computer, 1986. (AM83) A. Aggarwal and R. C. Melville, "Fast Computation of the Modality of Polygons," Proc. of the Conf. on Information Sciences and Systems, The Johns Hopkins University. To appear in the Journal of Algorithms. 1986. (ATB82) D. Avis, G. T. Toussaint and B. K. Bhattacharya, "On the Multimodality of Distance in Convex Polygons," Comp. and Math. with Applications, Vol. 8, No. 2, pp. 153-156, 1982. (BDDG82) J. E. Boyce, D. P. Dobkin, R. L. Drysdale, and L. J. Guibas, "Finding Extremal Polygons," SIAM J. of Computing, pp. 134-147. Vol. 14, 1985. Also appears in the Prec. STOC 1982. (DKSSU81) D. Dolev, K. Karplus, A. Siegel, A. Strong, and J. D. Ullman. "Optimal wiring between rectangles," Thirteenth Annual ACM Symposium on the Theory of Computing, pp. 312-317, 1981. (LP78) D. T. Lee and F. P. Preparata, "The AllNearest Neighbor Problem for Convex Polygons," Info. Prec. Letters, Vol. 7, No. 4, pp. 189-192, June 1978. (LY85) D. T. Lee and Chee K. Yap, Private Communication. (MOS85) M. Mckenna, J. O'Rourke and S. Suri, " Finding the Largest Rectangle in an Orthogonal Polygon," Tech. Report, The Johns Hopkins University, 1985. Also appears in the Prec. of the Allerton Conference on Control, Communications and Computing, 1985. (Pr77) F. P. Preparata, "Minimum Spanning Circle," in Steps in Computational Geometry, F. P. Preparata Ed., University of Illinois, Urbana, pp. 3-5, 1977. (SD81) A. Seigel and D. Dolev, "The Separation for General Single-Layer Wiring Barriers," Prec. of the CMU Conference on VLSI, pp. 143-152, 1981. (Sh75) M. I. Shames, "Geometric Complexity," Prec. 7th Annual Symposium on Theory of Computing, pp. 224-233, May 1975. (SH75) M. I. Shames and D. Hoey, "Closest-point Problems," Prec. 16th Annual IEEE Symposium of Foundations of Computer Science, pp. 151-162, October l975. (To82) G. T. Toussaint, "Complexity, Convexity and Unimodality," Prec. Second World Conf. on Mathematics, Las Palmas, Spain, 1982. Also, appears in the Journal of Computer and Information Sciences, 1983. (To83) G. T. Toussaint, "The Symmetric AllFurthest Neighbor Problem," Comp. and Math. Applications, Vol. 9, No. 6, pp. 747-754, 1983. (TB81) G. T. Toussaint and B. K. Bhattacharya, "On Geometric Algorithms that Use the Furthest-Neighbor Pair of a Finite Planar Set," Tech. Report, School of Computer Science, McGill University, Jan. 1981. 292
© Copyright 2025 Paperzz