Why it matters

Closest pair is classic D&C. Understanding shapes geometric optimization.

Advertisement

The architecture

Sort by x.

Divide in half.

Recurse both.

Check strip near dividing line.

Closest pair D&CSort by xdivideRecurse halvesd = min distanceStrip checkcandidates within dStrip has O(1) candidates to check per point (Shamos-Hoey); crucial for O(n log n)
Closest pair.
Advertisement

How it works end to end

Master theorem: T(n) = 2T(n/2) + O(n) = O(n log n).

Strip candidates: 7 per point in y-sorted order.

Alternative: KD-tree.