cs lunch mary allen wilkes wednesday 12 15 kendade 307
play

CS Lunch Mary Allen Wilkes Wednesday 12:15 Kendade 307 2 Divide - PowerPoint PPT Presentation

1 CS Lunch Mary Allen Wilkes Wednesday 12:15 Kendade 307 2 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common usage.


  1. 1 CS Lunch Mary Allen Wilkes Wednesday 12:15 Kendade 307 2 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common usage. Break up problem of size n into two equal parts of size n/2. Solve two parts recursively. Combine two solutions into overall solution in linear time. 3 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Fundamental geometric primitive. Graphics, computer vision, geographic information systems, molecular modeling, air traffic control. Brute force. Check all pairs of points p and q with Θ (n 2 ) comparisons. Slides14 - ClosestPairPoints.key - March 20, 2019

  2. 4 Closest Pair of Points 1-dimensional version 5-1 Closest Pair of Points 1-D version. Sort points For each point, find the distance between a point and the point that follows it. Remember the smallest. 5-2 Closest Pair of Points 1-D version. Cost Sort points For each point, find the distance between a point and the point that follows it. Remember the smallest. Slides14 - ClosestPairPoints.key - March 20, 2019

  3. 5-3 Closest Pair of Points 1-D version. Cost Sort points O(n log n) For each point, find the distance between a point and the point that follows it. Remember the smallest. 5-4 Closest Pair of Points 1-D version. Cost Sort points O(n log n) For each point, find the distance O(n) between a point and the point that follows it. Remember the smallest. 5-5 Closest Pair of Points 1-D version. Cost Sort points O(n log n) For each point, find the distance O(n) between a point and the point that follows it. Remember the smallest. Total is O(n log n) Slides14 - ClosestPairPoints.key - March 20, 2019

  4. 6-1 Closest Pair of Points Divide: draw vertical line L so that n/2 points on each side. L 6-2 Closest Pair of Points Divide: draw vertical line L so that n/2 points on each side. L 7-1 Closest Pair of Points Solve: find closest pair in each side recursively. L Slides14 - ClosestPairPoints.key - March 20, 2019

  5. 7-2 Closest Pair of Points Solve: find closest pair in each side recursively. L 12 7-3 Closest Pair of Points Solve: find closest pair in each side recursively. L 21 12 Closest Pair of Points 8 Combine: find closest pair with one point in each side. Return best of 3 solutions. How do we do this without comparing each point on left with each point on right??? L 8 21 12 Slides14 - ClosestPairPoints.key - March 20, 2019

  6. 9 Closest Pair of Points Let δ be the minimum between pair on left and pair on right If there exists a pair with one point in each side and whose distance < δ , find that pair. L 21 δ = min(12, 21) 12 10 Closest Pair of Points Observation: only need to consider points within δ of line L. δ L 21 δ = min(12, 21) 12 11 Closest Pair of Points Sort points in 2 δ -strip by their y coordinate. δ L 7 6 5 21 4 δ = min(12, 21) 3 12 2 1 Slides14 - ClosestPairPoints.key - March 20, 2019

  7. 12 Closest Pair of Points Only need to check distances of those within 15 positions in sorted list!!!! δ L 7 6 5 21 4 δ = min(12, 21) 3 12 2 1 13 Closest Pair of Points Let s i be the point in the 2 δ -strip, with j 39 the i th smallest y-coordinate. Claim. If |i – j| ≥ 16, then the distance 31 between s i and s j is at least δ . ½ δ 3 rows Proof: 30 ½ δ 29 No two points lie in same ½ δ -by- ½ δ ½ δ 28 i 27 box. Two points separated by at least 3 26 rows have distance ≥ 3( ½ δ ). 25 δ δ 14 Closest Pair of Points Let s i be the point in the 2 δ -strip, with the i th smallest y-coordinate. j 39 Claim. If |i – j| ≥ 16, then the distance between s i and s j is at least δ . 31 Proof: ½ δ No two points lie in same ½ δ -by- ½ δ 2 rows 30 ½ δ 29 box. ½ δ Two points separated by at least 3 i 28 27 rows have distance ≥ 3( ½ δ ). 26 If a point is within δ of point 27, it 25 must be in one of the blue boxes. There are only 15 blue boxes! δ δ Slides14 - ClosestPairPoints.key - March 20, 2019

  8. 15-1 Closest Pair Algorithm Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 are on one side and half on the other side. δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) Delete all points further than δ from separation line L Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } 15-2 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 are on one side and half on the other side. δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) Delete all points further than δ from separation line L Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } 15-3 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) Delete all points further than δ from separation line L Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } Slides14 - ClosestPairPoints.key - March 20, 2019

  9. 15-4 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. 2T(n / 2) δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) Delete all points further than δ from separation line L Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } 15-5 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. 2T(n / 2) δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) O(n) Delete all points further than δ from separation line L Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } 15-6 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. δ 1 = Closest-Pair(left half) 2T(n / 2) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) O(n) Delete all points further than δ from separation line L O(n log n) Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y value within δ . If any of these distances is less than δ , update δ . return δ . } Slides14 - ClosestPairPoints.key - March 20, 2019

  10. 15-7 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. 2T(n / 2) δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) O(n) Delete all points further than δ from separation line L O(n log n) Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y O(n) value within δ . If any of these distances is less than δ , update δ . return δ . } 15-8 Closest Pair Algorithm Cost Closest-Pair(p 1 , …, p n ) { Compute separation line L such that half the points 
 O(n log n) are on one side and half on the other side. 2T(n / 2) δ 1 = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min( δ 1 , δ 2 ) O(n) Delete all points further than δ from separation line L O(n log n) Sort remaining points by y-coordinate. Scan points in y-order and calculate distance to all points with a y O(n) value within δ . If any of these distances is less than δ , update δ . T(n) ≤ 2T(n/2) + O(n log n) return δ . T(n) = O(n log 2 n) } Slides14 - ClosestPairPoints.key - March 20, 2019

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend