In [[computer science]] and [[graph theory]], the '''Edmonds-Karp algorithm''' is an implementation of the [[Ford-Fulkerson algorithm|Ford-Fulkerson method]] for computing the [[maximum flow problem|maximum flow]] in a [[flow network]]. The distinguishing feature is that the shortest augmenting path is used at each step, which guarantees that the computation will terminate. In most implementations, the shortest augmenting path is found using a [[breadth-first search]], which gives a running time ofin <math>O(VE^2)</math>. It is asymptotically slower than the [[relabel-to-front algorithm]], which runs in <math>O(V^3)</math>, but it is often faster in practice for [[sparse graph]]s. The algorithm was first published by a Russian scientist, Dinic, in 1970{{ref|Din70}}, and later, independently, by [[Jack Edmonds]] and [[Richard Karp]] who published it in 1972{{ref|EK72}}. Dinic's algorithm includes additional techniques that reduce the running time to <math>O(V^2E2 E)</math>.
==Algorithm==
The algorithm is identical to the [[Ford-Fulkerson algorithm]], except that the search order when finding the augmenting path is defined. The path found must be the shortest path which has available capacity. This can be found by a [[breadth-first search]], as we let edges have unit length. The running time of <math>O(V^2 E)</math> is found by showing that the length of the augmenting path found never decreases, that for every time one of the <math>E</math> edge becomes saturated the augmenting path must be longer than last time it was saturated, that a path is at most <math>V</math> long, and can be found in <math>O(E)</math> time. There is an accessible proof in {{ref|CLRS01}}.
<!--
This argument is so incomplete and hard to understand that we better leave it out until somebody write a new one. The one in Introduction to algorithms is nice.
==Complexity==
Given that the augmenting path is found with a [[breadth-first search]], the running time of the Edmonds-Karp algorithm is <math>O(VE^2)</math>. This can be seen from the following argument:
[[Image:ek-flow_comp1.png|right]]
The length of the augmenting paths found never decreases. For a new path to open, flow must have been sent in the opposite direction along at least one of its edges. Assume that flow was sent along the path <math>s \dots w u v x \dots t</math> (green), such that there opened a path <math>s \dots y v u z \dots t</math> (blue) which was shorter, and that only one edge on this path was closed previously. Since we always choose the shortest path, we know that <math>|s \dots w u v| \leq |s \dots y v|</math>, which means that <math>|s \dots w u| \leq |s \dots y v| - 1</math>, as the length of <math>uv</math> is 1. Likewise we know that <math>|u v x \dots t| \leq |u z \dots t|</math>, which means that <math>|v x \dots t| \leq |u z \dots t| - 1</math>. From this we conclude that <math>|s \dots w u v x \dots t| \leq |s \dots y v u z \dots t| - 2</math>, which contradicts the assumption that the second path was shorter. The argument can be extended to cases where multiple edges in the second path are opened when flow is sent on the first.
The number of times each edge is saturated is <math>O(V)</math>. We know that if <math>uv</math> is saturated when sending flow along a path, flow must be sent in the opposite direction, on <math>vu</math> on a second path, before flow can be sent on <math>uv</math> again, on a third path. The first path must be shorter than the second, which again must be shorter than the third. For each edge, the series of augmenting paths which saturated it have strictly increasing length. Since paths do not have cycles, their length is <math>O(V)</math>. Hence the number of saturating sends on an edge is <math>O(V)</math>.
Each time a path is found, at least one of the <math>E</math> edges is saturated. Since each edge is saturated <math>O(V)</math> times, the maximum flow is found in <math>O(VE)</math> rounds. As the cost of a breadth-first-search is <math>O(V+E)</math>, the total running time is <math>O(VE^2)</math> (if <math>E<V</math> we can remove the unused nodes in O(V) first).
-->
==Sample implementation==
==References==
* {{Note|Din70}}{{cite journal
* E. A. Dinic, Algorithm for solution of a problem of maximum flow in a network with power estimation, ''Soviet Math. Doklady'', Vol 11 (1970) pp1277-1280. ▼
| last = E. A. Dinic
* J. Edmonds and R. M. Karp, Theoretical improvements in algorithmic efficiency for network flow problems, ''Journal of the [[Association for Computing Machinery|ACM]]'', Vol 19, No. 2 (1972) pp248-264. [http://delivery.acm.org/10.1145/330000/321699/p248-edmonds.pdf PDF (needs subscription)]
▲* E. A.| Dinic,title = Algorithm for solution of a problem of maximum flow in a network with power estimation , ''Soviet Math. Doklady'', Vol 11 (1970) pp1277-1280.
| journal = Soviet Math. Doklady
| volume = Vol 11
| issue =
| pages = 1277-1280
| publisher = Doklady
| date = 1970
| url =
| doi =
| id =
| accessdate = }}
* {{Note|EK72}}{{cite journal
| author = [[Jack Edmonds]] and [[Richard Karp|Richard M. Karp]]
| title = Theoretical improvements in algorithmic efficiency for network flow problems
| journal = Journal of the [[Association for Computing Machinery|ACM]]
| volume = 19
| issue = 2
| pages = 248-264
| publisher =
| date = 1972
| url = http://www.akira.ruc.dk/~keld/teaching/algoritmedesign_f03/Artikler/08/Edmonds72.pdf
| doi =
| id =
| accessdate = }}
* {{Note|CLRS01}}{{cite book
| author = [[Thomas H. Cormen]] and [[Charles E. Leiserson]] and [[Ronald L. Rivest]] and [[Clifford Stein]]
| title = [[Introduction to Algorithms]]
| publisher = MIT Press and McGraw-Hill
| DATE = 2001
| id = ISBN 0262531968
| edition = second edition
}}
[[Category:Network flow]]
|