tex2html_deferredGiven | |||
Floyd's Algorithm
A[i, j] | = | C[i, j] if ij | (7.12) |
= | 0 if i = j |
Note that C[i, j] is taken as if there is no directed arc from ito j.
Ak - 1[i, j] | = | (7.13) | |
(7.14) | |||
See Figure 7.8
{ int i, j, k;
{ for(i = 0, in - 1;i + +)
for(j = 0;jn - 1, j + +)
A[i, j] = C[i, j];
for(i = 0;in - 1;i + +)
A[i, i] = 0;
for(k = 0;kn - 1;k + +);
{
for(i = 0;in - 1;i + +)
{
for(j = 0;jn - 1, j + +)
if(A[i, k] + A[k, j] < A[i, j])
A[i, j] = A[i, k] + A[k, j]
}
}
}
}
Example: See Figure 7.9.
A0 | = | ; A1 = | (7.15) |
A2 | = | ; A3 = |