Nearest Pair Hot Sheet¶
Use this page when the task is:
one static set of planar points -> one global closest Euclidean pair
and you want the shortest route back to the active strip invariant.
Do Not Use When¶
- the points change online
- the task is really event ordering over segments or rectangles
- the statement wants the outer boundary of the points
- the metric or dimension changed enough that the usual 2D packing argument no longer applies directly
Choose By Signal¶
- one static nearest Euclidean pair ->
closest-pair-sweep.cpp - same family, but the repo note you want is implementation-heavy -> Minimum Euclidean Distance
- outer boundary of many points -> Convex Hull
- many geometric events, active objects, and local neighbor rules -> Sweep Line
Core Invariants¶
- points are processed in increasing
x - the active set contains exactly the points still close enough in
xto matter - the active set is ordered by
y, because the surviving candidate window is ayinterval - internal comparisons are safest in squared distance, even if the final answer needs one square root
Main Traps¶
- mixing squared and unsquared distance in the strip test
- forgetting duplicate points imply answer
0 - ordering the active set by the wrong coordinate
- treating this as a hull or generic geometry-predicate problem
Exact Starters In This Repo¶
- exact starter ->
closest-pair-sweep.cpp - flagship in-lane rep -> Closest Pair
- compare point -> Minimum Euclidean Distance
- nearby chooser -> Geometry cheatsheet
Reopen Paths¶
- full lesson -> Nearest Pair of Points
- broader geometry chooser -> Geometry cheatsheet
- snippet chooser -> Template Library