The Closest Pair Problem can be solved using a divide and conquer algorithm. The algorithm works as follows:
1. Sort the points by x-coordinate and then y-coordinate.
2. Divide the points into two subsets by a median splitting line.
3. Recursively find the closest pairs in the subsets. Combine the results, checking for closer pairs that cross the splitting line.
The algorithm runs in O(n log n) time, making it efficient for solving the Closest Pair Problem.
3. Closest-Pair Problem by Divide-and-Conquer
Step 0 Sort the points by x co-ordinate (list one) and then by y co-
ordinate (list two).
Step 1 Divide the points given into two subsets S1 and S2 by a
vertical line, x = m, through the median m of their x coordinates
so that half the points lie to the left or on the line and half the
points lie to the right or on the line.
Step 2 Find recursively the closest pairs for the left and right
subsets.
4.
5. Closest Pair by Divide-and-Conquer (cont.)
Step 3 Set d = min{d1, d2}. d is not necessarily the smallest distance
between all the point pairs because points of a closer pair can lie on
the opposite sides of the separating line. While combining the
solutions such points need to be examined.
Points in the symmetric vertical strip of width 2d will be possible
closest pair.
Let C1 and C2 be the subsets of points in the left subset S1 and of the
right subset S2, respectively, that lie in this vertical strip. The points in
C1 and C2 are stored in increasing order of their y coordinates, taken
from the second list.
Step 4 For every point P(x,y) in C1, we inspect points in C2 that may be
closer to P than d. There can be no more than 6 such points
(because d ≤ d2)!
8. Efficiency of the Closest-Pair Algorithm
Running time of the algorithm (without sorting) is:
T(n) = 2T(n/2) + M(n), where M(n) Θ(n)
By the Master Theorem (with a = 2, b = 2, d = 1)
T(n) Θ(n log n)
So the total time is Θ(n log n).
9. Quickhull Algorithm
Convex hull: smallest convex set that includes given points.
• Quick hull algorithm uses divide and conquer technique.
• Initially points are sorted by x-coordinate values with ties
resolved by y coordinates.
• Identify extreme points P1 and Pn (leftmost and rightmost).
10. Quickhull Algorithm
• Compute upper hull recursively:
• find point Pmax that is farthest away from line P1Pn
• compute the upper hull of the points to the left of line
P1Pmax
• compute the upper hull of the points to the left of line
PmaxPn
• Compute lower hull in a similar manner
P1
Pn
Pmax
12. Quick hull
If q1(x1, y1), q2(x2, y2), and q3(x3, y3) are three arbitrary points in the
Cartesian plane, then the area of the triangle q1q2q3 is equal to one-half of the
magnitude of the determinant
the sign of this expression is positive if and only if the point q3 = (x3, y3) is to the left of the line q1q2.
13. Efficiency of Quickhull Algorithm
Time Complexity:
• Finding point farthest away from line P1Pn can be
done in linear time and merging of the left and the
right convex hulls take O(n) time and as we are
dividing the points into two equal parts,
T(n) = 2T(n/2) + O(n)
• so the time complexity of the above algorithm is
O(n * log n).
• Time efficiency:
• worst case: O(n2)
T(n) = T(n-1) + O(n)