Floyd Warshall Calculator

Build matrices quickly, test directed graphs, and verify costs. Review intermediate updates and decisions clearly. Solve complex routing problems with stepwise shortest path outputs.

Graph Input

Enter a weighted adjacency matrix. Use numbers for edge costs and INF for missing edges.

Example Data Table

This sample graph demonstrates directed weighted edges and missing links.

From To Weight
AB3
AD7
BA8
BC2
CA5
CD1
DA2

Formula Used

d(i, j, k) = min(d(i, j, k-1), d(i, k, k-1) + d(k, j, k-1))

The Floyd Warshall method improves every pair distance by testing each node as an intermediate stop. It starts with the original adjacency matrix and repeatedly updates distances whenever a shorter route appears through node k.

Path reconstruction uses a next-hop matrix. When distance i→j improves through k, the first step becomes the first step of i→k. Negative cycles are flagged whenever any final diagonal distance becomes negative.

How to Use This Calculator

  1. Choose the number of nodes in your graph.
  2. Enter node labels separated by commas, such as A, B, C, D.
  3. Paste the adjacency matrix with one row per line.
  4. Use INF where a direct edge does not exist.
  5. Select directed or undirected behavior.
  6. Pick a start and end index for one highlighted shortest route.
  7. Enable intermediate iterations when you want stepwise updates.
  8. Submit the form to view matrices, route details, diagnostics, and exports.

FAQs

1. What does this calculator compute?

It computes shortest distances between every ordered pair of nodes. It also shows a next-hop matrix, a selected route, graph metrics, and optional intermediate iterations.

2. Can I use negative edge weights?

Yes. Floyd Warshall supports negative edges as long as the graph does not contain a reachable negative cycle that makes shortest paths undefined.

3. How are missing edges entered?

Use INF for any missing direct edge. The calculator treats that cell as unreachable until another indirect route produces a finite path.

4. What does the next-hop matrix show?

Each cell shows the first node to visit when traveling from one source node to a destination along a shortest path. It helps reconstruct routes quickly.

5. Why are diagonal values important?

The diagonal usually starts at zero because every node reaches itself with no cost. A negative final diagonal value signals a negative cycle.

6. What happens in undirected mode?

The calculator mirrors each edge weight across the diagonal. If opposite directions differ, it keeps the smaller finite value for both directions.

7. Why might no selected route appear?

No route appears when the destination remains unreachable from the chosen source. In that case, the final distance stays INF and the path is empty.

8. When should I enable intermediate iterations?

Enable them when learning the method, debugging a matrix, or verifying how each intermediate node improves distances during the dynamic programming process.

Related Calculators

topological sort calculatorminimum spanning tree calculatorgraph distance calculatorford fulkerson calculatorvertex degree calculatorconnected components countereulerian path calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.