Algorithm Search⌘K

Proofs: Hub labeling

These are the human proofs of Hub labeling, at full length.

Pruned landmark labeling gives labels with the cover property, and queries return exact distances full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a directed graph with weights w:E→R≥0w : E \to \mathbb{R}_{\ge 0} and let v1,…,vnv_1, \ldots, v_n be the order of the vertices. Write d(x,y)d(x, y) for the shortest-path distance, +∞+\infty if yy is not reachable from xx. The rank of vkv_k is kk. For vertices u,vu, v with d(u,v)<∞d(u, v) < \infty, let

S(u,v)={x∈V:d(u,x)+d(x,v)=d(u,v)}.S(u, v) = \{ x \in V : d(u, x) + d(x, v) = d(u, v) \}.

Round kk is the execution of lines L3 and L4 for this kk.

Fact 1 (pruned search is Dijkstra on a subgraph). In one call of PRUNED-SEARCH from hh in HH, let PP be the set of vertices skipped in line L7. The decision for a vertex xx is made when xx is extracted, and it only decides whether the arcs out of xx are relaxed, which happens after xx is extracted in any case. So the run is the same as a run of Dijkstra from hh in the graph H′H' obtained from HH by deleting the arcs out of the vertices of PP. As all weights are nonnegative, Dijkstra is correct on H′H': every vertex xx reachable from hh in H′H' is extracted exactly once, with key D(x)=dH′(h,x)D(x) = d_{H'}(h, x), and vertices not reachable in H′H' are never extracted.

Fact 2 (upper bounds). For every pair (k,D)(k, D) in Lin(x)\mathrm{Lin}(x), D≥d(vk,x)D \ge d(v_k, x), and for every pair (k,D)(k, D) in Lout(x)\mathrm{Lout}(x), D≥d(x,vk)D \ge d(x, v_k). Consequently, at any time, QUERY(u,v)≥d(u,v)\mathrm{QUERY}(u, v) \ge d(u, v).

Proof. A pair (k,D)(k, D) in Lin(x)\mathrm{Lin}(x) is appended in line L8 of the forward search of round kk, with D=dH′(vk,x)D = d_{H'}(v_k, x) by Fact 1. Every path in H′H' is a path in GG, so D≥d(vk,x)D \ge d(v_k, x). Backward searches run on the reverse of GG, where a path from vkv_k to xx is a path from xx to vkv_k in GG, so the same holds for out-labels. A query value is a+ba + b for some kk with (k,a)∈Lout(u)(k, a) \in \mathrm{Lout}(u) and (k,b)∈Lin(v)(k, b) \in \mathrm{Lin}(v), so a+b≥d(u,vk)+d(vk,v)≥d(u,v)a + b \ge d(u, v_k) + d(v_k, v) \ge d(u, v) by the triangle inequality. □\square

Fact 3 (what the labels hold during round kk). While the forward search of round kk runs, every out-label holds only pairs with rank less than kk. While the backward search of round kk runs, every in-label holds only pairs with rank at most kk, and the out-label of a vertex xx that has not yet been extracted in this search holds only ranks less than kk.

Proof. Pairs with rank kk are appended to out-labels only in the backward search of round kk, which starts after the forward search ends, and a vertex gets its pair from this search only when it is extracted. Pairs of rank k′>kk' > k are appended only in later rounds. □\square

Lemma 4 (no prune on the path from the first vertex). Let d(u,v)<∞d(u, v) < \infty, and let h=vkh = v_k be the vertex of S(u,v)S(u, v) of least rank. (The set is not empty, as u∈S(u,v)u \in S(u, v).)

(a) Let h=x0,x1,…,xr=vh = x_0, x_1, \ldots, x_r = v be a shortest path from hh to vv in GG. In the forward search of round kk, each xjx_j is extracted with key d(h,xj)d(h, x_j) and is not pruned.

(b) Let u=yr,yr−1,…,y0=hu = y_r, y_{r-1}, \ldots, y_0 = h be a shortest path from uu to hh in GG. In the backward search of round kk, each yjy_j is extracted with key d(yj,h)d(y_j, h) and is not pruned.

Proof of (a). First, every xjx_j is in S(u,v)S(u, v): the prefix and suffix of a shortest path are shortest, so d(h,xj)+d(xj,v)=d(h,v)d(h, x_j) + d(x_j, v) = d(h, v), and

d(u,xj)+d(xj,v)≤d(u,h)+d(h,xj)+d(xj,v)=d(u,h)+d(h,v)=d(u,v),d(u, x_j) + d(x_j, v) \le d(u, h) + d(h, x_j) + d(x_j, v) = d(u, h) + d(h, v) = d(u, v),

where the last equality holds because h∈S(u,v)h \in S(u, v). The reverse inequality is the triangle inequality, so equality holds.

Now induct on jj. Assume x0,…,xj−1x_0, \ldots, x_{j-1} are extracted and not pruned (nothing is assumed for j=0j = 0). Then their arcs are kept in H′H', so the path x0,…,xjx_0, \ldots, x_j lies in H′H', and by Fact 1, xjx_j is extracted with key D=dH′(h,xj)≤d(h,xj)D = d_{H'}(h, x_j) \le d(h, x_j). As H′H' is a subgraph of GG, D=d(h,xj)D = d(h, x_j).

Suppose xjx_j were pruned in line L7: QUERY(h,xj)≤D\mathrm{QUERY}(h, x_j) \le D. Then there are a rank k′k' and values a,ba, b with (k′,a)∈Lout(h)(k', a) \in \mathrm{Lout}(h), (k′,b)∈Lin(xj)(k', b) \in \mathrm{Lin}(x_j) and a+b≤d(h,xj)a + b \le d(h, x_j). By Fact 3, k′<kk' < k; write h′=vk′h' = v_{k'}. By Fact 2, d(h,h′)+d(h′,xj)≤a+b≤d(h,xj)d(h, h') + d(h', x_j) \le a + b \le d(h, x_j). Then

d(u,h′)+d(h′,v)≤d(u,h)+d(h,h′)+d(h′,xj)+d(xj,v)≤d(u,h)+d(h,xj)+d(xj,v)=d(u,v),d(u, h') + d(h', v) \le d(u, h) + d(h, h') + d(h', x_j) + d(x_j, v) \le d(u, h) + d(h, x_j) + d(x_j, v) = d(u, v),

using xj∈S(u,v)x_j \in S(u, v) and h∈S(u,v)h \in S(u, v) in the last step as above. So h′∈S(u,v)h' \in S(u, v) and h′h' has rank k′<kk' < k, against the choice of hh. Hence xjx_j is not pruned, which completes the induction.

Proof of (b). The same argument on the reverse of GG. Each yjy_j is in S(u,v)S(u, v) by the symmetric computation. If yjy_j were pruned, QUERY(yj,h)≤d(yj,h)\mathrm{QUERY}(y_j, h) \le d(y_j, h) would give a rank k′k' with (k′,a)∈Lout(yj)(k', a) \in \mathrm{Lout}(y_j) and (k′,b)∈Lin(h)(k', b) \in \mathrm{Lin}(h). By Fact 3, Lout(yj)\mathrm{Lout}(y_j) holds only ranks below kk when yjy_j is extracted, so k′<kk' < k, and h′=vk′h' = v_{k'} gives d(yj,h′)+d(h′,h)≤d(yj,h)d(y_j, h') + d(h', h) \le d(y_j, h). As before this puts h′h' into S(u,v)S(u, v) with rank less than kk, a contradiction. □\square

Theorem (cover property). For all u,vu, v with d(u,v)<∞d(u, v) < \infty, with h=vkh = v_k as in Lemma 4, the final labels contain (k,d(u,h))∈Lout(u)(k, d(u, h)) \in \mathrm{Lout}(u) and (k,d(h,v))∈Lin(v)(k, d(h, v)) \in \mathrm{Lin}(v).

Proof. By Lemma 4(a) with j=rj = r, the vertex vv is extracted in the forward search of round kk with key d(h,v)d(h, v) and is not pruned, so line L8 appends (k,d(h,v))(k, d(h, v)) to Lin(v)\mathrm{Lin}(v). By Lemma 4(b) with j=rj = r, line L8 of the backward search appends (k,d(u,h))(k, d(u, h)) to Lout(u)\mathrm{Lout}(u). Pairs are never removed. □\square

Corollary (queries are exact). After line L5, QUERY(u,v)=d(u,v)\mathrm{QUERY}(u, v) = d(u, v) for all u,vu, v.

Proof. Each label holds at most one pair per rank, because a vertex is extracted at most once per search, and the pairs are appended in increasing order of rank, because rounds run in increasing kk. So both lists are sorted by rank with distinct ranks, and the merge in lines L9 and L10 finds exactly the ranks in both lists. If d(u,v)<∞d(u, v) < \infty, the theorem gives a common rank kk with sum d(u,h)+d(h,v)=d(u,v)d(u, h) + d(h, v) = d(u, v), since h∈S(u,v)h \in S(u, v); by Fact 2 no sum is smaller, so line L11 returns d(u,v)d(u, v). If d(u,v)=+∞d(u, v) = +\infty, a common rank kk with finite values would give d(u,vk)<∞d(u, v_k) < \infty and d(vk,v)<∞d(v_k, v) < \infty, so vv would be reachable from uu; hence there is none and line L11 returns ∞\infty. □\square

Termination. Line L2 runs nn rounds, each with two searches. A search is Dijkstra on a finite graph: each vertex is extracted at most once and each arc relaxed at most once, so the heap receives at most m+1m + 1 entries and the search ends. Each query in line L7 merges two finite lists. So the algorithm stops after 2n2n searches. ■\blacksquare

Back to Hub labeling