Initialize an array with and for . For , replace every entry in place by
This is the Floyd-Warshall algorithm. At the start of stage , the induction hypothesis is . During that stage, row and column do not change: and no negative cycle can lower it. Hence the operands remain the stage-start values even with in-place updates. Part (b) proves that after the stage every entry is . Induction gives all shortest path lengths after stage . The algorithm uses stored lengths and arithmetic operations, with only a fixed number of loop counters beyond the array.