Divide. Draw vertical line L with \approx n/2 points on each side.
Divide with vertical line
Divide. Draw vertical line L with \approx n/2 points on each side.
Conquer. Find closest pair on each side, recursively.
Conquer recursively
Divide. Draw vertical line L with \approx n/2 points on each side.
Conquer. Find closest pair on each side, recursively.
Combine. Find closest pair with one point in each side.
Return best of 3 solutions.
Combine step
Find closest pair with one point in each side, assuming distance < \delta = \min\{d_1, d_2\}.
Return best of 3 solutions.
Finding crossing pair
Find closest pair with one point in each side, assuming distance < \delta = \min\{d_1, d_2\}.
Return best of 3 solutions.
Observation: Suffices to consider points within \delta of line L.
Points within \delta of L
Find closest pair with one point in each side, assuming distance < \delta = \min\{d_1, d_2\}.
Return best of 3 solutions.
Observation: Suffices to consider points within \delta of line L.
Almost the one dimensional problem: Sort points in 2\delta-strip by their y coordinate.
Only check points within 8 in sorted list!
Checking points in strip
Def. Let p_i have the i^{th} smallest y-coordinate among points in the 2\delta-width-strip.
Claim. If |i-j| > 8, then the distance between p_i and p_j is > \delta.
Proof. No two points lie in the same \delta/2-by-\delta/2 square!
\delta/2 box argument
Full algorithm
Analysis-1: Let D(n) be the number of pairwise distance calculations in the Closest-Pair Algorithm when run on n \geq 1 points.
D(n) \leq \begin{cases} 0, & n=1\\ 2D(n/2) + 7n, & n > 1. \end{cases}
\implies D(n) = O(n\log{n}).
This is the number of distance computations.
Analysis-2: Let C(n) be the number of comparisons in the Closest-Pair Algorithm when run on n \geq 1 points.
C(n) \leq \begin{cases} 0, & n=1\\ 2C(n/2) + O(n\log{n}), & n > 1. \end{cases}
\implies C(n) = O(n\log^2{n}).
This is the number of comparisons.
Can we reduce the time complexity to O(n\log{n})?
Thus, total complexity can be reduced to O(n\log{n}).
CS F364: Design & Analysis of AlgorithmsTulasimohan Molli