1
$\begingroup$

I am studying how Floyd-Warshall works and came across this doubt.
In the code:

for(int k = 0; k < V; k++)
    for(int i = 0; i < V; i++)
        for(int j = 0; j < V; j++)
            Matrix[i][j] = min(Matrix[i][j], Matrix[i][k] + Matrix[k][j]);

I can see I can not change order of k because it is the intermediate vertex. The order of i and j, on the other hand, seems like don't necessarily need to be in that position.

Am I wrong? All I can see is that they are just the combination of pairs with k in the middle.

$\endgroup$
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.