Solution: Closest Points

Solution for the Closest Points Problem.

We'll cover the following

Solution

This computational geometry problem has many applications in computer graphics and vision. A naive algorithm with quadratic running time iterates through all pairs of points to find the closest pair. Our goal is to design an O(nO(n\cdotlog(n))log(n)) time divide-and-conquer algorithm.

To solve this problem in time O(nO(n\cdotlog(n))log(n)), let’s first split the given nn points by an appropriately chosen vertical line into two halves, S1S_{1} and S2S_{2}, of size n2\frac{n}{2} (assume for simplicity that all xx-coordinates of the input points are different). By making two recursive calls for the sets S1S_{1} and S2S_{2}, we find the minimum distances d1d_{1} and d2d_{2} in these subsets. Let dd = min{d1d_{1}, d2d_{2}}.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.