310 likes | 440 Views
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
E N D
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
Topics of Presentation • Introduction • Rectangle Enclosure and Dominance • A Two-Dimensional Subproblem • Time and Space Analysis
Introduction • 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 • The suggested solution achieves time using O(n) space
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
Transforming to Point Dominance problem • iff all the following hold:
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
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 find
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
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 ,
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
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
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
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. )
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
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 )
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
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 )
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)
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]; } } Algorithm Combine
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
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
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
Time and Space Analysis • SpaceAll 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
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
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
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
Solving the equations M3(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
Next Steps There are variations of this algorithm which improve the time complexity on account of the space complexity