6

Reminder: Closest-Pair Problem Given a collection P of n points in × , obtain the two points p1 and p2 such that their distance is less or equal that

Embed Size (px)

Citation preview

Page 1: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that
Page 2: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that

Reminder: Closest-Pair Problem

Given a collection P of n points in × , obtain the two points p1 and p2 such that their distance is less or equal that the distance between any two other points

Brute Force: O(n2)

Practical Uses?Air Traffic control (3 dimensions)

Page 3: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that

Closest-Pair by Divide and Conquer

• Sort points in P by the x coordinate (O(n log2n))

• Recursive Divide and Conquer process (O(n log2n)):

1. Select c that splits points in P in two equal-sized groups M and Q

2. Compute the closest pair (m1, m2) and (q1, q2) for each group M and Q separately

3. The closest-pair for P could be either m1, m2 or q1, q2 or some other pairs

Page 4: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that

Reminder: Convex-Hull Problem

Given a collection P of n points in × , obtain the smallest convex set containing all points in P

Brute Force: O(n3)

Practical Uses?Path finding

Page 5: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that

QuickHull: Convex-Hull by Divide and Conquer

• Sort points in P by the x coordinate (O(n log2n))

• Select p1 with smallest x- and p2 with largest x-coordinate. p1 and p2 are in the Convex-Hull. Let p1p2 be the line connecting p1 and p2.

Recursive Divide and Conquer process (worst case: O(n2), average case: O(n log2n)):

1. Divide points in P as follows:

o L: those that are to the “left” of p1p2.

o R: those that are to the “right” of p1p2.

Page 6: Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that

QuickHull: Convex-Hull by Divide and Conquer (II)

2. Find the point pL in L which is the farthest from p1p2. If tides occur, select the one that maximizes the angle between p1p2 and p1pL . pL is in the Convex-Hull

3. Find the point pR in R which is the farthest from p1p2. If tides occur, select the one that maximizes the angle between p1p2 and p1pR . pR is in the Convex-Hull

4. Repeat 1 with:

o p1pL and L

o p1pR and R

As discussed in class there is an error in this algorithm. Make sure that you know the correct version (look in the book)