Step 1: Initialize distance matrix with direct edges and 0 for same nodes
[[0,5,∞,10],
[∞,0,3,∞],
[∞,∞,0,1],
[∞,∞,∞,0]]
Why: Start with known distances: direct edges or infinity if no direct path
Step 2: Use node 0 as intermediate: update distances if going through 0 is shorter
[[0,5,∞,10],
[∞,0,3,∞],
[∞,∞,0,1],
[∞,∞,∞,0]]
Why: No shorter paths found through node 0 yet
Step 3: Use node 1 as intermediate: update distance 0->2 via 1 (5+3=8 < ∞)
[[0,5,8,10],
[∞,0,3,∞],
[∞,∞,0,1],
[∞,∞,∞,0]]
Why: Going 0->1->2 is shorter than no direct path
Step 4: Use node 2 as intermediate: update distance 0->3 via 2 (8+1=9 < 10) and 1->3 via 2 (3+1=4 < ∞)
[[0,5,8,9],
[∞,0,3,4],
[∞,∞,0,1],
[∞,∞,∞,0]]
Why: Going 0->1->2->3 and 1->2->3 are shorter than direct or previous paths
Step 5: Use node 3 as intermediate: no shorter paths found
[[0,5,8,9],
[∞,0,3,4],
[∞,∞,0,1],
[∞,∞,∞,0]]
Why: No improvements by going through node 3
Result: Final shortest path matrix:
[[0,5,8,9],
[∞,0,3,4],
[∞,∞,0,1],
[∞,∞,∞,0]]