Talk:Floyd–Warshall algorithm

This is an old revision of this page, as edited by Netvor (talk | contribs) at 15:32, 28 June 2005 (Predecessor matrix?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Change pseudocode to Wikicode?

The pseudocode in this article is very hard to understand. I suggest changing it to something like this:

Template:Wikicode

 function fw(int[0..n,0..n] graph) {
     var int[0..n,0..n] dist := graph
     for k from 0 to n
         for i from 0 to n
             for j from 0 to n
                 if dist[i,j] > dist[i,k] + dist[k,j]
                     dist[i,j] = dist[i,k] + dist[k,j]
     return dist
 }

I will change this soon if nobody protests

Predecessor matrix?

Wouldn't it be advantageous to also mention the predecessor matrix Pk[i,j] defined as the predecessor of j on the shortest path from i to j, using internal nodes 1...k? We would add the following to the pseudocode. First initialization:

var int[0..n,0..n] pred
    for i from 0 to n
        for j from 0 to n
            if dist[i,j] > 0
                pred[i,j] := i

Next, we add one more line after the "dist[i,j] = dist[i,k] + dist[k,j]" line:

pred[i,j] = pred[k,j]

I'm not entirely sure if this addition would be appreciated. Being a novice Wikipedian, I decided I won't make the addition but rather post it here. If an experienced Wikipedian thinks it's a good addition, please make it.