AlgoFrames

Which loop goes outside?

Standard · Multiple choice · about 3 min

A student writes Floyd-Warshall with the loops in the order i, j, k, so k is the innermost loop. On the chain shown, one cell comes out wrong. Why?

Example 1

Input:

{"edges":[[0,3,1],[3,2,1],[2,1,1]]}

Output:

The cell is finished before its parts are final

Cell (0, 1) should be 3.

Learn the idea first: Floyd-Warshall: all pairs, a visual lesson.

More Floyd-Warshall: all pairs problems