The ALT query returns shortest paths full
This proof shows: correctness, termination.
Claim. Let all weights be nonnegative, let the tables hold the exact distances from and to each landmark, and let h be the bound of line L2. The query from s to t ends, scans each vertex at most once, and returns dist(s,t) with a path of that weight if t is reachable from s, and ∞ otherwise.
Write dist for distances in G, with dist(x,y)=∞ when y is not reachable from x.
Step 1: each term is a valid lower bound or proves unreachability. Fix a landmark L and a vertex v.
(a) Suppose dist(t,L)<∞. If dist(v,t)<∞, then dist(v,L)≤dist(v,t)+dist(t,L), so dist(v,L)−dist(t,L)≤dist(v,t), and in particular dist(v,L)<∞. So if dist(v,L)=∞, then dist(v,t)=∞.
(b) Suppose dist(L,v)<∞. If dist(v,t)<∞, then dist(L,t)≤dist(L,v)+dist(v,t), so dist(L,t)−dist(L,v)≤dist(v,t). If dist(L,t)=∞, then dist(v,t)=∞.
Terms of the form ∞−∞ or with an infinite subtrahend are skipped. Taking the maximum with 0: h(v)≤dist(v,t) for every v, and h(v)=∞ implies that v cannot reach t. Also h(t)=0, since each term at v=t is 0 or skipped.
Step 2: consistency. Let (u,v) be an edge with h(u)<∞ and h(v)<∞. Consider a term at u. For (a) with dist(t,L)<∞: dist(u,L)≤w(u,v)+dist(v,L), and dist(v,L)<∞ since otherwise h(v)=∞; so dist(u,L)−dist(t,L)≤w(u,v)+(dist(v,L)−dist(t,L))≤w(u,v)+h(v). For (b) with dist(L,u)<∞: dist(L,v)≤dist(L,u)+w(u,v)<∞, and dist(L,t)<∞ since otherwise h(u)=∞; so dist(L,t)−dist(L,u)≤w(u,v)+(dist(L,t)−dist(L,v))≤w(u,v)+h(v). The term 0 is at most w(u,v)+h(v) since both are nonnegative. Taking the maximum, h(u)≤w(u,v)+h(v).
Step 3: pruning is safe. Let V′={v:h(v)<∞} and G′ the subgraph induced by V′. Line L8 never puts a vertex outside V′ into Q, and if h(s)=∞ the queue starts empty; so the query is A* on G′. By Step 1, every vertex on an s-t path of G can reach t, so if it had h=∞ it could not; hence every s-t path of G lies in G′, and distG′(s,t)=dist(s,t). If h(s)=∞, then s cannot reach t and returning ∞ is correct.
Step 4: the query is Dijkstra on reduced weights. On G′ define wh(u,v)=w(u,v)−h(u)+h(v), which is ≥0 by Step 2. For a path P from s to v in G′, the sum telescopes: wh(P)=w(P)−h(s)+h(v). Define g′[v]=g[v]+h(v)−h(s). Line L3 sets g′[s]=0; line L8 tests g[u]+w(u,v)<g[v], which is g′[u]+wh(u,v)<g′[v]; line L9 sets g′[v]=g′[u]+wh(u,v); and line L5 picks the least g[u]+h(u)=g′[u]+h(s), the least g′. So the run is exactly Dijkstra's algorithm from s on G′ with the nonnegative weights wh, with labels g′, and stopped when t is removed. (A vertex re-entered with a smaller key is a decrease-key; the implementation's stale heap entries are skipped.)
Step 5: conclusion. By the correctness of Dijkstra's algorithm on nonnegative weights, each vertex is removed at most once, and when u is removed, g′[u]=distwh(s,u), the reduced distance in G′, and the predecessors give a path of that reduced weight. By Step 4 the reduced weight of any s-u path differs from its weight by the constant h(u)−h(s), so the same path is a shortest path in G′ and g[u]=distG′(s,u). If t is removed, line L6 returns g[t]=distG′(s,t)=dist(s,t) by Step 3, with a path of that weight. If t is never removed, the queue empties, so Dijkstra has removed every vertex of G′ reachable from s, hence t is not reachable from s in G′, hence not in G by Step 3, and line L10 returns ∞ correctly.
Termination. Each vertex is removed at most once and each removal inserts at most one entry per edge, so the loop runs at most n+m times. ■