Algorithm Search⌘K

Proofs: Vantage-point tree

These are the human proofs of Vantage-point tree, at full length.

The vantage-point tree has logarithmic height and its range and nearest neighbor searches are exact full

This proof shows: correctness.

We use the names of the pseudocode on the page. (U,d)(U, d) is a metric space and P⊆UP \subseteq U a finite set of nn objects; obj(N)\mathrm{obj}(N) is the set of vantage points of the nodes in the subtree of NN.

Lemma 1 (structure). BUILD(S)(S) returns a tree whose nodes have the objects of SS as vantage points, each exactly once, and each node N=(v,μ,in,out)N = (v, \mu, \mathit{in}, \mathit{out}) satisfies d(v,x)≤μd(v, x) \le \mu for x∈obj(in)x \in \mathrm{obj}(\mathit{in}) and d(v,x)≥μd(v, x) \ge \mu for x∈obj(out)x \in \mathrm{obj}(\mathit{out}).

Proof. By induction on ∣S∣|S|. For SS empty, line L1 returns nil. Otherwise line L2 takes v∈Sv \in S, and the two lists of line L6 partition S′=S∖{v}S' = S \setminus \{v\}, each shorter than SS, so by induction the children hold their objects once each; with vv at the root, SS is covered once. If S′S' is empty, line L4 returns a node with empty children, and the claim holds vacuously. Otherwise S′S' is sorted by d(v,⋅)d(v, \cdot) and μ=d(v,S′[m])\mu = d(v, S'[m]); for i≤mi \le m, d(v,S′[i])≤μd(v, S'[i]) \le \mu, and for i>mi > m, d(v,S′[i])≥μd(v, S'[i]) \ge \mu. □\square

Lemma 2 (height). The tree built from n≥1n \ge 1 objects has height h(n)=⌊log⁡2n⌋+1h(n) = \lfloor \log_2 n \rfloor + 1, counting nodes on a longest root-to-leaf path. BUILD makes at most n⋅h(n)n \cdot h(n) evaluations.

Proof. The children have ⌈(n−1)/2⌉=⌊n/2⌋\lceil (n-1)/2 \rceil = \lfloor n/2 \rfloor and ⌊(n−1)/2⌋\lfloor (n-1)/2 \rfloor objects. So h(1)=1h(1) = 1 and h(n)=1+h(⌊n/2⌋)h(n) = 1 + h(\lfloor n/2 \rfloor) for n≥2n \ge 2, since hh is nondecreasing by induction. For n≥2n \ge 2, ⌊log⁡2⌊n/2⌋⌋=⌊log⁡2n⌋−1\lfloor \log_2 \lfloor n/2 \rfloor \rfloor = \lfloor \log_2 n \rfloor - 1: if 2j≤n<2j+12^j \le n < 2^{j+1} then 2j−1≤⌊n/2⌋<2j2^{j-1} \le \lfloor n/2 \rfloor < 2^j. Induction gives h(n)=⌊log⁡2n⌋+1h(n) = \lfloor \log_2 n \rfloor + 1. Line L3 makes ∣S∣−1|S| - 1 evaluations at a node with subtree set SS, and the line L5 distance is already known. The subtree sets of the nodes at one depth are disjoint, so each depth costs at most nn evaluations, and there are h(n)h(n) depths. □\square

Theorem 1 (range). RANGE(root,q,r,out)(\text{root}, q, r, \mathit{out}) adds to out\mathit{out} exactly the objects x∈Px \in P with d(q,x)≤rd(q, x) \le r, each once.

Proof. We show by induction on the tree that RANGE(N,q,r,⋅)(N, q, r, \cdot) adds exactly {x∈obj(N):d(q,x)≤r}\{x \in \mathrm{obj}(N) : d(q, x) \le r\}. For NN = nil, line L7 adds nothing. Otherwise let t=d(q,v)t = d(q, v). Line L8 adds vv if and only if d(q,v)≤rd(q, v) \le r. If line L9 recurses, the induction hypothesis gives the answers in in\mathit{in}. If it does not, then t−r>μt - r > \mu, and for each x∈obj(in)x \in \mathrm{obj}(\mathit{in}), by the triangle inequality and Lemma 1, d(q,x)≥d(q,v)−d(v,x)≥t−μ>rd(q, x) \ge d(q, v) - d(v, x) \ge t - \mu > r, so in\mathit{in} has no answer. If line L10 does not recurse, then μ−t>r\mu - t > r, and for x∈obj(out)x \in \mathrm{obj}(\mathit{out}), d(q,x)≥d(v,x)−d(q,v)≥μ−t>rd(q, x) \ge d(v, x) - d(q, v) \ge \mu - t > r. Lemma 1 says that vv, obj(in)\mathrm{obj}(\mathit{in}) and obj(out)\mathrm{obj}(\mathit{out}) are disjoint, so nothing is added twice. □\square

Theorem 2 (nearest). If PP is nonempty, after NEAREST(root,q)(\text{root}, q) with τ=∞\tau = \infty at the start, b∈Pb \in P and τ=d(q,b)=min⁡x∈Pd(q,x)\tau = d(q, b) = \min_{x \in P} d(q, x).

Proof. Line L12 is the only line that changes (b,τ)(b, \tau); it sets them to a visited object and its distance, and only when the distance is smaller. So at every moment τ=min⁡\tau = \min of the distances of the visited objects, τ\tau never increases, and bb attains it. The root is visited, so b∈Pb \in P at the end. Let τf\tau_f be the final value. Suppose some x∈Px \in P has d(q,x)<τfd(q, x) < \tau_f. Then xx was not visited, since otherwise τf≤d(q,x)\tau_f \le d(q, x). So xx lies in a subtree CC of a visited node NN that line L15 skipped at a moment when τ\tau had a value τ0≥τf\tau_0 \ge \tau_f. If C=inC = \mathit{in}, then t−τ0>μt - \tau_0 > \mu and d(q,x)≥t−μ>τ0≥τfd(q, x) \ge t - \mu > \tau_0 \ge \tau_f. If C=outC = \mathit{out}, then t+τ0<μt + \tau_0 < \mu and d(q,x)≥μ−t>τ0≥τfd(q, x) \ge \mu - t > \tau_0 \ge \tau_f. Both contradict d(q,x)<τfd(q, x) < \tau_f. So τf\tau_f is the least distance. ■\blacksquare

Back to Vantage-point tree