edmonds_karp(G, c, s, t) Input: A flow network. Output: A max flow on the network.1. Set f(e) = 0 for all e in E.2. Build the residual network G^f for the current flow f.3. Check for any s-t paths p in G^f using BFS. 1. If no such path then output f.4. Given p let c(p) = min_{e in p} c^f(e).5. Augment f by c(p) units along p. 1. f(e) = f(e) + c(p) for forward edges. 2. f(e) = f(e) - c(p) for backward edges.6. Repeat from step 2.
To run each iteration we need need to update the path length number of edges in the graph which takes time. We need to run BFS which takes if we assume is connected. Then calculating and updating the weights also takes time. So all together a single iteration takes time.
Therefore together this takes times.
Proof of claims
A bit of notation will help us understand what is going.
Suppose we have flows during the course of the algorithm - with being the empty flow and being the returned flow.
Let be the augmenting path in to make for .
Let be the edge distance from to as produced by our run of the DFS to produce path .
Claim 1
Claim 1
The algorithm has at most loops. i.e. .
Proof
Note that as we let in each round of the algorithm we remove at least one edge of to make . (This isn’t to say the number of edges reduces each round - as we may add in more edges to than we have deleted.)
From Claim 2 we know each edge gets deleted and reinserted to at most times.
Therefore we can only iterate times. As there has to be an edge to remove.
Claim 2
Claim 2
For every edge , is deleted and reinserted to at most times.
Proof
Let then from Claim 3 every time we remove and add the distance between and increases by 2. As the distance between and can be at most . This can only happen less than times.
Claim 3
Claim 3
Suppose edge is removed from and added back to . Then .
Proof
As we delete from from Claim 5 therefore
From Claim 4 we have that
As we add to from Claim 5 therefore
Combining this all together we have