java - Closest pair algorithm for comparing points from 2 different arrays -


I would like to compare numbers from one array to another and get the closest pair. So far whatever I have come with is an array. I do not want to compare numbers with the same array. Brute force algorithm works but it is very slow. Is there an algorithm for this or implementation, using partition and can conquer the law?

Edit 1: The point is defined as the pair on the surface of the earth (latitude, longitude).

P>

You can create a KD-tree for the first array of digits, and then each of the other array The point is to find the nearest point from the first point, the use of this tree works on average in O (n log n) (n is the largest size of the two arrays). To use KD-tree, you can convert your initial coordinates to a 3D-space coordinate.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -