For example, I have two lists of points:
List<Point2D> a; List<Point2D> b;
What would be the best way to find such i and j so that a.get(i).distance(b.get(j)) minimal?
The obvious solution is brute force - calculate the distance from each point in a to each point in b , keep the pair with the shortest distance. But this algorithm is O(n^2) , which is not very good. Is there a better approach?
source share