Knowee
Questions
Features
Study Tools

What procedure is being followed in Floyd Warshall Algorithm?

Question

What procedure is being followed in Floyd Warshall Algorithm?

🧐 Not the exact question you are looking for?Go ask a question

Solution

The Floyd Warshall Algorithm is a popular algorithm used for finding the shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles). Here is the step-by-step procedure:

  1. Initialize the solution matrix same as the input graph matrix as a first step. We update the solution matrix by considering all vertices as an intermediate vertex. The idea is to one by one pick all vertices and update all shortest paths which include the picked vertex as an intermediate vertex in the shortest path. When we pick vertex number k as an intermediate vertex, we have already considered vertices {0, 1, 2, .. k-1} as intermediate vertices.

  2. For every pair (i, j) of the source and destination vertices respectively, there are two possible cases. a) k is not an intermediate vertex in shortest path from i to j. We keep the value of dist[i][j] as it is. b) k is an intermediate vertex in shortest path from i to j. We update the value of dist[i][j] to dist[i][k] + dist[k][j] if dist[i][j] > dist[i][k] + dist[k][j]

  3. Repeat step 2 for different intermediate vertices.

  4. After we have updated the solution matrix, if dist[i][j] is infinite, then there is no path from vertex i to j. If dist[i][j] is not infinite and it is not equal to dist[j][i], then the direction of path is from vertex i to j. Else, the direction of path is from vertex j to i.

  5. The final matrix obtained after all the iterations is the shortest path matrix. The element at the i-th row and j-th column represents the shortest distance from the i-th vertex to the j-th vertex.

This is the basic procedure followed in the Floyd Warshall Algorithm.

This problem has been solved

Similar Questions

What procedure is being followed in Floyd Warshall Algorithm?Marks : 1Negative Marks : 0Answer hereTop downBottom upBig bangSandwich

Write and explain the Floyd Warshall algorithm to find the allpair shortest path

Floyd-Warshall algorithm utilizes __________ to solve the all-pairs shortest paths problem on a directed graph in __________ time.

What happens when the value of k is 0 in the Floyd Warshall Algorithm? Options 1 intermediate vertex 0 intermediate vertex N intermediate vertices N-1 intermediate vertices

Roy-Warshall Algorithm

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.