Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Closest Pair of Points ( 1 0 points ) : Computing the closest pair of points from a collection of n points takes ( n
Closest Pair of Points points: Computing the closest pair of points from a collection
of points takes naively, by checking each point against every other point and keeping
track of the minimum distance seen. We would like to improve upon that solution.
For this problem, you are not provided any helper code. The input will be provided in a
file named points.txt which contains million points, each described by an and value
on the same line, each in the range to The distance can be
computed via
Comparing all pairs of points is infeasible with million points. Instead, we will divide
the grid into grids, each of size Each point is then hashed into its
specific grid based on its location, and need only to be compared to points in its grid and in
the neighboring grids. This reduces the total number of comparisons needed, provided we
choose a good grid size. You can experiment yourself to find the best possible value of
Each grid cell should contain a linked list of the points that hashed to that location. If you
create a Node class to store the points, the two dimensional grid could be declared by writing:
Your program should follow the following steps:
a Allocate a D array of grid cells, based on your particular choice of
b Read the input file, hash each point to the corresponding grid cell.
c For each point, compare it against all points in the x block of grid cells centered on
that point's grid cell. Maintain the smallest distance you've seen.
d Print minimum distance.
Your program should be named Closest. java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started