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

This is an old lecture that I include now as supplemental material. In this lecture, I give an example of calculating network flow with three different path-finding algorithms. At the end, I show how to find the minimum cut.

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->D->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->F*. 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. They each have an expensive
component -- in greedy DFS, processing the residual graph is
*O(|V|log|V|)*rather than*O(|V|)*. In the modified Dijkstra, finding the augmenting path is*O(|E|log|V|)*rather than*O(|E|)*. - Edmonds-Karp attempts to find a small number of paths, but its path-finding algorithm
is fast --
*O(|E|)*-- as is its residual processing algorithm, which is*O(|V|)*.

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.