A common application of k-d trees is nearest-neighbor search (NNS) , where a query point q is given, and the goal is to find the point x i in the dataset that minimizes the distance |q -x i |. The k-d tree supports a depth-first search that prunes large regions of the search space. The query starts by traversing the tree, comparing q with the splitting coordinate at each node to decide whether to continue left or right. Once a leaf node is reached, its data point is recorded as the current "best candidate." The algorithm then backtracks upward, pruning branches of the tree that cannot contain a point closer than the best candidate so far. In practice, this pruning significantly reduces the number of distance comparisons and typically yields O(log N ) query time for balanced trees.