+ All Categories
Home > Documents > An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T....

An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T....

Date post: 14-Dec-2015
Category:
Upload: christy-hopps
View: 218 times
Download: 2 times
Share this document with a friend
31
An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)
Transcript
Page 1: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

An Improved Algorithm for the Rectangle Enclosure

Problem

Anatoli Uchitel

From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Page 2: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Introduction

This essay gives an algorithm for solving the Rectangle Enclosure problem in

time and O(n) space

n is the number of rectangles and q is the number of the required rectangle pairs

)qnlogn(O 2

Page 3: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Topics of Presentation

Introduction

Rectangle Enclosure and Dominance

A Two-Dimensional Subproblem

Time and Space Analysis

Page 4: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Introduction What is the Rectangle Enclosure

problem ?Given a set of n rectangles in the Given a set of n rectangles in the plane, with sides parallel to the plane, with sides parallel to the coordinate axes , find all q pairs of coordinate axes , find all q pairs of rectangles such that one rectangle of rectangles such that one rectangle of the pair encloses the otherthe pair encloses the other

The suggested solution achieves time using O(n) space)qnlogn(O 2

Page 5: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Rectangle Enclosure and Dominance

We begin by transforming the rectangle enclosure problem into an equivalent one, which is easier to describe and understand

Let be a set of iso-oriented rectangles in the plane

For each i=1,…,n

}r,...,r,r{R n21

]y,y[]x,x[r )i(2

)i(1

)i(2

)i(1i

Page 6: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Transforming to Point Dominance problem

iff all the following hold:ji rr )j(

1)i(

1 xx

)i(2

)j(2 yy

)j(1

)i(1 yy

)i(2

)j(2 xx

)i(1x )j(

1x )j(2x )i(

2x

)i(1y

)j(1y

)j(2y

)i(2y

Page 7: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

This is equivalent to:

which expresses the relation “<“ of dominance between two four-dimensional points

Thus, after mapping each from R to its corresponding point in 4D we need to solve

)i(1

)j(1 xx

)i(2

)j(2 xx

)i(1

)j(1 yy

)i(2

)j(2 yy

ij pp

ir

Page 8: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

The Point Dominance Problem in 4D

Definition: p<q iff for i=1,2,3,4 where ui(p) is the i-th coordinate of p

Given a set , for each Given a set , for each find find

4n21 R}p,...,p,p{S

Spi S}pp|Sp{D ii

(q)u(p)u ii

Page 9: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Solving the dominance problem Input : a set

Required Output : all pairs of points (p,q)where p < q

Notation : the i-th coordinate of a point p will be donated by

Preliminary step : sort the elements of S by values in increasing orderIf two points have equal coordinates sort by etc.

Strategy : Divide & Conquer

4n21 R}p,...,p,p{S

)p(uin

1ii}p{

)p(u1

1u2u

Page 10: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Algorithm Dominance

D1. ( Devide ) Partition S into S1 S2 where ,

D2. ( Recur ) Solve the point-dominance problem on S1 and S2 separately

D3. ( Merge ) Find all pairs where ,

}p,...,p,p{S 2/n211 }p,...,p{S n12/n2

ji pp 1i Sp 2j Sp

Page 11: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Explaining the correctness of the algorithm

All dominance pairs within S1 and S2 will be found in D2. ( Recur )

If there exists a dominance pair in which one point is from S1 ( say p ) and the other is from S2 ( say q ) , than it must be that p < q , since by construction )q(u)p(u 11

Page 12: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Implementing D3 step - Merge

If and than by construction

Thus iff for l=2,3,4 We have reduced the 4D problem to a 3D

problem let be the median of Strategy : Divide & Conquer again

1Sp 2Sq)q(u)p(u 11

)q(u)p(u 1l qp

2u }Sp|(p){u 22

Page 13: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Algorithm Merge

M1. ( devide ) Partition S1 into S11 S12 and S2 into S21 S22 whereS12 = S1-S11 S22 = S2-S21

M2. ( Recur ) Solve the merge problem on the set pairs (S11,S21) and (S12,S22)

M3. (Combine) Find all pairs pi<pj such that and

}u)p(u|Sp{S 22111 }u)p(u|Sp{S 22221

11i Sp 22j Sp

Page 14: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Why does that work? By division : S = S11 S12 S21 S22

Within each Sij the dominance pairs are found at step D2 since they are contained in S1 and S2

About Dominant pairs where the points are from different subsets Sij we should notice that we should only examine cases where the dominant point is from a higher indexed set since the points are sorted by increasing order of u1 ( if u1 are the same a secondary sort by u2 is done etc. )

Page 15: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

The way all cases are processed

The solution includes the following cases:• (S21,S22) and (S11,S12) are processed in D2

since and• (S11,S21) and (S12,S22) are processed in M2

( Recur in Merge )• (S11,S22) is processed in M3 ( Combine in

Merge )• (S12,S21) need not be considered because for

each and we have and)p(u)p(u j1i1 )(pu u )(pu j22i2

S S 22i S S 11i

S p 12i S p 21j

Page 16: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Implementation of the Combine

The key operation of the entire task is therefore the implementation of step M3 ( the combine )

Again we reduce the dimension of the problem, since the Combine step is a 2D merge problem ( in u3 and u4 )

Page 17: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

A Two-Dimensional Subproblem Initial preprocessing : Construct a

quadruply threaded list ( QTL ) with bidirectional links, for S.

for each p in S there is a node containing all the coordinate values and 8 pointers NEXTi,PREVi for i=1,2,3,4 that describe the ordering by the appropriate coordinates.

The construction of the QTL takes O(nlogn) time and O(n) space

Page 18: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Explaining the algorithm for Combine

We traverse the points in S22 by the sort sorting order that u3 constrains ( NEXT32 )

For each such point q in S22 we find all the points in S11 which is dominated by it in u3. This is done by traversing S11 by the sort sorting order that u3 constrains ( NEXT31 )

Page 19: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

For each such point p we insert u4(p) into the sorted list L.

When we reach p such that u3(p) > u3(q) we print all the points is S11 which are dominated by q, by traversing L from the beginning until reaching a point p’ for which u4(p’) > u4(q)

Page 20: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Algorithm CombineJ1 = BEG31; j2 = BEG32; // initialization

while ( j2 != null){

if ((j1!=null) && (u3[j1] <= u3[j2])){

// if j2 dominates j1 by u3

L->insert_maintaining_order(u4[j1]);

j1=NEXT3[j1];

} else { // j2 doesn’t dominate j1

l = BEGL;

// print all the points in S11 which are dominated in both u3 and u4 by j2

while ((l!=null) and (u4[j2]>=u4[l])){

print(j2,l);

l = NEXTL[l];

}

j2 = NEXT3[j2];

}

}

Page 21: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Example

Page 22: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

The Crucial task of the procedure

How can we insert u4[j1] into L maintaining sorted order efficiently?

The naive approach would yield time

Using AVL Trees we can achieve O(|S1|log|S11|)

We can take advantage of the fact that the points are known in advance to achieve O(|S1|) total time

)|sO(| 211

Page 23: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Creating Schedule Of Insertion Into L in O(|S11|) The Basic Idea :

Let’s take a look at the point p in S11 which has the highest u3 value.We reach p after we processed all the other points from S11.It should be placed in L after PRED4[L]

Thus we can use PRED4 from the QTL in order to determine the schedule of insertion into L

Page 24: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Algorithm insertion schedule

l = last(u3 list)

while ( PRED3[l] != BEG3 ) {

NEXT4[PRED4[l]] = NEXT4[l];

PRED4[NEXT4[l]] = PRED4[l];

l = PRED3[l];

}

Final L is PREV4

Page 25: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Example

Page 26: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Time and Space Analysis Space

All the processing is done in a place proportional by a constant to the QTL arrays, yielding O(n) space complexity

TimeNotations:• D(n) = The time complexity of the dominance

algorithm• M3(r,s) = The time complexity of the merge

algorithm• M2(r’,s’) = The time complexity of the combine

algorithm

Page 27: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Time Complexity - Dominance

Let |S|=n be an even number for simplicity D(n) = 2D(n/2) + M3(n/2,n/2) + O(n)

• D2. Recur step for S1 and S2• D3. The Merge step on (S1,S2)• D1. The split of S to S1 and S2

Page 28: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Time Complexity - Merge

Let r be an even number for simplicity M3(r,s) = M3(r/2,m) + M3(r/2,s-m) +

M2(r/2, max(m,s-m)) + O(r+s)

• M2. Recur step for and• M3. Combine on• M1. Splitting S1 and S2 using the QTL

)S,(S 2111)S,(S 2212

)S,(S 2211

Page 29: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Time Complexity - Combine M2(r’,s’) = T(insertion schedule) + T(traversing

S11 and S22 elements) + T(insertions to L) + T(printing of dominance pairs) = O(r’) + O(r’+s’) + O(r’) + O(q) = O(r’+s’+q)

Since the q dominance pairs are printed only once in the entire algorithm we can add O(q) to the final time complexity and say thatM2(r’,s’) = O(r’+s’) for the calculations

Page 30: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Solving the equationsM3(r,s) = M3(r/2,m) + M3(r/2,s-m) + O(r+s)

Since the first parameter of M3 is always

divided by 2 , we can make a bound

M3(r,s) = O((r+s)log(r)) = O((r+s)log(r+s))

Thus, D(n) = 2D(n/2) + O(nlogn) ,which

yields D(n) =

Keeping in mind the debt for printing the pairs

of dominance points we get that the final time

complexity is

n)O(nlog2

q)nO(nlog2

Page 31: An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)

Next Steps

There are variations of this algorithm which

improve the time complexity on account of

the space complexity


Recommended