title: Floyd-Warshall Algorithm Logic - Stuck
body: <p>I am trying to use this logic to understand what is going on with the <a href="http://en.wikipedia.org/wiki/Adjacency_matrix" rel="nofollow noreferrer">adjacency matrix</a>, but i am massivley confused where it says about interspacing for a b c d .....</p>
  
  <p>Could anyone explain what is going on here?</p>
  
  <p>Thank you
  (tagged as java as its the language this was demonstrated to us in, so if anyone posted any code examples they could see it was in that language)</p>
  
  <p><a href="http://compprog.wordpress.com/2007/11/15/all-sources-shortest-path-the-floyd-warshall-algorithm/" rel="nofollow noreferrer">http://compprog.wordpress.com/2007/11/15/all-sources-shortest-path-the-floyd-warshall-algorithm/</a></p>
  
  <p>Here is the code:</p>
  
  <pre><code>for (k = 0; k &lt; n; ++k) {
      for (i = 0; i &lt; n; ++i)
          for (j = 0; j &lt; n; ++j)
              /* If i and j are different nodes and if
                 the paths between i and k and between
                 k and j exist, do */
              if ((dist[i][k] * dist[k][j] != 0) &amp;&amp; (i != j))
                  /* See if you can't get a shorter path
                     between i and j by interspacing
                     k somewhere along the current
                     path */
                  if ((dist[i][k] + dist[k][j] &lt; dist[i][j]) ||
                          (dist[i][j] == 0))
                      dist[i][j] = dist[i][k] + dist[k][j];
  </code></pre>