The *Ford-Fulkerson algorithm* is an algorithm for finding the maximum flow (which see!), and consequently *constructing* a maximal flow, in a capacitated graph.

Let G=(V,E) be directed graph, let s,t∈V be source and sink vertices, and let c:E→[0,∞) be capacities for the edges of G. We're seeking a *maximal* flow: a flow f:E→[0,&infin) of the maximal possible size

|f| =
∑_{{v: (s,v)∈E}} f(s,v) -
∑_{{v: (v,s)∈E}} f(v,s) =
∑_{{u: (u,t)∈E}} f(u,t) -
∑_{{u: (t,u)∈E}} f(t,u)

on (G,s,t,c).

The Ford-Fulkerson algorithm does the simplest thing possible. At each iteration it has some feasible flow f, which it attempts to improve. It searches for a **un**directed path from s to t which isn't saturated.

A path P=(v_{0},v_{1},...,v_{k}) is *saturated* if for each i=1,...,k,
f(v_{i-1},v_{i}) = c(v_{i-1},v_{i}) if (v_{i-1},v_{i})∈E, or

f(v_{i},v_{i-1}) = 0 if (v_{i},v_{i-1})∈E

Such a path can be easily found, using any of the path-seeking algorithms (e.g.

Dijkstra's algorithm).

Suppose there is such an unsaturated path, then we can improve the flow f very easily. Define the *slack* of the edges along the path:

- For each edge e
_{i}=(v_{i-1},v_{i})∈E, we can define d_{i} = c(v_{i-1},v_{i})-f(v_{i-1},v_{i}) > 0;
- For each edge e
_{i}=(v_{i},v_{i-1})∈E, we can define d_{i} = f(v_{i-1},v_{i}) > 0.

Taking d =

min_{i=1,...,k} d

_{i}, we see that we can

augment the flow by d. Define a new flow f' by:

- For each edge e
_{i}=(v_{i-1},v_{i})∈E, define 0 ≤ f'(e_{i}) = f(e_{i}) + d ≤ c(v_{i-1},v_{i}).
- For each edge e
_{i}=(v_{i},v_{i-1})∈E, define 0 ≤ f'(e_{i}) = f(e_{i}) - d ≤ c(v_{i-1},v_{i}).
- For every other edge e not in the path, define f'(e)=f(e).

Then f' is a flow, with |f'| = |f|+d > |f|.

So we have a procedure to increase any flow with an unsaturated path. The Ford-Fulkerson algorithm is simply:

- Initialise some flow (usually f=0).
- Find an unsaturated path for the flow f; if all paths are saturated, terminate.
- Otherwise: Increase flow f along the unsaturated path, and continue with step 2.

See a proof of the Ford-Fulkerson algorithm for and why if the algorithm terminates it finds a correct answer, and for why this algorithm does indeed terminate when all values are integers. Note that if all capacities are integers, and if we start with the flow f≡0, then all values in every flow appearing in the algorithm are also integers. Thus, we have that

If all capacities are integers, the size of the maximal flow is an integer, and there exists a maximal flow with integer flows along each edge.

Running time for the algorithm -- *when all capacities are integers* -- is O(n⋅m⋅c) -- the product of the number of vertices (giving a bound on the time to find an unsaturated path), the number of edges, and the maximal capacity of all edges. More efficient algorithms exist, but Ford-Fulkerson offers the nicest formulation.

We also have the following neat results which follow from the proof:

- "max flow = min cut": The maximal flow -- that found by the algorithm -- has equal size to the size of the minimal cut in the graph.
- Linear programming: Maximal flow is a linear programming problem (in particular, general algorithms for linear programming will solve it). Minimal cut is its dual problem, so the above is a special case of duality in linear programming.
- Related NP-complete problems:
- max cut is NP-complete; evidently we were lucky with the structure of the "max flow" problem.
- Integer linear programming -- linear programming with all scalars limited to integer values -- is NP-complete; evidently we were
*extremely* lucky with the structure of the "max flow" problem, which allows us to find integer solutions to a (particular type of) integer linear programming problem.