course-slide-A.pdf

# Suppose we pre sort the points in s with respect to

• 191

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

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
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

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
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

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
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

Subscribe to view the full document.

Divide-and-Conquer Algorithms
• Fall '09
• ?

{[ snackBarMessage ]}

###### "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

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern