Loading...
Divide & Conquer at work
Lower delta means closer points found.
Splitting points set at median x into left and right subsets.
1function closestPair(points):2 sort points by x3 return recursive(points)4function recursive(P):5 if |P| <= 3: return bruteForce(P)6 mid = |P|/2; L = P[0:mid]; R = P[mid:]7 d = min(recursive(L), recursive(R))8 strip = points within d of mid line9 return min(d, stripClosest(strip, d))