Download presentation

Presentation is loading. Please wait.

Published byChristy Hopps Modified over 2 years ago

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)

2
Introduction w This essay gives an algorithm for solving the Rectangle Enclosure problem in time and O(n) space w n is the number of rectangles and q is the number of the required rectangle pairs

3
Topics of Presentation w Introduction w Rectangle Enclosure and Dominance w A Two-Dimensional Subproblem w Time and Space Analysis

4
Introduction Given a set of n rectangles in the plane, with sides parallel to the coordinate axes, find all q pairs of rectangles such that one rectangle of the pair encloses the other w What is the Rectangle Enclosure problem ? Given a set of n rectangles in the plane, with sides parallel to the coordinate axes, find all q pairs of rectangles such that one rectangle of the pair encloses the other w The suggested solution achieves time using O(n) space

5
Rectangle Enclosure and Dominance w We begin by transforming the rectangle enclosure problem into an equivalent one, which is easier to describe and understand w Let be a set of iso- oriented rectangles in the plane w For each i=1,…,n

6
Transforming to Point Dominance problem w iff all the following hold:

7
w This is equivalent to: which expresses the relation “<“ of dominance between two four-dimensional points w Thus, after mapping each from R to its corresponding point in 4D we need to solve

8
The Point Dominance Problem in 4D w Definition: p
{
"@context": "http://schema.org",
"@type": "ImageObject",
"contentUrl": "http://images.slideplayer.com/11/3312049/slides/slide_8.jpg",
"name": "The Point Dominance Problem in 4D w Definition: p

9
Solving the dominance problem w Input : a set Required Output : all pairs of points (p,q) where p < q w Notation : the i-th coordinate of a point p will be donated by w Preliminary step : sort the elements of S by values in increasing order If two points have equal coordinates sort by etc. w Strategy : Divide & Conquer

10
Algorithm Dominance w D1. ( Devide ) Partition S into S1 S2 where, w D2. ( Recur ) Solve the point-dominance problem on S 1 and S 2 separately w D3. ( Merge ) Find all pairs where,

11
Explaining the correctness of the algorithm w All dominance pairs within S 1 and S 2 will be found in D2. ( Recur ) w If there exists a dominance pair in which one point is from S 1 ( say p ) and the other is from S 2 ( say q ), than it must be that p < q, since by construction

12
Implementing D3 step - Merge w If and than by construction w Thus iff for l=2,3,4 w We have reduced the 4D problem to a 3D problem w let be the median of w Strategy : Divide & Conquer again

13 Algorithm Merge w M1. ( devide ) Partition S 1 into S 11 S 12 and S 2 into S 21 S 22 where S 12 = S 1 -S 11 S 22 = S 2 -S 21 w M2. ( Recur ) Solve the merge problem on the set pairs (S 11,S 21 ) and (S 12,S 22 ) w M3. (Combine) Find all pairs p i

{ "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3312049/slides/slide_13.jpg", "name": "Algorithm Merge w M1.", "description": "( devide ) Partition S 1 into S 11 S 12 and S 2 into S 21 S 22 where S 12 = S 1 -S 11 S 22 = S 2 -S 21 w M2. ( Recur ) Solve the merge problem on the set pairs (S 11,S 21 ) and (S 12,S 22 ) w M3. (Combine) Find all pairs p i

14
Why does that work? w By division : S = S 11 S 12 S 21 S 22 w Within each S ij the dominance pairs are found at step D2 since they are contained in S 1 and S 2 w 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 u 1 ( if u 1 are the same a secondary sort by u 2 is done etc. )

15
The way all cases are processed w The solution includes the following cases: (S 21,S 22 ) and (S 11,S 12 ) are processed in D2 since and (S 11,S 21 ) and (S 12,S 22 ) are processed in M2 ( Recur in Merge ) (S 11,S 22 ) is processed in M3 ( Combine in Merge ) (S 12,S 21 ) need not be considered because for each and we have and

16
Implementation of the Combine w The key operation of the entire task is therefore the implementation of step M3 ( the combine ) w Again we reduce the dimension of the problem, since the Combine step is a 2D merge problem ( in u 3 and u 4 )

17
A Two-Dimensional Subproblem w Initial preprocessing : Construct a quadruply threaded list ( QTL ) with bidirectional links, for S. w 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. w The construction of the QTL takes O(nlogn) time and O(n) space

18
Explaining the algorithm for Combine w We traverse the points in S 22 by the sort sorting order that u 3 constrains ( NEXT 32 ) w For each such point q in S 22 we find all the points in S 11 which is dominated by it in u 3. This is done by traversing S11 by the sort sorting order that u 3 constrains ( NEXT31 )

19
w For each such point p we insert u 4 (p) into the sorted list L. w When we reach p such that u 3 (p) > u 3 (q) we print all the points is S 11 which are dominated by q, by traversing L from the beginning until reaching a point p’ for which u 4 (p’) > u 4 (q)

20
Algorithm Combine J1 = 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]; }

21
Example

22
The Crucial task of the procedure w How can we insert u 4 [j 1 ] into L maintaining sorted order efficiently? w The naive approach would yield time w Using AVL Trees we can achieve O(|S 1 |log|S 11 |) w We can take advantage of the fact that the points are known in advance to achieve O(|S 1 |) total time

23
Creating Schedule Of Insertion Into L in O(|S 11 |) w The Basic Idea : Let’s take a look at the point p in S 11 which has the highest u 3 value. We reach p after we processed all the other points from S 11. It should be placed in L after PRED4[L] w Thus we can use PRED4 from the QTL in order to determine the schedule of insertion into L

24
Algorithm insertion schedule l = last(u3 list) while ( PRED3[l] != BEG3 ) { NEXT4[PRED4[l]] = NEXT4[l]; PRED4[NEXT4[l]] = PRED4[l]; l = PRED3[l]; } w Final L is PREV4

25
Example

26
Time and Space Analysis w Space All the processing is done in a place proportional by a constant to the QTL arrays, yielding O(n) space complexity w Time Notations: D(n) = The time complexity of the dominance algorithm M 3 (r,s) = The time complexity of the merge algorithm M 2 (r’,s’) = The time complexity of the combine algorithm

27
Time Complexity - Dominance w Let |S|=n be an even number for simplicity w D(n) = 2D(n/2) + M 3 (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

28
Time Complexity - Merge w Let r be an even number for simplicity w 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 S 1 and S 2 using the QTL

29
Time Complexity - Combine w M 2 (r’,s’) = T( insertion schedule ) + T( traversing S 11 and S 22 elements ) + T( insertions to L ) + T( printing of dominance pairs ) = O(r’) + O(r’+s’) + O(r’) + O(q) = O(r’+s’+q) w 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 that M 2 (r’,s’) = O(r’+s’) for the calculations

30
Solving the equations M 3 (r,s) = M 3 (r/2,m) + M 3 (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

31
Next Steps There are variations of this algorithm which improve the time complexity on account of the space complexity

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google