Prev     Next
Express a Loop Invariant

Let S be the starting node.
At iteration i all nodes which were visited on iteration k < i
are a minimum of k hops from S...
and minimum path back to S is determined by "back" labels.
What if i=1?
All nodes reached are neighbors of S and are one hop from it.
Back labels all point to S.
What if i > 1?
Assume hypothesis holds for iterations 1, 2, 3, ..., i.
Does this mean it holds for iteration i+1?
A node N reached from S at iteration i+1 is a neighbor of a node X reached at iteration i
and, by hypothesis, we know the minimum number of hops from X to S is i.
Since N could not be reached by iteration i the minimum number of hops from N to S
is no less than i+1.
But we just found a way to reach N using i+1 hops so that must be the minimum.