Algorithm Search⌘K

Proofs: M-tree

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

The M-tree keeps its covering invariants under insertion, and its range and k-NN 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. For a node NN, obj(N)\mathrm{obj}(N) is the multiset of objects in the leaf entries below NN. A routing entry ee with child CC covers when d(e.obj,y)≤e.radiusd(e.\mathrm{obj}, y) \le e.\mathrm{radius} for all y∈obj(C)y \in \mathrm{obj}(C). The invariants are (I1) every routing entry covers; (I2) every non-root entry has e.dp=d(e.obj,p)e.d_p = d(e.\mathrm{obj}, p), where pp is the routing object of the entry that points to its node; (I3) all leaves are at one depth; (I4) every node has at most MM entries, and every non-root node at least b=⌊(M+1)/2⌋b = \lfloor (M+1)/2 \rfloor.

Lemma 1 (radius of a split). Let oo be an object and EE a set of entries of one node, all covering. If ρ=max⁡e∈E(d(o,e.obj)+e.radius)\rho = \max_{e \in E} (d(o, e.\mathrm{obj}) + e.\mathrm{radius}), with radius 0 for leaf entries, then d(o,y)≤ρd(o, y) \le \rho for every object yy of every entry of EE (the object of a leaf entry, or an object below a routing entry).

Proof. For a leaf entry y=e.objy = e.\mathrm{obj} and d(o,y)≤ρd(o, y) \le \rho. For a routing entry, d(o,y)≤d(o,e.obj)+d(e.obj,y)≤d(o,e.obj)+e.radius≤ρd(o, y) \le d(o, e.\mathrm{obj}) + d(e.\mathrm{obj}, y) \le d(o, e.\mathrm{obj}) + e.\mathrm{radius} \le \rho by the triangle inequality and (I1). □\square

Lemma 2 (insertion). If the tree satisfies (I1) to (I4) before INSERT(x)(x), it does after, and its objects are the old ones plus xx.

Proof. Let N0,N1,…,NhN_0, N_1, \ldots, N_h be the nodes on the path chosen by lines L20 and L21, from the root to a leaf, and eie_i the entry of NiN_i chosen there. After line L20 or L21, d(x,ei.obj)≤ei.radiusd(x, e_i.\mathrm{obj}) \le e_i.\mathrm{radius}, and radii only grow, so each eie_i covers its old objects and xx. No other entry gains an object. Line L18 adds xx to NhN_h with dp=d(x,eh−1.obj)d_p = d(x, e_{h-1}.\mathrm{obj}), passed down in line L22, which is (I2) for it.

Now consider a split of a node NN with M+1M + 1 entries in lines L24 to L27. The balanced partition of line L25 gives the two promoted objects alternate turns until no entry is free, so the parts have ⌈(M+1)/2⌉\lceil (M+1)/2 \rceil and ⌊(M+1)/2⌋=b\lfloor (M+1)/2 \rfloor = b entries: (I4) for the new nodes. By Lemma 1 the new routing entries cover. Line L26 sets the dpd_p of every entry to its distance to the routing object of its new parent entry, which gives (I2) inside the new nodes, and line L22 sets the dpd_p of the two new routing entries to their distance to pp, the routing object of the node that now holds them. The new entries replace ee in that node, which holds one more entry; its routing entry, if any, covers the same objects as before, so (I1) holds there. If that node now has M+1M + 1 entries, line L23 splits it in turn. If the root splits, line L17 makes a new root with two entries and no dpd_p, and every leaf gets one level deeper, so (I3) holds; otherwise no depth changes. The new root has 2 entries, which (I4) allows. □\square

Theorem 1 (range). If (I1) and (I2) hold, RANGE(root,q,r,none)(\text{root}, q, r, \text{none}) reports exactly the objects yy of the tree with d(q,y)≤rd(q, y) \le r, with multiplicity.

Proof. By induction on the height of NN, RANGE(N,q,r,d(q,oN))(N, q, r, d(q, o_N)), where oNo_N is the routing object of the entry pointing to NN (none for the root), reports exactly the answers in obj(N)\mathrm{obj}(N). Each leaf entry is reported only if line L5 found d(q,y)≤rd(q, y) \le r. Suppose an answer yy is not reported; then an entry ee on its path was skipped. If line L2 skipped it, then by (I2), e.dp=d(e.obj,oN)e.d_p = d(e.\mathrm{obj}, o_N) and dqp=d(q,oN)d_{qp} = d(q, o_N), so by the triangle inequality d(q,e.obj)≥∣dqp−e.dp∣>r+e.radiusd(q, e.\mathrm{obj}) \ge |d_{qp} - e.d_p| > r + e.\mathrm{radius}. If line L6 skipped it, d(q,e.obj)>r+e.radiusd(q, e.\mathrm{obj}) > r + e.\mathrm{radius} directly. For a leaf entry with radius 0 and y=e.objy = e.\mathrm{obj} this says d(q,y)>rd(q, y) > r. For a routing entry, (I1) gives d(q,y)≥d(q,e.obj)−d(e.obj,y)>r+e.radius−e.radius=rd(q, y) \ge d(q, e.\mathrm{obj}) - d(e.\mathrm{obj}, y) > r + e.\mathrm{radius} - e.\mathrm{radius} = r. Either way yy is not an answer, a contradiction. □\square

Theorem 2 (kk nearest). If (I1) and (I2) hold and the tree stores nn objects, KNN(q,k)(q, k) returns min⁡(k,n)\min(k, n) objects whose distances are the min⁡(k,n)\min(k, n) least distances from qq to the stored objects.

Proof. For an entry ee define lb(e)=max⁡(d(q,e.obj)−e.radius,0)\mathrm{lb}(e) = \max(d(q, e.\mathrm{obj}) - e.\mathrm{radius}, 0). By (I1) and the triangle inequality, every object yy below ee has d(q,y)≥lb(e)d(q, y) \ge \mathrm{lb}(e); for a leaf entry lb(e)=d(q,y)\mathrm{lb}(e) = d(q, y). As in Theorem 1, the test of line L12 skips ee only if d(q,e.obj)−e.radius>τd(q, e.\mathrm{obj}) - e.\mathrm{radius} > \tau, and then every object below ee has distance greater than τ\tau.

The value τ\tau is ∞\infty while ∣B∣<k|B| < k and then the largest distance in BB; it never increases, because an object enters a full BB only if its distance is below τ\tau, and the farthest is dropped. Call an object lost if it is never offered to BB in line L14. An object yy is lost only if (a) an entry above it or its own entry was skipped by line L12 or not added in line L15 at a moment with threshold τ0\tau_0, so d(q,y)>τ0d(q, y) > \tau_0; or (b) the search stopped in line L10 while a node above yy was still in PQ, or below a node in PQ, with dmin⁡>τ1d_{\min} > \tau_1 at that moment, and each node in PQ has dmin⁡≥d_{\min} \ge the popped one, so d(q,y)≥dmin⁡>τ1d(q, y) \ge d_{\min} > \tau_1. Since τ\tau only decreases, in both cases d(q,y)>τfd(q, y) > \tau_f, the final threshold.

If fewer than kk objects were offered, then τf=∞\tau_f = \infty, nothing is lost, and BB holds all n<kn < k objects. Otherwise ∣B∣=k|B| = k at the end, and BB holds the kk least distances among the offered objects, all at most τf\tau_f; every lost object has distance greater than τf\tau_f. So the kk distances in BB are the kk least distances of all stored objects. □\square

Lemma 3 (height). Under (I3) and (I4) with M≥3M \ge 3, a tree of height h≥2h \ge 2 levels holds n≥2bh−1n \ge 2 b^{h-1} objects, so h≤1+log⁡b(n/2)h \le 1 + \log_b(n/2).

Proof. The root has at least 2 entries when it is internal, since it was made by a split of the root in line L17. Every other internal node has at least bb children, and every leaf at least bb entries, and b≥2b \ge 2 for M≥3M \ge 3. By (I3) there are at least 2bh−22 b^{h-2} leaves, each with at least bb objects. ■\blacksquare

Back to M-tree