An **intermediate** vertex of a simple path p =
<*v*_{1}, *v*_{2}, .., *v*_{l}>is any vertex of p other than *v*_{1} and *v*_{l}.

The Floyd-Warshall (FW) algorithm works by successively reducing the number of intermediate vertices that can occur in a shortest path and its subpaths.

Let graph G = (V, E) have vertices V numbered 1 .. *n*,
V = {1, 2, .., n}, and consider a subset {1, 2, .., k}
for some k.

Let p be the minimum weight path from vertex i to vertex j whose intermediate vertices are drawn from {1, 2, .., k}. One of two situations then occur:

- 1.
- k is not an intermediate vertex of p
contains vertices from {1, 2, .., k-1}
- 2.
- k is an intermediate vertex of p
contains vertices from {1, 2, .., k-1}
*p*_{1}is the shortest path from i to k*p*_{2}is the shortest path from k to j(by Lemma 24.1)