advanced topics in algorithms and data structures lecture 7.1, page 1 an overview of lecture 7 an...
TRANSCRIPT
![Page 1: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/1.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 1
An overview of lecture 7
• An optimal parallel algorithm for the 2D convex hull problem,
• Some applications of the 2D convex hull algorithm.
![Page 2: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/2.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 2
The convex hull problem
Input: A set S = (p1, p2,…,pn) of n points on the plane.Output: The convex hull CH(S) of these n points.
• The convex hull is the smallest convex polygon containing all the n points.
• Each vertex of CH(S) is called an extreme point and the convex hull is output as a list of the extreme points.
![Page 3: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/3.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 3
The convex hull problem
• Let pmax and pmin be two points in the set S with the maximum and minimum x coordinates.
• Then pmax and pmin are convex hull vertices.
• The line segment divides the convex hull into two parts, upper hull and lower hull.
max minp p
![Page 4: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/4.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 4
The convex hull problem
• We use the notation x(p) and y(p) to denote the x and y coordinates of a point p.
• Given a line L specified by the equation y = ax + b, and a point q =( , ),
• We say, q is below L if < a + b.• We also say, q is above L if > a + b.
![Page 5: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/5.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 5
The convex hull problem
• Given the set S of n points, we can find pmax and pmin in O(n) time.
• We can find all the points above and below also in O(n) time.
• We can compute the convex hull of all the points above and call this as UH(S).
• Similarly, we can compute the convex hull of all the points below and call this as LH(S).
• At the end, we can stitch these two hulls together at the two points pmax and pmin.
max minp p
max minp p
max minp p
![Page 6: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/6.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 6
Sequential complexity
• The convex hull of n planar points can be constructed in (n log n) time sequentially.
• The lower bound can be proved by showing that the convex hull problem is equivalent to sorting.
• We need to design an O(n log n) work algorithm to achieve optimality.
![Page 7: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/7.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 7
Computing the upper hull
• We will discuss an algorithm for computing the upper hull of the set S. The algorithm for computing the lower hull is exactly the same.
• A line L is tangent to a convex polygon P if all the vertices of P are on the same side of L.
![Page 8: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/8.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 8
A divide-and-conquer algorithm
• We discuss a divide-and-conquer algorithm for computing the upper hull. There are two phases, top-down and bottom-up.
• First, we sort the points according to x-coordinates.
![Page 9: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/9.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 9
A divide-and-conquer algorithm
• In the top-down phase, we divide the point set recursively into two parts and compute the convex hull when the size of each subproblem is small.
• In the bottom-up phase, we merge these hulls pairwise to get the upper hull.
• The strategy is exactly similar to the sequential algorithm for merge sort.
![Page 10: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/10.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 10
A divide-and-conquer algorithm
![Page 11: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/11.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 11
Merging two upper hulls
• The main problem in combining two upper hulls to form a single upper hull is to compute a common tangent to the two hulls.
• To achieve O(n log n) work, we need to complete the merging of all the upper hulls at a level of the tree in O(1) time.
![Page 12: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/12.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 12
Merging two upper hulls
• We consider two upper hulls UH(S1) and UH(S2).
• Our aim is to find a common tangent to these two upper hulls.
• We first find a tangent to UH(S2) from a point ri on UH(S1).
![Page 13: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/13.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 13
Merging two upper hulls
• Suppose the line is the tangent to UH(S2) from ri.
• Suppose ql is another vertex of UH(S2).
• Given the line riql, we first try to locate .
ii rrq
irq
![Page 14: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/14.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 14
Merging two upper hulls
• In O(1) time, we can say whether is above or below the line .
• If the neighboring vertices ql -1 and ql +1 of ql are on either side of , then is above ql.
irq
irq
i lrq
i lrq
![Page 15: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/15.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 15
Parallel search algorithm
• For each of the p + 1 parts of the array, a processor checks whether y < xl, where xl is the last element of the part.
• If y < xl, the subarray to the right of xl can be rejected. If y > xl, the subarray to the left of xl can be rejected.
• In each iteration we identify only one subarray for further search.
![Page 16: Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,](https://reader036.vdocuments.net/reader036/viewer/2022072006/56649cf95503460f949c9ea7/html5/thumbnails/16.jpg)
Advanced Topics in Algorithms and Data Structures
Lecture 7.1, page 16
Complexity of parallel searching
• We need to analyze what is the complexity of reducing the size of the array to p.
• At the first iteration, we are reducing the size of the array from n to n/p.
• Suppose, the size reduces to p after k iterations.
• Hence, , which implies n = pk +1.• . We need the CREW PRAM
model.
k
np
p
log( )log
nk O
p