- April 2, 2008. Latest revision, November, 2012.
- James S. Plank
- Directory:
**/home/plank/cs302/Notes/Netflow1**

There is more material in the following Wikipedia pages. As with a lot of Wikipedia, the presentation is too dry and mathematical, so I don't require that you read it, but I provide links to it anyway:

- Wikipedia's page on network flow
- Wikipedia's page on maximum flow
- Wikipedia's page on the Ford-Fulkerson algorithm
- Wikipedia's page on the Edmonds-Karp algorithm

It's pretty easy to eyeball this graph and see that it has a maximum flow of 1000.
The two paths are *S->A->T* and *S->B->T*. However, if you try to determine
the maximum flow using augmenting paths, and you choose the wrong path at each step,
it will take 1000 iterations of the algorithm. To illustrate, suppose that the first
path you choose is *S->A->B->T* with a flow of one. When you process this path
through the residual graph, you end up with the following:

At the next iteration, suppose you choose the path *S->B->A->T*, again with a
flow of one. The residual looks as follows:

You continue in that vein. The pictures below show how you choose *S->A->B->T* again,
and then *S->B->A->T*, again:

Each time, you add one unit of flow, which means that this will take 1000 iterations. Although this example is unlikely to happen in practice, it demonstrates a need for a smart determination of paths. Below, we will present three determinations. In the third set of lecture notes, we will evaluate these experimentally on a set of graphs.

When we perform a greedy DFS on this graph, we start with edge from *A* to *B*
since its flow is greater than the edge from *A* to *D*. There is only one
edge leaving *B*. When we read node *C*, we traverse the edge to *E*, since
it has the maximum flow of *C's* three edges. Finally, *E* goes to *G*.
Thus, the first path we get is *A->B->C->E->G*
with a flow of one.

Below, I show the flow and residual graphs when this path is processed. In the residual, the edges whose flow is reduced are colored red, and the reverse edges are colored green:

Flow | Residual |

The next greedy path through the residual is *A->B->C->D->F->G*, with a flow of two:

Flow | Residual |

The last path is *A->D->F->G* with a flow of three. Here are the final flow and
residual graphs:

Flow | Residual |

The modification works as follows. When processing a node, again the algorithm traverses the node's edges, and if paths with more flow to any other nodes are discovered, then the nodes are updated. At each step, the node with the maximum flow is processed next.

We'll work an example with the same graph as above:

The maximum flow path here is *A->D->F->G* with a flow of three:

Flow | Residual |

The next maximum flow path is *A->B->C->D->F->G* with a flow of 2:

Flow | Residual |

The final path is *A->B->C->E->G* with a flow of one:

Flow | Residual |

Again, we use the same graph as an example:

There are two minimum hop paths: *A->D->E->G* and *A->D->F->G*. Suppose
we process the former of these, with a flow of one:

Flow | Residual |

Now, there is only one minimum hop path through the residual: *A->D->F->G*, with a flow
of two:

Flow | Residual |

At this point, there are only two paths through the residual: *A->B->C->D->F->G* and
*A->B->C->E->D->F->G*. The first of these has fewer hops, so we process it.
It has a flow of two:

Flow | Residual |

The final path through the residual is *A->B->C->E->D->F->G* with a flow of one. When
we process it, we get the same flow and residual graphs as the other two algorithms:

Flow | Residual |

- The greedy DFS and modified Dijkstra algorithms attempt to minimize the number of
paths that you find by finding paths with a lot of flow. The path-finding algorithms
themselves are more expensive, on the order of
*O(|E|log|V|)*. - Edmonds-Karp attempts to find a small number of paths, but its path-finding algorithm
is fast:
*O(|E|)*.

One thing that you should remember about network flow is that it is quite a bit slower than all of the other graph algorithms we've studied so far.

Now, in the original graph, we divide our nodes into two sets: the set determined above, and all of the remaining nodes. They are drawn purple and yellow in the original graph below:

The minimum cut is composed of all the edges that go from the source set to the sink set. These are edges AD, CD and EG, which I've drawn in red above. The sum of their capacities equals the maximum flow of six.