1 / 8

Convex Hull

4. 5. 3. 6. 2. 1. 0. Convex Hull. Given a set of pins on a pinboard And a rubber band around them How does the rubber band look when it snaps tight? We represent the convex hull as the sequence of points on the convex hull polygon, in counter-clockwise order. A. B.

olin
Télécharger la présentation

Convex Hull

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4 5 3 6 2 1 0 Convex Hull • Given a set of pins on a pinboard • And a rubber band around them • How does the rubber band look when it snaps tight? • We represent the convex hull as the sequence of points on the convex hull polygon, in counter-clockwise order. CS 3343 Analysis of Algorithms

  2. A B Convex Hull: Divide & Conquer • Preprocessing: sort the points by x-coordinate • Divide the set of points into two sets A and B: • A contains the left n/2 points, • B contains the right n/2 points • Recursively compute the convex hull of A • Recursively compute the convex hull of B • Merge the two convex hulls CS 3343 Analysis of Algorithms

  3. Convex Hull: Runtime O(n log n) just once • Preprocessing: sort the points by x-coordinate • Divide the set of points into two sets A and B: • A contains the left n/2 points, • B contains the right n/2 points • Recursively compute the convex hull of A • Recursively compute the convex hull of B • Merge the two convex hulls O(1) T(n/2) T(n/2) O(n) CS 3343 Analysis of Algorithms

  4. Convex Hull: Runtime • RuntimeRecurrence: T(n) = 2 T(n/2) + cn • Solves to T(n) = (n log n) CS 3343 Analysis of Algorithms

  5. Merging in O(n) time • Find upper and lower tangents in O(n) time • Compute the convex hull of AB: • walk counterclockwise around the convex hull of A, starting with left endpoint of lower tangent • when hitting the left endpoint of the upper tangent, cross over to the convex hull of B • walk counterclockwise around the convex hull of B • when hitting right endpoint of the lower tangent we’re done • This takes O(n) time 4 5 3 6 2 7 1 A B CS 3343 Analysis of Algorithms

  6. right turn or left turn? can be checked in constant time Finding the lower tangent in O(n) time 3 a = rightmost point of A b = leftmost point of B while T=ab not lower tangent to both convex hulls of A and B do{ while T not lower tangent to convex hull of A do{ a=a-1 } while T not lower tangent to convex hull of B do{ b=b+1 } } 4=b 4 2 3 5 5 a=2 6 1 7 1 0 0 A B CS 3343 Analysis of Algorithms

  7. Convex Hull: Runtime O(n log n) just once • Preprocessing: sort the points by x-coordinate • Divide the set of points into two sets A and B: • A contains the left n/2 points, • B contains the right n/2 points • Recursively compute the convex hull of A • Recursively compute the convex hull of B • Merge the two convex hulls O(1) T(n/2) T(n/2) O(n) CS 3343 Analysis of Algorithms

  8. Convex Hull: Runtime • RuntimeRecurrence: T(n) = 2 T(n/2) + cn • Solves to T(n) = (n log n) CS 3343 Analysis of Algorithms

More Related