Question
The Floyd-Warshall algorithm for ALL-PAIRS SHORTEST PATHS is shown in Figure 3.30. The only difference between it and the matrix-squaring algorithm we gafve in Section
The Floyd-Warshall algorithm for ALL-PAIRS SHORTEST PATHS is shown in Figure 3.30. The only difference between it and the matrix-squaring algorithm we gafve in Section 3.4.3 is that the loop over k is now outside the loops over i and j, rather than being the innermost. Surprisingly, this change means that we no longer need to repeat this process times with an additional outer loop, so the running time is now instead of .
Prove that this algorithm works. Hint: state a loop invariant that holds after running the outer loop k times, and use induction on k.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started