smallest k-point enclosing rectangle and square of arbitrary orientation

8
Information Processing Letters 94 (2005) 259–266 www.elsevier.com/locate/ipl Smallest k -point enclosing rectangle and square of arbitrary orientation Sandip Das a,, Partha P. Goswami b , Subhas C. Nandy a a Indian Statistical Institute, Kolkata 700 108, India b Calcutta University, Kolkata 700 029, India Received 12 August 2004; received in revised form 8 February 2005 Available online 8 April 2005 Communicated by F.Y.L. Chin Abstract Given a set of n points in 2D, the problem of identifying the smallest rectangle of arbitrary orientation, and containing exactly k( n) points is studied in this paper. The worst case time and space complexities of the proposed algorithm are O(n 2 log n + nk(n k)(n k + log k)) and O(n), respectively. The algorithm is then used to identify the smallest square of arbitrary orientation, and containing exactly k points in O(n 2 log n + kn(n k) 2 log n) time. 2005 Elsevier B.V. All rights reserved. Keywords: Levels of arrangement; Plane sweep; Computational geometry; Optimization 1. Introduction Given a set S of n points in 2D, and an integer k( n), we consider the problem of identifying the smallest rectangle on the plane which encloses exactly k points of S . A restricted variation of this problem has already been investigated, where the desired rec- tangle is axis-parallel. The first result on this prob- lem appeared in [1] with time and space complexities O(k 2 n log n) and O(kn), respectively. The time com- plexity result is improved to (k 2 n + n log n) in [5,8]. * Corresponding author. E-mail address: [email protected] (S. Das). The space complexities of [8,5] are O(kn) and O(n), respectively. All these algorithms are efficient when k is small. For large k (very close to n), an efficient algo- rithm is proposed in [14]. It runs in O(n + k(n k) 2 ) time and using O(n) space. In d (> 2) dimensions, the algorithm proposed in [14] runs in O(dn + dk · (n k) 2(d 1) ) time using O(dn) space. In all these variations, the points are assumed to be in general po- sition, i.e., no two points lie on the same horizontal or vertical line, and the desired rectangle is isothetic and closed (i.e., enclosed points may lie on the boundary of the rectangle). A similar problem is studied in [12], where n points are distributed on the plane, and the proposed algorithm identifies the smallest circle con- 0020-0190/$ – see front matter 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.ipl.2005.02.013

Upload: sandip-das

Post on 26-Jun-2016

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Smallest k-point enclosing rectangle and square of arbitrary orientation

l

ainingithm arere of

Information Processing Letters 94 (2005) 259–266

www.elsevier.com/locate/ip

Smallestk-point enclosing rectangle and squareof arbitrary orientation

Sandip Dasa,∗, Partha P. Goswamib, Subhas C. Nandya

a Indian Statistical Institute, Kolkata 700 108, Indiab Calcutta University, Kolkata 700 029, India

Received 12 August 2004; received in revised form 8 February 2005

Available online 8 April 2005

Communicated by F.Y.L. Chin

Abstract

Given a set ofn points in 2D, the problem of identifying the smallest rectangle of arbitrary orientation, and contexactly k (� n) points is studied in this paper. The worst case time and space complexities of the proposed algorO(n2 logn + nk(n − k)(n − k + logk)) and O(n), respectively. The algorithm is then used to identify the smallest squaarbitrary orientation, and containing exactlyk points in O(n2 logn + kn(n − k)2 logn) time. 2005 Elsevier B.V. All rights reserved.

Keywords:Levels of arrangement; Plane sweep; Computational geometry; Optimization

rectly

recb-ies-

l po-or

andary],

theon-

1. Introduction

Given a setS of n points in 2D, and an integek (� n), we consider the problem of identifying thsmallest rectangle on the plane which encloses exak points of S. A restricted variation of this problemhas already been investigated, where the desiredtangle is axis-parallel. The first result on this prolem appeared in [1] with time and space complexitO(k2n logn) and O(kn), respectively. The time complexity result is improved to(k2n + n logn) in [5,8].

* Corresponding author.E-mail address:[email protected] (S. Das).

0020-0190/$ – see front matter 2005 Elsevier B.V. All rights reserveddoi:10.1016/j.ipl.2005.02.013

-

The space complexities of [8,5] are O(kn) and O(n),respectively. All these algorithms are efficient whenk

is small. For largek (very close ton), an efficient algo-rithm is proposed in [14]. It runs in O(n + k(n − k)2)

time and using O(n) space. Ind (> 2) dimensions,the algorithm proposed in [14] runs in O(dn + dk ·(n − k)2(d−1)) time using O(dn) space. In all thesevariations, the points are assumed to be in generasition, i.e., no two points lie on the same horizontalvertical line, and the desired rectangle is isotheticclosed (i.e., enclosed points may lie on the boundof the rectangle). A similar problem is studied in [12wheren points are distributed on the plane, andproposed algorithm identifies the smallest circle c

.

Page 2: Smallest k-point enclosing rectangle and square of arbitrary orientation

260 S. Das et al. / Information Processing Letters 94 (2005) 259–266

ob-aryit

en-n-

stall-

onn,t sere-].

.an-

urthe,p-

he

r a

et

n-a

he

ngthe

hef

well.ll

l-

tsew

-

ider

-

-

taining exactlyk points in O(n logn+(n−k)3nε) timefor someε > 0.

We consider the generalized version of this prlem, where the desired rectangle may be of arbitrorientation. Our proposed algorithm is simple andruns in O(n2 logn+kn(n−k)(n−k + logk)) time us-ing O(n) space. The proposed technique can also idtify the smallestk-enclosing square of arbitrary orietation in O(n2 logn+kn(n−k)2 logn) time and O(n2)

space. The time complexity of identifying smallek-enclosing square is comparable with that of smestk-enclosing circle proposed in [12].

The motivation of studying this generalized versicomes from pattern recognition and facility locatiowhere essential features are represented as a poinand the objective is to identify a precise cluster (gion) containing desired number of features [3,4,10

2. Smallest k-point enclosing rectangle

Let S = {p1,p2, . . . , pn} be the set of given pointsThe objective is to identify the smallest area rectgle of arbitrary orientation which contains exactlyk

points ofS. Without loss of generality, we describe omethod under the general position assumptions forpoints inS, i.e., (i) no two points lie on a vertical lineand (ii) no three points are collinear. But the assumtions can be relaxed with a minor modification of talgorithm. The following definition is motivated fromthe fact that many rectangles exist which can covegiven set ofk points.

Definition 1. An exactlyk point enclosing rectanglR is said to be ak-rectangleif there does not exisanother rectangleR′ having area less than that ofR

and containing the same set ofk points.

Let a k-rectanglecontain a designated subsetS′(⊂ S) of k points. In other words, this rectangle ecloses the convex hull ofS′. Thus, each side ofk-rectanglecontains at least one member ofS′. Thefollowing result implies that at least one edge of tk-rectanglecontains two points ofS′.

Result 1 [15]. The minimum area rectangle enclosia convex polygon has a side collinear with one ofedges of the polygon.

t,

Given this characterization of ak-rectangle, we canspecify major steps of the algorithm for identifying tminimum areak-rectangle. We consider each pair opointspi,pj ∈ S, and execute two passes. Below,explain Pass-1of the algorithm, which identifies athe k-rectangles with pi andpj at bottom boundaryThe Pass-2works in a similar manner to identify athe k-rectangles with pi and pj at top boundary. Ineachpass, we maintain the smallest areak-rectanglefound so far. Finally, the smallest areak-rectangleamong the twopasses is reported.

Let Lij denote the line joiningpi andpj , and as-sume thatpi be to the left ofpj on Lij . Let Li andLj be two lines perpendicular toLij , drawn atpi andpj , respectively. This splits the half-plane aboveLij

into three parts, say LEFT, MID and RIGHT. Our agorithm for Pass-1sweeps a lineL parallel toLij inthe upward direction. The following observation lisall possible situations that may take place when a npoint pm is encountered by the sweep lineL. Let SL,SR andSM denote the set of points encountered byL

in LEFT, RIGHT and MID, respectively, up to and includingpm. We assume thatpi,pj ∈ SM . We use|A|to denote the cardinality of the setA.

Observation 1.

(a) If |SL| + |SM | + |SR| < k then nok-rectangle ex-ists withpm at top boundary andpi , pj at bottomboundary.

(b) If |SM | = k andpm ∈ MID , then only onek-rect-angle exists with the line segment[pi,pj ] as itsbottom boundary,pm at top boundary, left andright boundaries are defined by linesLi andLj ,respectively. Here, one need not have to consany point abovepm, and hence the sweep ofL

stops.(c) If |SM | < k and pm ∈ MID , thenmin(k − |SM |,

|SL|, |SR|) + 1 k-rectangles exist withpm at topboundary andpi,pj at bottom boundary.

(d) If |SM | < k andpm ∈ LEFT, then if the rectanglewith one side aligned withLij and the line segment[pm,pj ] as diagonal contains more thankpoints then nok-rectangle exists withpm at topboundary andpi,pj at bottom boundary. Moreover, in the further sweep if another pointp� ap-pears whose projection onL is to the left of that

ij
Page 3: Smallest k-point enclosing rectangle and square of arbitrary orientation

S. Das et al. / Information Processing Letters 94 (2005) 259–266 261

gh

eept

n-

-

lly

ale-

nt

es

x

en-

left

har-

ur-

of

texay.

in

e

e

l-

them

o-d

of pm, then also nok-rectangle exists withpl attop boundary andpi,pj at bottom boundary.

(e) If |SM | < k and pm ∈ LEFT, then if the rectan-gle with one side aligned withLij and the linesegment[pm,pj ] as diagonal containsr (� k)

points thenmin(k − r, |SL∪SM | − r, |SR|) + 1k-rectangles exist withpm at top boundary andpi , pj at bottom boundary.

(f) Results similar to(d) and (e) hold if |SM | < k,pm ∈ RIGHT.

Observation 1 leads to the following result.

Lemma 1. Let pi,pj ,pm ∈ S be three points. Thenumber ofk-rectangles with one edge passing throupi , pj , and its parallel edge passing throughpm, maybe anything from0 to k − 2.

Proof. Let us consider the lineLij as thex-axis.Consider the set of points encountered by the swline L until it reachespm. Among these points, leχ � k be the number of points havingx-coordinatebetween min(x(pi), x(pj ), x(pm)) and max(x(pi),

x(pj ), x(pm)). Thus, in a validk-rectangle, at most(k − χ) points may havex-coordinate less thamin(x(pi), x(pj ), x(pm)). This indicates that the number of possiblek-rectangleswith (pi,pj ) at bottomboundary andpm at its top boundary is(k − χ + 1).As the minimum value ofχ is 3, the maximum number of possiblek-rectangles isk − 2. �2.1. Algorithm

We use geometric duality [6] for systematicaidentifying the point-pairs inS. Here (i) a pointp =(a, b) in the primal plane is mapped to the linep∗:y = ax − b in the dual plane, and (ii) a non-verticline �: y = mx −c in the primal plane is mapped to thpoint �∗ = (m, c) in the dual plane. Immediate consequence of this definition is that a pointp is below(resp. on, above) a line� in the primal plane if andonly if the linep∗ is above (resp. on, below) the poi�∗ in the dual plane.

LetA(H) denote the arrangement of the set of linH = {p∗

i , i = 1,2, . . . , n}, wherep∗i is the dual (line)

of the point pi ∈ S. The vertices inA(H) are de-noted by{vij , i �= j, i = 1,2, . . . , n, j = 1,2, . . . , n},wherev is the dual ofL . We consider each verte

ij ij

vij ∈ A(H), and executePass-1which computes thek-rectangles in the primal plane withpi andpj at itsbottom boundary. Our algorithm does not store thetire arrangement in the memory. The vertices inA(H)

are considered by sweeping a vertical line fromto right through the arrangementA(H) (see [7,11] fordetails of the approach).

During the sweep of the vertical line througA(H), the sweep line status is maintained as anray B of size n. It contains the lines ofH in theorder in which they intersect the sweep line in its crent position, from bottom to top. Each elementB[α](representing a linep∗) is attached with anid of thecorresponding point inS. The arrayB is initialized bythe lines ofH in increasing order of the ordinatestheir intersections with the lineX = −∞. The sweepprocess is guided by an event-queueQ. It is main-tained in the form of a min-heap. It stores the vervij if p∗

i andp∗j are consecutive entries in the arr

B and intersect atvij to the right of the sweep lineDuring the sweep, the next event pointvij is obtainedfrom Q in O(logn) time. The updating ofQ needsanother O(logn) time using the method described[7,11]. The processing ofvij includes swapping twoconsecutive entriesp∗

i andp∗j in the arrayB, and con-

sidering all k-rectangleswith pi andpj at its bottomboundary.

Lemma 2. If B[α] = p∗i andB[α + 1] = p∗

j , then thepoints in the primal plane corresponding to all thlines stored atB[θ ], θ = 1,2, . . . , α − 1, are abovethe lineLij , and the points corresponding to all thlines stored inB[θ ], θ = α + 2, . . . , n, are below theline Lij .

Proof. Follows from the definition of geometric duaity. �

Thus, while processing a vertexvij ∈ A(H) (i.e.,the pair of pointspi and pj in the primal plane),the upward sweep for scanning the points aboveline Lij in increasing order of their distances froLij is equivalent to scanning the elementsB[θ ], θ =α −1, α −2, . . . ,1. In order to analyze the combinatrial complexity ofk-rectangles on the plane, we neethe following definition:

Page 4: Smallest k-point enclosing rectangle and square of arbitrary orientation

262 S. Das et al. / Information Processing Letters 94 (2005) 259–266

e.,

-

ase

-eptsrd

-

s

-r.

ofin

thenray

r

urpre-

ch).e

red.

t

ort

ents

m-

red

Definition 2 [6]. A point q in the dual plane is atlevelθ (0 � θ � n) if and only if there are exactlyθ lines inH that lie strictly belowq. Theθ th levelof A(H) isthe closure of a set of points on the lines ofH whichare exactly at levelθ in A(H).

It also needs to be mentioned that the arrayB actu-ally contains the levels ofA(H) at the current positionof the sweep line.

Lemma 3. While processing a vertexvij at level θ(say) of A(H),

(i) if θ < k, then nok-rectangle exists withpi andpj

at its bottom boundary, and(ii) if θ � k, then the number ofk-rectangles withpi

and pj at bottom boundary is at most(k − 2) ×(θ − k + 1).

Proof. Part (i) of the lemma (i.e.,θ < k) followsfrom Lemma 2 and Observation 1(a). In part (ii) (i.θ � k), for eachB[β], β = θ − k, θ − k − 1, . . . ,0,at mostk − 2 k-rectanglesmay exist with the corresponding point at top-boundary andpi,pj at bottomboundary (by Lemma 2). Hence, the result in this cfollows. �

An integer variableχM is used to store the number of points inSM that are encountered by the sweline L up to the current instant of time. The poinin SL andSR that are encountered during the upwasweep ofL are stored in two link-listsTL andTR . Atan instant of time,TL stores at mostk − χM pointsin SL closest toLi in increasing order of their distances fromLi ; TR also stores at mostk−χM points inSR closest toLj in increasing order of their distancefrom Lj . Initially, bothTL andTR are empty,χM = 2,and the upward sweep ofL starts. For the firstk − 1encountered points, nok-rectangle is generated (byLemma 3(i)). For each of them, if it is in MID thenχM

is incremented. If it is in LEFT or RIGHT it is accumulated inTL or TR , respectively, in unordered manneWhen thekth point is encountered, the reportingk-rectangles starts. We now arrange the elementsTL in increasing order of their distances fromLi . Thisneeds copying the elements in a temporary array,sorting the array and finally copying the sorted ar

in TL. The elements inTR are also arranged in similamanner.

During the execution, we use a scalar variableoptwhich stores the area of the smallestk-rectanglethatis identified up to the present instant of time. The focorners of the corresponding rectangle are alsoserved in another four-tuple, calledopt_rectangle.

Let p be the point faced by the sweep line, whicorresponds toB[θ ] (in the sweep line status array|TL|, |TR| andχM indicates the number of points in threspective sets prior to the insertion ofp in its appro-priate set. The following cases need to be conside

p ∈ LEFT: If |TL| + χM = k, then the point farthesfrom Li is deleted fromTL. Note that,p is notinserted inTL just now; it will be inserted in thenext step. We execute the following steps to repthek-rectangles.• Perform a linear scan to identify the(k−|TL|−

χM)th element inTR (from left).• Next scanTL from its leftmost element andTR

from the(k − |SL| − χM)th element in orderedmanner until (i) the proper position ofp in TL

is reached or (ii) the end ofTR is reached. Ateach move, ak-rectangleis reported. Its bot-tom side passes throughpi and pj , top sidepasses through the pointp; the left and rightsides are bounded by the respective elemin TL andTR .

• The area of each of these rectangles is copared with that of the existingopt. If it is lessthan the existing value ofopt, thenopt is up-dated, and the corresponding rectangle is stoin opt_rectangle.

• In case (i),p is inserted inTL at its proper po-sition. In case (ii), the scanning inTL proceedsfurther to insertp in TL at its proper position.

p ∈ RIGHT: Similar to the earlier case.p ∈ MID: We incrementχM .

If χM = k, then ak-rectangleis reported with bot-tom boundary equal to the line segment[pi,pj ]andp at top boundary, and the sweep ofL stops(by Observation 1(b)).Otherwise, if|TL| + χM = k + 1, then the pointfarthest fromLi is deleted fromTL. Similarly, if|TR| + χM = k + 1, then the point farthest fromL is deleted fromT .

j R
Page 5: Smallest k-point enclosing rectangle and square of arbitrary orientation

S. Das et al. / Information Processing Letters 94 (2005) 259–266 263

or

p-nt.byer-achute

ual)pro-

of

ur

nd-

-f

el-es

-

aling

mfor

desen-theify

g-

ra-oanyoff the

ngee

ngoner

Next, k-rectangles are reported as described fp ∈ LEFT. Here the question of insertingp in anyset does not arise.

Remark 1. We can avoid the general position assumtion (i), if any, by rotating the plane by a small amouWe can relax the general position assumption (ii)allowing more than one (dual) lines pass through a vtex. While processing such a vertex, we consider epair of lines passing through that vertex, and execthe line sweep ofPass-1. The sweep lineL first en-counters the points corresponding to the other (dlines passing through the same vertex, and thenceeds upward.

2.2. Complexity

Theorem 1. Given a2D plane containingn points, thenumber ofk-rectangles on the plane isO(nk(n− k)2).

Proof. By Observation 1(a), nok-rectangleexists forthe verticesvij ∈ A(H) which are at level� k inPass-1of our algorithm. For each vertex ofA(H)

which is at level� k, at most O(k(n−k)) k-rectanglesare reported (by Lemma 3). The number of verticesA(H) which are at level� k is O(n(n − k + 1)) (seeCorollary 5.17 of [13]). Thus, at most O(nk(n − k)2)

k-rectangles can be reported inPass-1of all the ver-tices inA(H). Similarly, in Pass-2of all the verticesin A(H) can also generate at most O(nk(n − k)2)

k-rectangles. �Theorem 2. The time and space complexities of oalgorithm areO(n2 logn + nk(n − k)(n − k + logk))

andO(n), respectively.

Proof. The scanning of all the vertices ofA(H) usinga vertical sweep line needs O(n2 logn) time. We nowanalyze the time complexity ofPass-1for processinga vertexvij at a levelα (� k).

During the upward sweep, the points correspoing to B[α − 1],B[α − 2], . . . ,B[α − k − 1] are onlyaccumulated inTL or TR (without maintaining the order). This needs O(k) time. Prior to the processing oB[α − k], we arrange the accumulated elements inTL

andTR in ordered manner. This needs sorting theements inTL andTR separately, and hence it requirO(k logk) time.

Next, we start reporting thek-rectangleswith pi

and pj at bottom boundary. For each pointp cor-responding toB[α − k − i], i = 1,2, . . . , (α − k),we examine all possiblek-rectangles with p at itstop boundary, and finally, insertp in the respectivelist at its proper position. This needs at most O(k)

time. Thus, the total time required for processingvij

is O(k + k logk + k(n − k)) in the worst case.As the combinatorial complexity of(� k)-levels

is O(n(n − k)), the total time complexity of our algorithm is O(nk(n − k)(n − k + logk)). The spacecomplexity result follows from the fact that the totarrangement is not maintained in the memory durthe execution of the algorithm.�

3. Smallest k point enclosing square

In this section, we show that our above algorithcan easily be used to design a simple algorithmreporting the smallest arbitrarily orientedk point en-closing square. Ak point enclosing square is callea k-square if its size is smallest among all squarcontaining the same set of points. Without loss of gerality, we assume that the points appearing onboundary of a square are inside it. We now classthe k-squares with respect to the number of pointsη

present on its boundary. Obviously, nok-square ispossible withη = 0 or 1. The only possibility withη = 2 is that, the two points appear at the two diaonally opposite corners of the correspondingk-square(see Fig. 1(a)). Below, we list the possible configutions of ak-squarewith η = 3 and 4. It also needs tbe mentioned that we need not have to considerconfiguration withη > 4, since a suitable selectiona subset among its boundary points leads to one oconfigurations which we have dealt forη � 4.

Two instances ofη = 3 may produce a validk-square:

(i) Two points on one side of the correspondik-squareand one point on its parallel side (sFig. 1(b)).

(ii) One point at a corner of the correspondik-square, and the other two points lie on the twadjacent sides of the diagonally opposite cor(see Fig. 1(c)).

Page 6: Smallest k-point enclosing rectangle and square of arbitrary orientation

264 S. Das et al. / Information Processing Letters 94 (2005) 259–266

Fig. 1. Different possibilities ofk-squares.

theoesith

ofain

one

be

-

et,

hees

if

r

e

x-f

con-

aret

e

nts

f

or

in-

thee

ine

For otherk point enclosing squares withη = 3, wecan push them in the direction perpendicular toempty side such that the point on its opposite side ginside the square. Thus, we have a configuration wη = 0, 1 or 2. Thus a smallerk-squarewill always ex-ist with the same set ofk points.

For η = 4, the possible configurations for ak-squareare as follows:

(i) One side of the said square contains two pointsS, its parallel side and one adjacent side contone point each (see Fig. 1(d)).

(ii) Each side of the said square contains exactlypoint ofS (see Fig. 1(e)).

For all other configurations of thek point enclosingsquares withη = 4, a smaller square can alwaysobtained with the same set of points inside it.

Consider the type (i)k-squarewith η = 3. Its oneside contains two pointspi and pj , the corresponding parallel side contains a pointpm, but the other twomutually parallel sides do not contain any point. Lit contains a subsetS′ ⊂ S of k points inside it. Thusif we slide it horizontally, it will remain ak-squarecontaining the same setS′ of points and having thesame area. We do minimum horizontal sliding of tk-squaresuch that one of its vertical sides toucha point in S. If it is a member inS′, it is a type (i)k-squarewith η = 4 (see Fig. 1(d)). Suchk-squaresare identified in Procedure A, stated below. But,it is a memberpr ∈ S \ S′, then it gives birth to asquare containingk+1 points. We first move the othevertical side to touch with the point inS′. Thus, itbecomes a rectangle withk + 1 points with one sidepassing throughpi andpj , and each of the other thresides passing through exactly one point, namelyp�,pm andpr , respectively. In Procedure B, we shall etract ak-squarefrom such a configuration which is otype (ii) with η = 4 as shown in Fig. 1(e).

Lemma 4. Given four pointspi,pm,p�,pr ∈ S, thenumber of squares whose each of the four sidestains one of these four points is at most2.

Proof. Let the lines which form the desired squareLi , Lm, L� andLr , whereLa pass through the poinpa , wherea = i,m, �, r (see Fig. 1(e)). Also let thgradient of the linesLi and Lm be µ and thereforethe gradient of the linesL� and Lr be − 1

µ. Let A,

B, C andD denote the points of intersection of (Li

andLr ), (Lr andLm), (Lm andL�) and (L� andLi ),respectively. Equating the length of the line segme[A,B], [A,D], we get a quadratic equation inµ. Ifthe roots of this equation are imaginary, nok-squareispossible. Otherwise, at most twok-squares may exist.For each of them, we need to check whether

(i) pi , pr , pm andp� appear on the sidesDA, AB,BC, andCD, respectively, and

(ii) still it contains exactlyk points. �Remark 2. Eachk-squaremust satisfyη = 4. Notethat, thek-rectangles withη = 2 and case (ii) ofη = 3can be considered as degenerate cases of thek-rect-angles withη = 4.

3.1. Algorithm

Forη = 2, we consider each pair of pointspi,pj ∈S, and test whether the square with[pi,pj ] as diago-nal contains exactlyk points by using the method osimplex range searching [9]. Ifyes, we compare itsarea with the existing optimum. Thek-squares withη = 3 andη = 4 are identified using the method fidentifying k-rectangles with minor modification asdescribed below.

We describe two procedures for identifying thestances withη = 3 and η = 4, respectively. As inthe earlier problem, we consider the vertices ofarrangementA(H). At each vertex (representing a linL ), the upward (resp. downward) sweep of a l

ij
Page 7: Smallest k-point enclosing rectangle and square of arbitrary orientation

S. Das et al. / Information Processing Letters 94 (2005) 259–266 265

s-fies

he

nt

ei-

thery

intsep

p

-

ser

cha

ter-

g

f

-i)

he

-pings ad-us,

r

u-

alidd-

ngting

en-

-

ndonswe

L parallel toLij is also performed as earlier and uing the same data structure. Procedure A identithe smallestk-squarewith both pi,pj at its bottomboundary, and some other pointpm at its top bound-ary. Procedure B identifies the smallestk-squarewitheitherpi or pj at its bottom boundary, and each of tother three sides contains a point ofS.

Procedure A. Let the length of the line segme[pi,pj ] = r . Initially, we consider ther × r squarewith one side aligned with[pi,pj ]. Using simplexrange searching, wecountthe number of points insidthat square. If it exceedsk, then this procedure termnates without computing anyk-square. If it is equalto k then also the procedure terminates reportingk-squarewhose two corners on the bottom boundacontainpi andpj . But, if thecountis less thank, thefollowing steps are executed.

Step A1. Our upward sweep proceeds, and the poin LEFT and RIGHT, encountered by the sweline L, are accumulated inTL and TR . For thepoints in MID, χM is incremented. The sweecontinues until it hits a pointpm whose distancefrom Lij is greater than or equal tor .

Step A2. Now, the median find algorithm [2] is invoked for the points inTL to collect onlyk points(if available) which are closest toLi . They are alsoorderly stored inTL. Similarly, among the pointin TR only k points are stored in increasing ordof distances fromLj .

Step A3. The upward sweep continues and for eaencountered pointpm, we test the existence ofk-squarewith pi,pj at bottom boundary andpm

at top boundary as mentioned below. Sweepminates as soon as ak-squareis found.• Let the distance ofpm from Lij is equal toh.

We sequentially walk from left to right alonTL. For each elementπ ∈ TL (corresponding tothe projection of a pointpa ∈ SL on Lij ) wechoose a pointφ on Lij such that the length othe interval[π,φ] = h � [π,pj ]. If the h × h

square withpi,pj at its bottom boundary,pm

at top boundary, andpa at its left boundary contains exactlyk points, it is an instance of case (with η = 4. This can be observed fromTR dur-ing the walk.

Before describing Procedure B for identifying tk-squaresof type (ii) with η = 4, we need the follow-ing important observation.

Observation 2. Let R be the optimumk-squarecon-taining one designated point ofS in each of its boundaries. If we rotate each edge by the same angle keethe designated points on its boundaries, it becomerectangle. We continue rotation till one of its bounaries hit another point inside/outside the square. Thwe have ak-rectangleor a (k+1)-rectanglewhose oneside contains two points ofS and each of the othethree sides contains exactly one point ofS. In otherwords, thisk-rectangleor (k + 1)-rectangle, on rota-tion, produces the desired(optimum) k-square.

Thus, for each pair of points(pi,pj ), we identifyall k-rectangles and(k + 1)-rectangles with (pi,pj )

at one side. For each of these rectangleR, we executefollowing steps:

Procedure B.

Step B1. Let the other three sides ofR containpr,pm,p�, respectively. We consider two quadrples {pi,pr ,pm,p�} and {pj ,pr ,pm,p�}. Foreach quadruple, we compute the smallest vsquare with those four points at its four bounaries respectively using Lemma 4.

Step B2. Next, we apply simplex range searchitechnique to each of these squares for teswhether it is ak-squareor not. If yes, it is a can-didate for the optimumk-square.

It needs to be mentioned that, all the rectangles gerated in this process withpi (resp.pj ) at bottom-left(resp. bottom-right) corner will generate thek-squaresof type (ii) with η = 3 by applying required rotation.

3.2. Complexity

Theorem 3. Our proposed algorithm correctly computes the smallestk-squarein O(n2 logn+nk(n−k)2 ·logn) time usingO(n2) space.

Proof. The correctness follows from Remark 2, athe fact that we have considered all the configuratiwith η = 4 including the degenerate cases. Though

Page 8: Smallest k-point enclosing rectangle and square of arbitrary orientation

266 S. Das et al. / Information Processing Letters 94 (2005) 259–266

with

hatd in

tsto

e-ing

rthachin-

e-es

12

y-A,

in

o-, in:88,

y--

ry,

n-15

ding1–

tings

5.rdic

n-

andss,

s

ing4.

have considered the only case ofη = 2, i.e., two pointson the diagonally opposite corners of ak-rectangleseparately, it can be generated by Procedure Blittle modification.

In the time complexity analysis, we use the fact tthe simplex range counting query can be performeO(logn) time using O(n2) time and space [9].

For η = 2, we consider all possible pair of poin(pi,pj ) ∈ S, and perform simplex range searchingtest whether the square with(pi,pj ) as diagonal is ak-square. This needs O(n2 logn) time.

Using almost a similar argument of proving Thorem 2, the worst case time required for executProcedure A is O(n2 logn+nk(n−k)(n−k+ logk)).

In Procedure B, all thek-rectangles and(k + 1)-rectangles are considered. Each of them gives bito at most four squares at Steps B1 and B2. For esquare, the simplex range counting query is to bevoked. As the total number of possiblek-rectanglesis O(nk(n − k)2) (see Theorem 1), the total time rquired for execution of Procedure B for all the verticof A(H) is O(nk(n − k)2 logn). �

References

[1] A. Aggarwal, H. Imai, N. Katoh, S. Suri, Findingk point withminimum diameter and related problems, J. Algorithms(1991) 38–56.

[2] A.V. Aho, J.E. Hopcroft, J.D. Ullman, The Design and Analsis of Computer Algorithms, Addison-Wesley, Reading, M1974.

[3] H.C. Andrews, Introduction to Mathematical TechniquesPattern Recognition, Wiley-Intersciences, New York, 1972.

[4] T. Asano, B. Bhattacharya, M. Keil, F. Yao, Clustering algrithms based on maximum and minimum spanning treesProc. 4th Annual Symp. on Computational Geometry, 19pp. 252–257.

[5] A. Datta, H.-P. Lenhof, C. Schwarz, M. Smid, Static and dnamic algorithms fork-point clustering problems, J. Algorithms 19 (1995) 474–503.

[6] H. Edelsbrunner, Algorithms in Computational GeometSpringer, Berlin, 1987.

[7] H. Edelsbrunner, E. Welzl, Constructing belts in two-dimesional arrangements with applications, SIAM J. Comput.(1986) 271–284.

[8] D. Eppstein, J. Erickson, Iterated nearest neighbors and finminimal polytopes, Discrete Comput. Geom. 11 (1994) 32350.

[9] P.P. Goswami, S. Das, S.C. Nandy, Triangular range counquery in 2D and its application in findingk nearest neighborof a line segment, Comput. Geom. 29 (2004) 163–175.

[10] J.A. Hartigan, Clustering Algorithms, Wiley, New York, 197[11] R. Janardan, F.P. Preparata, Widest-corridor problems, No

J. Comput. 1 (1994) 231–245.[12] J. Matoušek, On geometric optimization with few violated co

straints, Discrete Comput. Geom. 14 (1995) 365–384.[13] M. Sharir, P.K. Agarwal, Davenport–Schinzel Sequences

their Geometric Applications, Cambridge University PreNew York, 1995.

[14] M. Segal, K. Kedem, Enclosingk points in the smallest axiparallel rectangle, Inform. Process. Lett. 65 (1998) 95–99.

[15] G. Toussaint, Solving geometric problems with the rotatcalipers, in: Proc. IEEE MELECON’83, 1983, pp. A10.02/1–