Suppose we pre sort the points in s with respect to

This preview shows page 70 - 78 out of 191 pages.

Suppose we pre-sort the points in S with respect to their x -co-ordinates. This takes time Θ( n log n ) . Divide: Let the first n/ 2 points be denoted S 1 and let the last n/ 2 points be denoted S 2 . Conquer: Recursively solve the subproblems defined by the two instances S 1 and S 2 . Combine: Given the non-dominated points in S 1 and the non-dominated points in S 2 , how do we find the non-dominated points in S ? Observe that no point in S 1 dominates a point in S 2 . Therefore we only need to eliminate the points in S 1 that are dominated by a point in S 2 . This can be done in time O ( n ) . D.R. Stinson (SCS) CS 341 Winter, 2017 70 / 191
Image of page 70

Subscribe to view the full document.

Divide-and-Conquer Algorithms Non-dominated Points Non-dominated Points Algorithm: Non-dominated ( S ) comment: the n points in S are pre-sorted WRT their x -co-ordinates if n = 1 then return ( { S [1] } ) else { Q [1] , . . . , Q [ ] } ← Non-dominated ( { S [1] , . . . , S [ b n/ 2 c ] } ) { ( R [1] , . . . , R [ m ] } ← Non-dominated ( { S [ b n/ 2 c + 1] , . . . , S [ n ] } ) i 1 while i and Q [ i ] .y > R [1] .y do i i + 1 return ( { Q [1] , . . . , Q [ i - 1] , R [1] , . . . , R [ m ] } ) D.R. Stinson (SCS) CS 341 Winter, 2017 71 / 191
Image of page 71
Divide-and-Conquer Algorithms Closest Pair Closest Pair Problem Closest Pair Instance: a set Q of n distinct points in the Euclidean plane, Q = { Q [1] , . . . , Q [ n ] } . Find: Two distinct points Q [ i ] = ( x, y ) , Q [ j ] = ( x 0 , y 0 ) such that the Euclidean distance p ( x 0 - x ) 2 + ( y 0 - y ) 2 is minimized. D.R. Stinson (SCS) CS 341 Winter, 2017 72 / 191
Image of page 72

Subscribe to view the full document.

Divide-and-Conquer Algorithms Closest Pair Closest Pair: Problem Decomposition Suppose we presort the points in Q with respect to their x -coordinates (this takes time Θ( n log n ) ). Then we can easily find the vertical line that partitions the set of points Q into two sets of size n/ 2 : this line has equation x = Q [ m ] .x , where m = n/ 2 . The set Q is global with respect to the recursive procedure ClosestPair1 . At any given point in the recursion, we are examining a subarray ( Q [ ] , . . . , Q [ r ]) , and m = b ( + r ) / 2 c . We call ClosestPair1 (1 , n ) to solve the given problem instance. D.R. Stinson (SCS) CS 341 Winter, 2017 73 / 191
Image of page 73
Divide-and-Conquer Algorithms Closest Pair Closest Pair: Solution 1 Algorithm: ClosestPair1 ( ‘, r ) if = r then δ ← ∞ else m ← b ( + r ) / 2 c δ L ClosestPair1 ( ‘, m ) δ R ClosestPair1 ( m + 1 , r ) δ min { δ L , δ R } R SelectCandidates ( ‘, r, δ, Q [ m ] .x ) R SortY ( R ) δ CheckStrip ( R, δ ) return ( δ ) D.R. Stinson (SCS) CS 341 Winter, 2017 74 / 191
Image of page 74

Subscribe to view the full document.

Divide-and-Conquer Algorithms Closest Pair Selecting Candidates from the Vertical Strip Algorithm: SelectCandidates ( ‘, r, δ, xmid ) j 0 for i to r do if | Q [ i ] .x - xmid | ≤ δ then j j + 1 R [ j ] Q [ i ] return ( R ) D.R. Stinson (SCS) CS 341 Winter, 2017 75 / 191
Image of page 75
Divide-and-Conquer Algorithms Closest Pair Checking the Vertical Strip Algorithm: CheckStrip ( R, δ ) t size ( R ) δ 0 δ for j 1 to t - 1 do for k j + 1 to min { t, j + 7 } do x R [ j ] .x x 0 R [ k ] .x y R [ j ] .y y 0 R [ k ] .y δ 0 min n δ 0 , p ( x 0 - x ) 2 + ( y 0 - y ) 2 o return ( δ 0 ) D.R. Stinson (SCS) CS 341 Winter, 2017 76 / 191
Image of page 76

Subscribe to view the full document.

Divide-and-Conquer Algorithms
Image of page 77
Image of page 78

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern