Given n points on a 2D plane, find the distance between the closest pair of points.
Given n points on a 2D plane, find the distance between the closest pair of points.
The Closest Pair of Points Problem
Given n points on a 2D plane, find the distance between the closest pair of points.
Naive (Brute-Force) Approach:
The naive solution can be implemented in just a few lines, by finding the distance between all pairs of points and returning the distance between the closest pair. This approach requires O(n^2) time.
Recursive Divide-and-Conquer Approach
The problem can be solved in O(nlogn) time using the following recursive divide and conquer approach:
Assignment Structure:
First, let us go over the files provided in the starter code:
-Makefile
, which you will notice contains a new flag, -fsanitize=signed-integer-overflow, as well as the -lm flag required for the math library.
-main.c
contains the logic to:
1. Parse command-line arguments
2. Either generate points or read them from a file
3. Optionally save generated points to a file
4. Sort the points with qsort()
5. Call both the single-process and multi-process implementations to find the distance between the closest pair of points
6. Measure the time taken by both the single-process and multi-process implementations
-closest_tests.c
contains a test case to test the correctness of your implementation. You may use this as a skeleton to add additional test cases.
-closest_helpers.h
, closest_brute.h
, closest_serial.h
, and closest_parallel.h
declare all the functions that you will implement.
-closest_helpers.c
, closest_brute.c
, closest_serial.c
, and closest_parallel.c
are where your implementations will go.