Algorithm
Floyd-Warshall Algorithm:
- Initialize a 2D array `dist[][]` to represent the shortest distances between every pair of vertices.
- Set `dist[i][j]` to the weight of the edge between vertex `i` and vertex `j`. If no edge exists, set it to infinity (`INF`).
- For each vertex `k` in the graph:
- For each pair of vertices `(i, j)`:
- Check if the vertex `k` can be used as an intermediate vertex to provide a shorter path from `i` to `j`.
- If `dist[i][k] + dist[k][j] < dist[i][j]`, update `dist[i][j]` to `dist[i][k] + dist[k][j]`.
- For each pair of vertices `(i, j)`:
- After processing all vertices, `dist[i][j]` will contain the shortest distance between vertex `i` and vertex `j`.
Example:

Fig. 1: Step-by-Step Process of Floyd-Warshall Algorithm
Note: The Floyd-Warshall Algorithm works for both directed and undirected graphs but does not handle negative weight cycles.