Algorithm Search⌘K

Proofs: ALT algorithm

These are the human proofs of ALT algorithm, at full length.

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 hh be the bound of line L2. The query from ss to tt ends, scans each vertex at most once, and returns dist⁡(s,t)\operatorname{dist}(s, t) with a path of that weight if tt is reachable from ss, and ∞\infty otherwise.

Write dist⁡\operatorname{dist} for distances in GG, with dist⁡(x,y)=∞\operatorname{dist}(x, y) = \infty when yy is not reachable from xx.

Step 1: each term is a valid lower bound or proves unreachability. Fix a landmark LL and a vertex vv. (a) Suppose dist⁡(t,L)<∞\operatorname{dist}(t, L) < \infty. If dist⁡(v,t)<∞\operatorname{dist}(v, t) < \infty, then dist⁡(v,L)≤dist⁡(v,t)+dist⁡(t,L)\operatorname{dist}(v, L) \le \operatorname{dist}(v, t) + \operatorname{dist}(t, L), so dist⁡(v,L)−dist⁡(t,L)≤dist⁡(v,t)\operatorname{dist}(v, L) - \operatorname{dist}(t, L) \le \operatorname{dist}(v, t), and in particular dist⁡(v,L)<∞\operatorname{dist}(v, L) < \infty. So if dist⁡(v,L)=∞\operatorname{dist}(v, L) = \infty, then dist⁡(v,t)=∞\operatorname{dist}(v, t) = \infty. (b) Suppose dist⁡(L,v)<∞\operatorname{dist}(L, v) < \infty. If dist⁡(v,t)<∞\operatorname{dist}(v, t) < \infty, then dist⁡(L,t)≤dist⁡(L,v)+dist⁡(v,t)\operatorname{dist}(L, t) \le \operatorname{dist}(L, v) + \operatorname{dist}(v, t), so dist⁡(L,t)−dist⁡(L,v)≤dist⁡(v,t)\operatorname{dist}(L, t) - \operatorname{dist}(L, v) \le \operatorname{dist}(v, t). If dist⁡(L,t)=∞\operatorname{dist}(L, t) = \infty, then dist⁡(v,t)=∞\operatorname{dist}(v, t) = \infty. Terms of the form ∞−∞\infty - \infty or with an infinite subtrahend are skipped. Taking the maximum with 0: h(v)≤dist⁡(v,t)h(v) \le \operatorname{dist}(v, t) for every vv, and h(v)=∞h(v) = \infty implies that vv cannot reach tt. Also h(t)=0h(t) = 0, since each term at v=tv = t is 00 or skipped.

Step 2: consistency. Let (u,v)(u, v) be an edge with h(u)<∞h(u) < \infty and h(v)<∞h(v) < \infty. Consider a term at uu. For (a) with dist⁡(t,L)<∞\operatorname{dist}(t, L) < \infty: dist⁡(u,L)≤w(u,v)+dist⁡(v,L)\operatorname{dist}(u, L) \le w(u, v) + \operatorname{dist}(v, L), and dist⁡(v,L)<∞\operatorname{dist}(v, L) < \infty since otherwise h(v)=∞h(v) = \infty; so dist⁡(u,L)−dist⁡(t,L)≤w(u,v)+(dist⁡(v,L)−dist⁡(t,L))≤w(u,v)+h(v)\operatorname{dist}(u, L) - \operatorname{dist}(t, L) \le w(u, v) + (\operatorname{dist}(v, L) - \operatorname{dist}(t, L)) \le w(u, v) + h(v). For (b) with dist⁡(L,u)<∞\operatorname{dist}(L, u) < \infty: dist⁡(L,v)≤dist⁡(L,u)+w(u,v)<∞\operatorname{dist}(L, v) \le \operatorname{dist}(L, u) + w(u, v) < \infty, and dist⁡(L,t)<∞\operatorname{dist}(L, t) < \infty since otherwise h(u)=∞h(u) = \infty; so dist⁡(L,t)−dist⁡(L,u)≤w(u,v)+(dist⁡(L,t)−dist⁡(L,v))≤w(u,v)+h(v)\operatorname{dist}(L, t) - \operatorname{dist}(L, u) \le w(u, v) + (\operatorname{dist}(L, t) - \operatorname{dist}(L, v)) \le w(u, v) + h(v). The term 0 is at most w(u,v)+h(v)w(u, v) + h(v) since both are nonnegative. Taking the maximum, h(u)≤w(u,v)+h(v)h(u) \le w(u, v) + h(v).

Step 3: pruning is safe. Let V′={v:h(v)<∞}V' = \{v : h(v) < \infty\} and G′G' the subgraph induced by V′V'. Line L8 never puts a vertex outside V′V' into QQ, and if h(s)=∞h(s) = \infty the queue starts empty; so the query is A* on G′G'. By Step 1, every vertex on an ss-tt path of GG can reach tt, so if it had h=∞h = \infty it could not; hence every ss-tt path of GG lies in G′G', and dist⁡G′(s,t)=dist⁡(s,t)\operatorname{dist}_{G'}(s, t) = \operatorname{dist}(s, t). If h(s)=∞h(s) = \infty, then ss cannot reach tt and returning ∞\infty is correct.

Step 4: the query is Dijkstra on reduced weights. On G′G' define wh(u,v)=w(u,v)−h(u)+h(v)w_h(u, v) = w(u, v) - h(u) + h(v), which is ≥0\ge 0 by Step 2. For a path PP from ss to vv in G′G', the sum telescopes: wh(P)=w(P)−h(s)+h(v)w_h(P) = w(P) - h(s) + h(v). Define g′[v]=g[v]+h(v)−h(s)g'[v] = g[v] + h(v) - h(s). Line L3 sets g′[s]=0g'[s] = 0; line L8 tests g[u]+w(u,v)<g[v]g[u] + w(u, v) < g[v], which is g′[u]+wh(u,v)<g′[v]g'[u] + w_h(u, v) < g'[v]; line L9 sets g′[v]=g′[u]+wh(u,v)g'[v] = g'[u] + w_h(u, v); and line L5 picks the least g[u]+h(u)=g′[u]+h(s)g[u] + h(u) = g'[u] + h(s), the least g′g'. So the run is exactly Dijkstra's algorithm from ss on G′G' with the nonnegative weights whw_h, with labels g′g', and stopped when tt 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 uu is removed, g′[u]=dist⁡wh(s,u)g'[u] = \operatorname{dist}_{w_h}(s, u), the reduced distance in G′G', and the predecessors give a path of that reduced weight. By Step 4 the reduced weight of any ss-uu path differs from its weight by the constant h(u)−h(s)h(u) - h(s), so the same path is a shortest path in G′G' and g[u]=dist⁡G′(s,u)g[u] = \operatorname{dist}_{G'}(s, u). If tt is removed, line L6 returns g[t]=dist⁡G′(s,t)=dist⁡(s,t)g[t] = \operatorname{dist}_{G'}(s, t) = \operatorname{dist}(s, t) by Step 3, with a path of that weight. If tt is never removed, the queue empties, so Dijkstra has removed every vertex of G′G' reachable from ss, hence tt is not reachable from ss in G′G', hence not in GG by Step 3, and line L10 returns ∞\infty 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+mn + m times. ■\blacksquare

Back to ALT algorithm