{"id":172,"date":"2026-11-13T12:33:30","date_gmt":"2026-11-13T04:33:30","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-edmonds-karp-bounds-augmentations-with-bfs\/"},"modified":"2026-11-13T21:51:47","modified_gmt":"2026-11-13T13:51:47","slug":"how-edmonds-karp-bounds-augmentations-with-bfs","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-edmonds-karp-bounds-augmentations-with-bfs\/","title":{"rendered":"How Edmonds-Karp bounds augmentations with BFS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Edmonds-Karp<\/strong> is Ford-Fulkerson with one restriction: the augmenting path is a <strong>shortest<\/strong> residual path, measured by number of edges, so the search is breadth-first. Each augmentation can be found in <strong>O(E)<\/strong>, and the number of augmentations is <strong>O(VE)<\/strong>, for a total of <strong>O(VE\u00b2)<\/strong>. The bound is polynomial in the size of the graph and does not depend on the magnitude of the capacities.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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\u00b2). Extra memory is the residual graph and the BFS arrays. The minimum cut is still the residual source side at termination.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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\u00b2).<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Build residual capacities as in Ford-Fulkerson, both directions.<\/li>\n<li>Breadth-first search in the residual graph from the source, using only edges of positive residual capacity. Stop when the sink is reached.<\/li>\n<li>If the sink is unreachable, stop. The flow is maximum.<\/li>\n<li>Walk parent pointers from the sink to the source, take the bottleneck residual, and update forward and backward residuals by that amount.<\/li>\n<li>Repeat the search. Do not reuse an old BFS layer after an augmentation. The residual graph has changed.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the augmenting path is not a shortest path<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Depth-first search for the path<\/td>\n<td>The flow is still correct if it terminates, and the O(VE) augmentation cap does not apply. Large capacities can force a long run.<\/td>\n<\/tr>\n<tr>\n<td>Reuse distances from the previous search<\/td>\n<td>An augmentation deletes at least one residual edge on the path and may add backward edges. The next shortest path is a new search.<\/td>\n<\/tr>\n<tr>\n<td>Weight the BFS by capacity<\/td>\n<td>Shortest means fewest edges. A fattest path is a different heuristic and does not inherit this proof.<\/td>\n<\/tr>\n<tr>\n<td>Quote O(VE\u00b2) for a graph stored as a matrix with an O(V\u00b2) scan per BFS<\/td>\n<td>The O(E) search assumes an adjacency list. A matrix search replaces E with V\u00b2 inside the same proof shape.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment augments along a shortest residual path, found by breadth-first search. Capacities: 0\u21921 is 3, 0\u21922 is 2, 1\u21923 is 2, 2\u21923 is 3, 1\u21922 is 1. The maximum flow is <code>5<\/code>.<\/p>\n\n<pre><code class=\"language-python\">from collections import deque\ncap = {(0, 1): 3, (0, 2): 2, (1, 3): 2, (2, 3): 3, (1, 2): 1}\nresidual = {k: v for k, v in cap.items()}\n\ndef add_res(u, v, d):\n    residual[(u, v)] = residual.get((u, v), 0) + d\n\ndef bfs():\n    parent = {0: None}\n    q = deque([0])\n    while q:\n        u = q.popleft()\n        for (a, b), c in residual.items():\n            if a == u and c &gt; 0 and b not in parent:\n                parent[b] = u\n                if b == 3:\n                    return parent\n                q.append(b)\n    return None\n\nflow = 0\nwhile (parent := bfs()):\n    v, add = 3, 10**9\n    while v != 0:\n        u = parent[v]\n        add = min(add, residual[(u, v)])\n        v = u\n    v = 3\n    while v != 0:\n        u = parent[v]\n        residual[(u, v)] -= add\n        add_res(v, u, add)\n        v = u\n    flow += add\nassert flow == 5\nprint(flow)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Edmonds-Karp is maximum flow with breadth-first augmentations, which is the version a library ships when it wants Ford-Fulkerson&#8217;s correctness and a polynomial bound. Dinic&#8217;s algorithm blocks a whole level graph per phase and is usually faster. The flow value is the same.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for Edmonds-Karp returns the breadth-first residual path and the O(VE\u00b2) bound that arbitrary paths do not have. <strong>Edmonds-Karp computes a maximum flow in O(VE\u00b2) time by always augmenting a residual path of fewest edges.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00b2). The bound is polynomial&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/172\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}