Questions in black, solutions in blue.

Our analysis of max flows and min cuts last week leads to an algorithm
(called the *Ford-Fulkerson method*) for finding max flows in a flow
diagram. The *residual graph* for a flow is the flow diagram that labels
each edge with the capacity in each direction, if any, not used by the flow.
For example, if an edge can take from 0 to 6 units in one direction and 4 are
currently going across it, the residual graph shows 2 units in the forward
direction and 4 in the backward direction.

An *augmenting path* is a path of non-zero edges in the residual graph.
If there is an augmenting path, we can increase the flow along it by an amount
equal to its lowest-labeled edge. (If there is no augmenting path, then there
is a cut equal to the flow capacity and the flow is maximum.) The
Ford-Fulkerson method is to keep finding an augmenting path and increasing
the flow as long as you can. It always works on integer flows, but not always
quickly:

```
1000 1000
------>(2)------
/ ^ \
/ | \
/ | v
>(1) 1| ((4))
\ | ^
\ | /
\ 1000 | 1000 /
------>(3)------
```

**Question 1:**Consider the flow diagram above. Explain how starting from a zero flow, we can find 2000 augmenting paths in succession, of capacity 1 each, before finding the optimal flow of 2000 from vertex 1 to vertex 4.The first residual graph is identical to the original diagram above, because it is the residual for a zero flow. The first augmenting path goes from 1 to 3 to 2 to 4, and has size 1 because there is capacity 1 in the residual graph from 3 to 2.

The second residual graph has capacity 1000 from 1 to 2, 999 from 1 to 3, 1 from 2 to 3 (because the current flow of 1 from 3 to 2 could be

*decreased*by 1), 999 from 2 to 4, and 1000 from 3 to 4. The second augmenting path has size 1 and goes from 1 to 2 to 3 to 4.(Note: Actually the first residual graph has edges with capacity 1 from 3 to 1 and from 4 to 2 as well as the edges I named. Below, whenever I say the residual from 1 to 2, for example, is x, remember that there is also an edge in the residual graph from 2 to 1 with capacity 1000-x.)

The new flow has 1 unit going from 1 to 2 to 4 and 1 unit going from 1 to 3 to 4. The new residual graph looks like the diagram above except that the four 1000 edges now have residual capacity 999 each. Our third augmenting path is exactly like the first, and the fourth is exactly like the second, leading to a flow of 2 over each of the four outer edges and a residual graph with 998 on each outer edge and still 1 from 2 to 3. We choose 998 more pairs of augmenting paths, with the first in each pair going from 1 to 3 to 2 to 4 and the second in each pair going from 1 to 2 to 3 to 4. After all 2000 paths we have a total flow of 2000, with 1000 units going from 1 to 2 to 4 and 1000 going from 1 to 3 to 4. The final residual graph has an edge on size 1 from 3 to 2, and backward edges of size 1000 from 2 to 1, from 3 to 1, from 4 to 2, and from 4 to 3. Since in this graph there is no path from 1 to 4, we have achieved the maximum flow, though in a very time-consuming way.

**Question 2:**The*Edmonds-Karp algorithm*is to employ Ford-Fulkerson but always use an augmenting path that contains as few edges as possible. How do you find such a path, and how long does it take?Use breadth-first search on the residual graph, ignoring the weights. This will take O(e+n) = O(e) time and will find a path from the source to the sink, if any such path exists, using as few edges as possible.

**Question 3:**An augmenting path*fills an edge*if after the flow is increased by the path, the edge is at its capacity. In [CLRS] they prove that using Edmonds-Karp, no edge can be filled more than n times before the flow is maximum (n is the number of vertices and e the number of edges). Using this fact and the answer to Question 2, find a big-O bound on the running time of Edmonds-Karp.If each of the e edges is filled at most n times and each iteration of Edmonds-Karp fills at least one edge, then there can be at most ne iterations. Since each iteration takes O(e) time, we have a total time of O(ne

^{2}) for the algorithm.**Question 4:**The*maximum matching problem*is to input a*bipartite*graph and find a subset of the edges such that (a) no two edges share a vertex, and (b) the subset is as large as possible. Explain how to reduce the maximum matching problem to the max-flow problem.Our flow diagram will have one vertex for each vertex of the bipartite graph plus two more vertices, the source s and the sink t. Let L and R be the two components of the bipartite graph, or more precisely any two disjoint sets that union to the vertices of the bipartite graph such that any edge goes between a vertex in L and one in R. Make an edge of size 1 from s to each vertex in L. Make a directed edge from the L-vertex to the R-vertex for each edge of the bipartite graph, also of weight 1. Make an edge of size 1 from each vertex of R to t.

Now any flow in this diagram corresponds to a matching in the bipartite graph, and the size of the flow is exactly the number of edges in the matching. (It is clear from the operation of the Ford-Fulkerson method that the eventual maximal flow will have an integer number of units passing over each edge, so each edge of the bipartite graph is either fully used or not used.) The maximum flow thus gives us a maximum matching.

Last modified 1 December 2003