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 be a directed graph with weights and let be the order of the vertices. Write for the shortest-path distance, if is not reachable from . The rank of is . For vertices with , let
Round is the execution of lines L3 and L4 for this .
Fact 1 (pruned search is Dijkstra on a subgraph). In one call of PRUNED-SEARCH from in , let be the set of vertices skipped in line L7. The decision for a vertex is made when is extracted, and it only decides whether the arcs out of are relaxed, which happens after is extracted in any case. So the run is the same as a run of Dijkstra from in the graph obtained from by deleting the arcs out of the vertices of . As all weights are nonnegative, Dijkstra is correct on : every vertex reachable from in is extracted exactly once, with key , and vertices not reachable in are never extracted.
Fact 2 (upper bounds). For every pair in , , and for every pair in , . Consequently, at any time, .
Proof. A pair in is appended in line L8 of the forward search of round , with by Fact 1. Every path in is a path in , so . Backward searches run on the reverse of , where a path from to is a path from to in , so the same holds for out-labels. A query value is for some with and , so by the triangle inequality.
Fact 3 (what the labels hold during round ). While the forward search of round runs, every out-label holds only pairs with rank less than . While the backward search of round runs, every in-label holds only pairs with rank at most , and the out-label of a vertex that has not yet been extracted in this search holds only ranks less than .
Proof. Pairs with rank are appended to out-labels only in the backward search of round , which starts after the forward search ends, and a vertex gets its pair from this search only when it is extracted. Pairs of rank are appended only in later rounds.
Lemma 4 (no prune on the path from the first vertex). Let , and let be the vertex of of least rank. (The set is not empty, as .)
(a) Let be a shortest path from to in . In the forward search of round , each is extracted with key and is not pruned.
(b) Let be a shortest path from to in . In the backward search of round , each is extracted with key and is not pruned.
Proof of (a). First, every is in : the prefix and suffix of a shortest path are shortest, so , and
where the last equality holds because . The reverse inequality is the triangle inequality, so equality holds.
Now induct on . Assume are extracted and not pruned (nothing is assumed for ). Then their arcs are kept in , so the path lies in , and by Fact 1, is extracted with key . As is a subgraph of , .
Suppose were pruned in line L7: . Then there are a rank and values with , and . By Fact 3, ; write . By Fact 2, . Then
using and in the last step as above. So and has rank , against the choice of . Hence is not pruned, which completes the induction.
Proof of (b). The same argument on the reverse of . Each is in by the symmetric computation. If were pruned, would give a rank with and . By Fact 3, holds only ranks below when is extracted, so , and gives . As before this puts into with rank less than , a contradiction.
Theorem (cover property). For all with , with as in Lemma 4, the final labels contain and .
Proof. By Lemma 4(a) with , the vertex is extracted in the forward search of round with key and is not pruned, so line L8 appends to . By Lemma 4(b) with , line L8 of the backward search appends to . Pairs are never removed.
Corollary (queries are exact). After line L5, for all .
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 . 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 , the theorem gives a common rank with sum , since ; by Fact 2 no sum is smaller, so line L11 returns . If , a common rank with finite values would give and , so would be reachable from ; hence there is none and line L11 returns .
Termination. Line L2 runs 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 entries and the search ends. Each query in line L7 merges two finite lists. So the algorithm stops after searches.