Explaining why BFS makes Edmonds-Karp polynomial
BFS finds the shortest augmenting path in the residual graph, ensuring these path lengths never decrease as flow augments. Each augmentation saturates an edge on a shortest path, and since each edge can be saturated at most O(V) times, the total number of augmentations is O(VE), giving Edmonds-Karp a guaranteed polynomial O(VE²) runtime. In contrast, DFS can pick arbitrary paths that cause many small or reversing augmentations, potentially leading to exponential time.
The algorithm that is usually called “Edmonds–Karp” is not a different maximum–flow algorithm, it is a particular way of instantiating Ford–Fulkerson’s augmenting–path scheme. The mechanics are:
- Maintain a residual graph (G_f) consisting of those arcs with spare capacity in either direction with respect to the current flow (f).
- While there is an (s)–(t) path in (G_f):
- Run a breadth–first search from (s) in (G_f) to find a shortest (s)–(t) path in terms of number of edges.
- Let (\delta) be the minimum residual capacity on that path.
- Increase (f) by (\delta) along the forward arcs of the path and decrease (f) by (\delta) along the backward arcs.
The only difference from a “plain” Ford–Fulkerson implementation is the tie–breaking rule “pick a shortest path”, and that is enough to give you a polynomial bound on the number of augmentations.
The key properties of BFS in this context are:
- If you define (d(v)) to be the length of the shortest residual path from (s) to (v), the sequence of distance labels (d) is non‑decreasing as the algorithm runs. Augmenting along a shortest path cannot create a new, strictly shorter path to any vertex.
- Each augmentation saturates at least one forward edge ((u,v)) on a shortest path with (d(v)=d(u)+1). For that edge to re‑appear as a forward edge on a shortest path, (d(u)) and (d(v)) have to both increase, because the current shortest (s)–(t) distance has not gone down.
From these observations one can show that a fixed directed edge ((u,v)) can become “critical” on a shortest augmenting path at most (O(V)) times: every time it is saturated, the BFS level of (u) must increase by at least one before ((u,v)) can be used again in the same direction. There are (O(E)) edges, so there are at most (O(VE)) augmentations in total. Each augmentation requires one BFS taking (O(E)) time, which gives the standard (O(VE^{2})) running time bound.
In contrast, the generic Ford–Fulkerson method says “find any augmenting path”. Depth–first search will happily return long, circuitous paths. On certain families of graphs with carefully chosen capacities, you can get into a “thrashing” pattern where you repeatedly augment by very small amounts along nearly the same path. If the capacities are arbitrary rationals, that behaviour can force an exponential number of augmentations before the residual graph disconnects (s) from (t). Even with integer capacities, the naïve bound on the number of augmentations is (\text{value of the max flow}), which is only pseudo‑polynomial. Edmonds–Karp’s choice of shortest paths rules out this pathological behaviour and yields a bound that depends only on (V) and (E).