Proofs: Ball tree
These are the human proofs of Ball tree, at full length.
The ball tree is balanced and its searches are exact full
This proof shows: correctness.
Let be a metric space, with , and the leaf size.
Lemma 1 (covering). Every node built by BUILD satisfies (R): for every point of its subtree.
Proof. Line L2 sets , where is the set of points of the subtree of .
Lemma 2 (height). A node at depth (the root has depth 0) holds at most points, and the tree has at most levels when .
Proof. Line L4 gives the children and points, and . A node with at most points is a leaf. At depth , , and is an integer, so and every node at that depth is a leaf.
Lemma 3 (lower bound). For every and every point in the subtree of , .
Proof. By the triangle inequality, , and by Lemma 1.
Theorem 1. KNN returns pairs whose distances are the smallest values of over , each with a point at that distance.
Proof. Let be the -th distance in , or when has fewer than pairs; never increases. Every pair in is a stored point with its true distance, since only line L7 offers pairs. Call a point skipped if it lies in a subtree pruned at line L6. At the moment a node is pruned, Lemma 3 gives for each point of , so already holds pairs of distance at most . Since keeps the least offered pairs, it holds pairs of distance at most at the end as well.
Let be the final distances in and the true sorted distances. Each is the distance of a distinct point, so . Suppose for some , and take the points with distances . At most of them are in with a distance below , so some with is not in . If was offered and later dropped or never kept, then at that moment held pairs of distance at most , and the final pairs are no larger, so , which is impossible. If was skipped, the paragraph above gives , again impossible. So for all . If , no node is pruned since , and every point is offered.
Theorem 2. RANGE reports exactly the points with , each once.
Proof. Line L10 reports only points that pass the test. A point is not offered only if an ancestor node was pruned at line L9, and then Lemma 3 gives . Each point is in exactly one leaf, which is visited at most once.