Nearest neighbor search (
NNS), also known as
proximity search,
similarity search or
closest point search, is an
optimization problem for finding closest (or most similar) points. Closeness is typically expressed in terms of a dissimilarity function: the less similar the objects, the larger the function values. Formally, the nearest-neighbor (NN) search problem is defined as follows: given a set
S of points in a space
M and a query point
q ∈
M, find the closest point in
S to
q.
Donald Knuth in vol. 3 of
The Art of Computer Programming (1973) called it the
post-office problem, referring to an application of assigning to a residence the nearest post office. A direct generalization of this problem is a
k-NN search, where we need to find the
k closest points.