added nearest neighbor search algorithm