Upcoming SlideShare
×

# Lecture24

819

Published on

Published in: Technology, Art & Photos
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
819
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Lecture24

1. 1. An overview of lecture • Geometric Algorithms – Range searching. – Nearest neighbor. – Finding intersections of geometric objects. • An optimal parallel algorithm for the 2D convex hull problem, • Some applications of the 2D convex hull algorithm.
2. 2. Geometric search: Overview • Types of data. Points, lines, planes, polygons, circles, ... • This lecture: Sets of N objects. • Geometric problems extend to higher dimensions. – Good algorithms also extend to higher dimensions. – Curse of dimensionality. • Basic problems. – Range searching. – Nearest neighbor. – Finding intersections of geometric objects.
3. 3. Range Searching 1D Range Search • Extension to symbol-table ADT with comparable keys. – Insert key-value pair. – Search for key k. – How many records have keys between k1 and k2? – Iterate over all records with keys between k1 and k2. • Application: database queries. • Geometric intuition. – Keys are point on a line. – How many points in a given interval? insert B B insert D B D insert A A B D insert I A B D I insert H A B D H I insert F A B D F H I insert P A B D F H I P count G to K 2 search G to K H I
4. 4. 1D Range Search Implementations • Range search. How many records have keys between k1 and k2? • Ordered array. Slow insert, binary search for k1 and k2 to find range. • Hash table. No reasonable algorithm (key order lost in hash). • BST. In each node x, maintain number of nodes in tree rooted at x. Search for smallest element k1 and largest element k2. log N N log N countinsert range ordered array N R + log N hash table 1 N BST log N R + log N nodes examined within interval not touched N = # records R = # records that match
5. 5. 2D Orthogonal Range Search • Extension to symbol-table ADT with 2D keys. – Insert a 2D key. – Search for a 2D key. – Range search: find all keys that lie in a 2D range? – Range count: how many keys lie in a 2D range? • Applications: networking, circuit design, databases. • Geometric interpretation. – Keys are point in the plane. – Find all points in a given h-v rectangle?
6. 6. 2D Orthogonal Range Search: Grid Implementation • Grid implementation. – Divide space into M-by-M grid of squares. – Create linked list for each square. – Use 2D array to directly access relevant square. – Insert: insert (x, y) into corresponding grid square. – Range search: examine only those grid squares that could have points in the rectangle. LB RT
7. 7. 2D Orthogonal Range Search: Grid Implementation Costs • Space-time tradeoff. – Space: M2 + N. – Time: 1 + N / M2 per grid cell examined on average. • Choose grid square size to tune performance. – Too small: wastes space. – Too large: too many points per grid square. – Rule of thumb: √N by √N grid. • Running time. [if points are evenly distributed] – Initialize: O(N). – Insert: O(1). – Range: O(1) per point in range. LB RT
8. 8. Clustering • Grid implementation. Fast, simple solution for well-distributed points. • Problem. Clustering is a well-known phenomenon in geometric data. • Ex: USA map data. – 80,000 points, 20,000 grid squares. – Half the grid squares are empty. – Half the points have 10 others in same grid square. – Ten percent have 100 others in same grid square. • Need data structure that gracefully adapts to data.
9. 9. Space Partitioning Trees • Space partitioning tree. Use a tree to represent the recursive hierarchical subdivision of d-dimensional space. • BSP tree:- Recursively divide space into two regions. • Quad tree:- Recursively divide plane into four quadrants. • Octree:- Recursively divide 3D space into eight octants. • kD tree:- Recursively divide k-dimensional space into two half- spaces. • Applications. – Ray tracing. – Flight simulators. – N-body simulation. – Collision detection. – Astronomical databases. – Adaptive mesh generation. – Accelerate rendering in Doom. – Hidden surface removal and shadow casting. Grid Quadtree kD tree BSP tree
10. 10. Quad Trees • Quad tree. Recursively partition plane into 4 quadrants. • Implementation: 4-way tree. • Good clustering performance is a primary reason to choose quad trees over grid methods. a b c e f g h d a h d ge b c f public class QuadTree { private Quad quad; private Value value; private QuadTree NW, NE, SW, SE; }
11. 11. kD Trees • kD tree. Recursively partition k-dimensional space into 2 halfspaces. • Implementation: BST, but cycle through dimensions. • Efficient, simple data structure for processing k-dimensional data. – Adapts well to clustered data. – Adapts well to high dimensional data. – Discovered by an undergrad in an algorithms class! level ≡ i (mod k) points whose ith coordinate is less than p’s points whose ith coordinate is greater than p’s p
12. 12. Summary • Basis of many geometric algorithms: search in a planar subdivision. grid 2D tree Voronoi diagram intersecting lines basis N h-v lines N points N points N lines representation 2D array of N lists N-node BST N-node multilist ~N-node BST cells ~N squares N rectangles N polygons ~N triangles search cost 1 log N log N log N extend to kD? too many cells easy cells too complicated use (k-1)D hyperplane
13. 13. Geometric Intersection • Problem. Find all intersecting pairs among set of N geometric objects. • Applications. CAD, games, movies, virtual reality. • Simple version: 2D, all objects are horizontal or vertical line segments. • Brute force. Test all (N2) pairs of line segments for intersection. • Sweep line. Efficient solution extends to 3D and general objects.
14. 14. • Sweep vertical line from left to right. – Event times: x-coordinates of h-v line segments. – Left endpoint of h-segment: insert y coordinate into ST. – Right endpoint of h-segment: remove y coordinate from ST. – v-segment: range search for interval of y endpoints. Orthogonal Segment Intersection: Sweep Line Algorithm range searchinsert y delete y
15. 15. Orthogonal Segment Intersection: Sweep Line Algorithm • Sweep line: reduces 2D orthogonal segment intersection problem to 1D range searching! • Running time of sweep line algorithm. – Put x-coordinates on a PQ (or sort). O(N log N) – Insert y-coordinate into SET. O(N log N) – Delete y-coordinate from SET. O(N log N) – Range search. O(R + N log N) • Efficiency relies on judicious use of data structures. N = # line segments R = # intersections
16. 16. Line Segment Intersection: Implementation • Efficient implementation of sweep line algorithm. – Maintain PQ of important x-coordinates: endpoints and intersections. – Maintain ST of segments intersecting sweep line, sorted by y. – O(R log N + N log N). • Implementation issues. – Degeneracy. – Floating point precision. – Use PQ since intersection events aren't known ahead of time.
17. 17. 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.
18. 18. 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
19. 19. 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.
20. 20. 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
21. 21. 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.
22. 22. 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.
23. 23. 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.
24. 24. 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.
25. 25. A divide-and-conquer algorithm
26. 26. 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.
27. 27. 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).
28. 28. 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
29. 29. 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
30. 30. Merging two upper hulls • Suppose, UH(S2) has s points given in an array according to their order on UH(S2). • We allocate processors and divide the points on UH(S2) into intervals and do a parallel search. • We can identify the point in time. s irq log ( ) (1) log s O O s s
31. 31. Merging two upper hulls • Suppose, the common tangent to UH(S1) and UH(S2) is the line . • u is on UH(S1) and v is on UH(S2) . • If we know the line , we can say in O(1) time whether u is above or below the line . uv ii rrq ii rrq
32. 32. Merging two upper hulls • Suppose, there are t points on UH(S1), given in an array according to their order on UH(S1). • We divide these t points in intervals, each interval contains points. • We now do a parallel search in the following ways. t t
33. 33. Merging two upper hulls • We allocate processors for the parallel search. • Suppose ri is the boundary vertex of one of the intervals. • For each such ri, we can find the tangent to UH(S2) in O(1) time using processors. t s s ii rrq
34. 34. Merging two upper hulls • Hence, we can identify two boundary vertices rj and rk such that u is above rj and below rk. • Hence, u must be one of the vertices in between rj and rk. • This computation takes O(1) time and processors. t ( )s t O n
35. 35. Merging two upper hulls • We can do a similar computation to find a group of vertices on UH(S2) in which v is a member. • This computation again takes O(1) time and processors. s ( )s t O n
36. 36. Merging two upper hulls • Now, we have vertices on UH(S2) and vertices on UH(S1) . • There are possible lines if we join one point from UH(S1) and one point from UH(S2) . • For each of these O(n) lines, we can check in O(1) time whether the line is a common tangent to UH(S1) and UH(S2) . s t ( )s t O n
37. 37. Merging two upper hulls • Suppose, is one such line. • ul and ur are the two neighboring vertices of u. Also, vl and vr are the two neighboring vertices of v. • is the common tangent to both UH(S1) and UH(S2) if all the point ul, ur, vl, vr are below . uv uv uv
38. 38. Merging two upper hulls • For each of the O(n) lines, we can check this condition in O(1) time. • Hence, we can find a common tangent to UH(S1) and UH(S2) in O(1) time and O(n) work. • We can form another array of vertices containing the vertices in UH(S1) UH(S2) by deleting some parts of the arrays of UH(S1) and UH(S2) and merging the remaining parts.
39. 39. The convex hull algorithm • We solve the problem through a divide and conquer strategy. • The depth of the recursion is O(log n) and we can do the merging of the convex hulls at every level of the recursion in O(1) time and O(n) work. • Hence, the overall time required is O(log n) and the overall work done is O(n log n) which is optimal. • We need the CREW PRAM model due to the concurrent reading in the parallel search algorithm.
40. 40. Intersection of half planes • Consider a line L defined by the equation y = ax + b. • L divides the entire plane into two half planes, H+(L) and H-(L). • H+(L) consists of all the points ( , ) such that a + b. • Similarly, H-(L) consists of all the points a + b. • Intuitively, H+(L) is the set of points on or above the line L, • And, H-(L) is the set of points on or below the line L.
41. 41. Intersection of half planes • For a set of lines, the intersection of the positive half planes defined by these lines is a convex region. • However, the intersection may or may not be bounded. • Our aim is to compute the boundary of the intersection.
42. 42. Dual transform • Let T be a transformation that maps a point p = (a, b) into the line T(p) defined by y = ax + b. • The reverse transformation maps the line L : y = ax + b into the point T(L) = (-a, b).
43. 43. A property Property: A point p is below a line L if and only if T(p) is below the point T(L). – Consider a set of lines L1, L2,…,Ln, and the region C defined by 1 i n H+(Li) – The region C consists of all the points above all the lines Li,1 i n
44. 44. Intersection of half planes • In the transformed domain, T(C+) = { T(p) | p C+ } consists of all the lines above all the points T(Li), for 1 i n.
45. 45. Intersection of half planes • The extreme points of the intersection of half planes are now the line segments between two consecutive vertices of the convex hull in the dual space.
46. 46. Intersection of half planes • To compute the intersection of the half planes, we first convert the lines into their dual points. • Then we compute the convex hull of these dual points. • Finally, we get the extreme points of the intersection of half planes by converting the line segments between two consecutive extreme points of the convex hull into points.
47. 47. Intersection of half planes • The transformations take O(1) time each if we allocate one processor for each line. • The convex hull construction takes O(log n) time and O(n log n) work on the CREW PRAM.
48. 48. Two variable linear program • The two-variable linear program problem is defined as: Minimize cx + dy (Objective function) Subject to: aix + biy + ci 0, 1 i n. (Constraints)
49. 49. Two variable linear programming • Each constraint is a half plane. The feasible region is a set of points satisfying all the constraints. • The solution of the linear program is a point in the feasible region that minimizes the objective function. • The objective function is minimized at one of the extreme points of the feasible region.
50. 50. Two variable linear programming • Hence, we can find all the O(n) extreme points of the feasible region by the half plane intersection algorithm. • Then we can find the extreme point which minimizes the objective function. • The algorithm takes O(log n) time and O(n log n) work on the CREW PRAM.
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.