Chapter 5.4: Finding the Closest Pair of Points

Given n points on a plane, our goal is to find the pair that is closest together. Comparing every possible pairing would take O(n^2) time. However, it is possible to do this in O(nlogn) time.

The Algorithm

We will denote the set of points by P={p_1,…, p_n}, where p_i has coordinates (x_i,y_i); and for two points p_i,p_j, d(p_i,p_j) to denote the Euclidean distance between them. We will also assume that all points have distinct coordinates. Our goal is to find a pair of coordinates p_i and p_j such that d(p_i,p_j) is minimized. We will approach this problem in a way that is similar to Mergesort: we will find the closest pair among the points in the left half of P and the closest pair among the right half of P.

Closest-Pair(P):

Closest-Pair-Rec(P_x,P_y):

this runs in O(nlogn)

I would rate this section a 6. The algorithm made more sense in class. I was really confused by all of the additional variables in this algorithm.