ClosestPair Class |
The ClosestPair data type computes a closest pair of points in a set of N points in the plane and provides accessor methods for getting the closest pair of points and the distance between them. The distance between two points is their Euclidean distance.
This implementation uses a divide-and-conquer algorithm. It runs in O(N log N) time in the worst case and uses O(N) extra space. See also .
Namespace: Algs4Net
public class ClosestPair
The ClosestPair type exposes the following members.
Name | Description | |
---|---|---|
![]() | ClosestPair |
Computes the closest pair of points in the specified array of points. |
Name | Description | |
---|---|---|
![]() | Either |
Returns one of the points in the closest pair of points. |
![]() | Other |
Returns the other point in the closest pair of points. |
Name | Description | |
---|---|---|
![]() | Distance |
Returns the Eucliden distance between the closest pair of points. |
![]() ![]() | MainTest |
Demo test the ClosestPair data type.
Reads in an integer N and N points (specified by
their X- and Y-coordinates) from standard input;
computes a closest pair of points; and prints the pair to standard
output. |
For additional documentation, see Section 9.9 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class ClosestPair implementation by the respective authors.