Math 2.0

Combinatorics Definition

Floyd–Warshall algorithm

Builds on Directed graphPathCycleAlgorithm

Definition

Let GG be a finite directed graph with vertex set {1,…,n}\set{1, \dots, n} and edge weights w(i,j)∈ℝw(i, j) \in \R. Assume that GG has no cycle of negative total weight. The Floyd–Warshall algorithm is the algorithm that computes numbers dk(i,j)d_k(i, j) for k=0,1,…,nk = 0, 1, \dots, n as follows.

  1. d0(i,i)=0d_0(i, i) = 0; d0(i,j)=w(i,j)d_0(i, j) = w(i, j) if i≠ji \ne j and (i,j)(i, j) is an edge; and d0(i,j)=∞d_0(i, j) = \infty otherwise.
  2. For k≥1k \ge 1, dk(i,j)=min⁡(dk−1(i,j), dk−1(i,k)+dk−1(k,j))d_k(i, j) = \min\bigl(d_{k-1}(i, j),\ d_{k-1}(i, k) + d_{k-1}(k, j)\bigr).

It returns dn(i,j)d_n(i, j) for all pairs (i,j)(i, j). Here dk(i,j)d_k(i, j) is the least weight of a directed path from ii to jj whose intermediate vertices all lie in {1,…,k}\set{1, \dots, k}. So dn(i,j)d_n(i, j) is the shortest path distance from ii to jj.

Remarks

Example: with edges 1→21 \to 2 of weight 33, 2→32 \to 3 of weight 44 and 1→31 \to 3 of weight 1010, one has d1(1,3)=10d_1(1, 3) = 10 and d2(1,3)=min⁡(10,3+4)=7=d3(1,3)d_2(1, 3) = \min(10, 3 + 4) = 7 = d_3(1, 3).

Non-example: if the hypothesis fails, say GG has the cycle 1→2→11 \to 2 \to 1 of total weight −1-1, then no shortest walk from 11 to 22 exists. The recurrence still runs, and the negative cycle shows up as dn(i,i)<0d_n(i, i) < 0 for a vertex ii on it.

The table can be updated in place, so the algorithm needs O(n2)O(n^2) memory and O(n3)O(n^3) time.

Reading path

To understand this page from the ground up, read these 5 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Cycle concept
  3. Directed graph concept
  4. Path concept
  5. Floyd–Warshall algorithm definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm
About this page
TagPXNQBKSQ9F
URIm2://PXNQBKSQ9F
Kinddefinition
WritingW0 stub
MSC05C85, 90C35, 68W40
DefinesFloyd–Warshall algorithm
UsesDirected graph, Path, Cycle, Algorithm
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.