Hypothetically, suppose I have a collection of 10,000 random points in 2-D (or more).
And suppose I want to quickly find which of those is closest to a new random point. Let’s say there are a million (or more) such new random points.
What’s the fastest computer algorithm to do this? Obviously I don’t want to compare every one of the 10,000 with every new random point.
I could pre-sort the 10,000 points on x, and then work outwards from the closest x value until I find a y value close enough. But I think there ought to be a much faster algorithm than that.
Perhaps a quadtree – whatever that is?
I’m sort of toying with the idea of sorting the 10,000 points simultaneously on x and y into a 2-D array P(i,j) such that x of P(i,j) >= x of P(i-1,k) for all values of j and k, and such that y of P(i,j) >= y of P(k,j-1) for all values of i and k.
The idea is that this would allow me to go straight from the x and y of the new random number to the i,j of P(i,j) and work out from there.
It wouldn’t work for 10,000 nonrandom points, such as x(i)=i, y(j)=j for i,j=1 to 10,000, but I think I’m on the right track for 10,000 random points, (or semi-random, or gridded or chaotic). What do you think?