How Edmonds-Karp bounds augmentations with BFS

Short answer: Edmonds-Karp is Ford-Fulkerson with one restriction: the augmenting path is a shortest residual path, measured by number of edges, so the search is breadth-first. Each augmentation can be found in O(E), and the number of augmentations is O(VE), for a total of O(VE²). The bound is polynomial in the size of the graph and does not depend on the magnitude of the capacities.


What the problem actually asks

Arbitrary augmentations can send a trickle along a long path, cancel it, and repeat. Shortest residual paths cannot do that for long. The breadth-first distance from the source in the residual graph never decreases for any vertex, except in a careful sense at the moments that matter, and the distance of the sink strictly increases every O(E) augmentations. Those two monotonicities cap the number of paths.

The residual update itself is unchanged. Only the choice of path changes. Implementation is a BFS that stops at the sink, followed by the same bottleneck update along the parent pointers.


What the algorithm guarantees

On any real capacities for which the arithmetic is exact, and in particular on integers, the algorithm terminates with a maximum flow after O(VE) augmentations. Time is O(VE²). Extra memory is the residual graph and the BFS arrays. The minimum cut is still the residual source side at termination.

The shortest-path rule counts edges, not residual capacities and not original costs. A cheapest path under a cost function is min-cost flow, a different problem. Unit capacities admit a faster bound by Dinic or by a specialized matching algorithm. Edmonds-Karp does not need those restrictions to hit O(VE²).


The working steps

  1. Build residual capacities as in Ford-Fulkerson, both directions.
  2. Breadth-first search in the residual graph from the source, using only edges of positive residual capacity. Stop when the sink is reached.
  3. If the sink is unreachable, stop. The flow is maximum.
  4. Walk parent pointers from the sink to the source, take the bottleneck residual, and update forward and backward residuals by that amount.
  5. Repeat the search. Do not reuse an old BFS layer after an augmentation. The residual graph has changed.

The polynomial bound comes from the breadth-first restriction. Replacing the BFS with a depth-first search returns to bare Ford-Fulkerson and can reintroduce the long sequence of tiny augmentations. Dinic keeps the level idea and pushes a whole blocking flow before the next BFS, which is asymptotically faster.


Approaches that look simpler and fail

Approach Why it fails when the augmenting path is not a shortest path
Depth-first search for the path The flow is still correct if it terminates, and the O(VE) augmentation cap does not apply. Large capacities can force a long run.
Reuse distances from the previous search An augmentation deletes at least one residual edge on the path and may add backward edges. The next shortest path is a new search.
Weight the BFS by capacity Shortest means fewest edges. A fattest path is a different heuristic and does not inherit this proof.
Quote O(VE²) for a graph stored as a matrix with an O(V²) scan per BFS The O(E) search assumes an adjacency list. A matrix search replaces E with V² inside the same proof shape.

A blocking flow on a level graph is Dinic, which is the usual next step when Edmonds-Karp is correct and still too slow. A preflow algorithm with no path search is push-relabel.


A working example

This Python fragment augments along a shortest residual path, found by breadth-first search. Capacities: 0→1 is 3, 0→2 is 2, 1→3 is 2, 2→3 is 3, 1→2 is 1. The maximum flow is 5.

from collections import deque
cap = {(0, 1): 3, (0, 2): 2, (1, 3): 2, (2, 3): 3, (1, 2): 1}
residual = {k: v for k, v in cap.items()}

def add_res(u, v, d):
    residual[(u, v)] = residual.get((u, v), 0) + d

def bfs():
    parent = {0: None}
    q = deque([0])
    while q:
        u = q.popleft()
        for (a, b), c in residual.items():
            if a == u and c > 0 and b not in parent:
                parent[b] = u
                if b == 3:
                    return parent
                q.append(b)
    return None

flow = 0
while (parent := bfs()):
    v, add = 3, 10**9
    while v != 0:
        u = parent[v]
        add = min(add, residual[(u, v)])
        v = u
    v = 3
    while v != 0:
        u = parent[v]
        residual[(u, v)] -= add
        add_res(v, u, add)
        v = u
    flow += add
assert flow == 5
print(flow)

Where it is used

Edmonds-Karp is maximum flow with breadth-first augmentations, which is the version a library ships when it wants Ford-Fulkerson’s correctness and a polynomial bound. Dinic’s algorithm blocks a whole level graph per phase and is usually faster. The flow value is the same.


When you can drop this algorithm

Drop Edmonds-Karp for large sparse instances where Dinic or push-relabel is available and tested. Keep it when a maximum flow must be polynomial, simple to prove, and implemented as BFS plus the residual update.


Why this stays published

We publish this so a search for Edmonds-Karp returns the breadth-first residual path and the O(VE²) bound that arbitrary paths do not have. Edmonds-Karp computes a maximum flow in O(VE²) time by always augmenting a residual path of fewest edges.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *