Floyd-Warshall Algorithm

If you want to find the length of node and shorthest path in a graph we can use Floyd-Warshall Algorithm

`
int [][] map = new int[n][n];
for (int i = 0; i < n; i++) {
Arrays.fill(map[i], Integer.MAX_VALUE/2);
}
for (int i = 0; i < n; i++) {
map[i][i] = 0;
}
for (int i = 0; i < a.length; i++) {
map[a[i]-1][b[i]-1] = len[i];
map[b[i]-1][a[i]-1] = len[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int j2 = 0; j2 < n; j2++) {
map[j][j2] = Math.min(map[j][j2], map[j][i] + map[i][j2]);
}
}

    }

`

You can see the explanation in here : http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm

 
0
Kudos
 
0
Kudos

Now read this

Working for kawalpemilu for android

On 9 July, Indonesia is doing the biggest democracy event for Indonesian poeple - The Election of Indonesian Presiden (Pemilu in Indonesian). The euforia is so big. Social media is so crowded about news from candidate no 1 Prabowo... Continue →