Imagine you have already organized a million points into a k-d tree — space sliced along alternating axes, half the points on each side of every cut. Now someone drops a query point and asks: which of the million is closest?
You could walk down to the leaf that contains the query and grab whatever is there, but that leaf might hold the wrong answer entirely — the true nearest point could sit just across a dividing line, in a sibling branch you never opened. So the search cannot simply go down; it has to be willing to come back up and check other branches too.
The nearest-neighbor algorithm solves this with a single recurring question at every fork: could anything on the unexplored side possibly be closer than the best point found so far? If the honest answer is no, the whole branch — thousands of points, maybe — is thrown away without a single one of them being touched.
Comments
Loading comments...