Suppose we have two sets of points A, B, and we want to find for every point in set A its nearest neighbor in set B.
There are many good algorithms to find the nearest neighbor for one point. Is there some way to use the information we got for a_1, to more efficiently search for the nearest neighbor for a_2 or other points in the set?
I am thinking something like: use triangular inequlity to get a interval for possible distance between every point in B and new point a_2, and sort the max and min of the intervals, and then I can search only the points in B which falls in the first interval.
The k-nearest neighbors algorithm, also known as KNN or k-NN, is a non-parametric, supervised learning classifier, which uses proximity to make classifications or predictions about the grouping of an individual data point.
In statistics, the k-nearest neighbors algorithm (k-NN) is a non-parametric supervised learning method first developed by Evelyn Fix and Joseph Hodges in 1951, and later expanded by Thomas Cover. It is used for classification and regression.
One strategy for solving the traveling salesman problem is the nearest-neighbor algorithm. Simply stated, when given a choice of vertices this algorithm selects the nearest (i.e., least cost) neighbor. In our applet below your goal is to select a Hamiltonian circuit using the nearest-neighbor algorithm.
Details for step 2: Keep all edges of Voronoi diagram, currently intersected by sweep line, in some ordered container. When sweep line covers some vertex of Voronoi diagram, remove/add edges, incident to this vertex, from/to container. To look, between which edges some point is located, get successor/predecessor edges to this point in container.
Time complexity is O((M+N) log M). N = |A|, M = |B|.
You may benefit from reading bentleys "writing efficient programs" where he deals with a case study of the traveling salesman program. One of the savings that he recognized was that the distince between two points involved taking a square root which was expensive. Taking the square root gives you the actual distance, not taking the square root gives you a number which can be used to compare against other relative values.
I highly recommend reading the book. It will put your brain in the right place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With