这是从该站点复制的Warshall算法的实现 https://rosettacode.org/wiki/Floyd-Warshall_algorithm#Java
我需要的是分析这个算法。我已经做了但我想确保一切正确。
for (int i = 0; i < weights.length; i++) { //O(E)?
dist[weights[i][0] - 1][weights[i][1] - 1] = weights[i][2];}
for (int i = 0; i < next.length; i++) {//O(v^2)
for (int j = 0; j < next.length; j++)
if (i != j)
next[i][j] = j + 1;
}
for (int k = 0; k < numVertices; k++)//O(v^3)
for (int i = 0; i < numVertices; i++)
for (int j = 0; j < numVertices; j++)
if (dist[i][k] + dist[k][j] < dist[i][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
next[i][j] = next[i][k];
}
//Finally takes O(v^3)