Teaching / Algorithm Design / Network Flow I

Interactive lesson · Chapter 7 · Network Flow

Network Flow I: maximum flow and minimum cut

How much can we ship from a source s to a sink t through a network with limited capacities? Run the algorithms step by step, play the algorithm yourself, and see why the biggest flow always equals the smallest cut.

For Algorithm Design (FTU, undergraduate). This page goes with the lecture slides 07 Network Flow I by Kevin Wayne, which follow Kleinberg and Tardos, Algorithm Design. The animations are my own; slide numbers are given so you can switch between the two.

Sections: 1 What is a flow? · 2 Algorithm lab · 3 You be the algorithm · 4 Cuts and max-flow = min-cut · 5 Cheat-sheet

1 · The problem (slides 3–10)

What is a flow?

A flow network is a directed graph with a capacity c(e) on every edge, a source s and a sink t. An s–t flow gives every edge a number f(e) such that (1) capacity: 0 ≤ f(e) ≤ c(e), and (2) conservation: at every node other than s and t, flow in = flow out. Its value is the flow leaving s. The pipe on each edge fills up in proportion to f(e)/c(e).

Click an edge to add 1 unit · right-click or Shift+click to remove 1

Flow network edge label = flow / capacity

flow in the pipesaturated edge (f = c)

2 · The algorithms (slides 12–72)

Algorithm lab

Pick a network and an algorithm, then step through it. The left view shows the flow f; the right view shows the residual network Gf, which is where every algorithm looks for its next move. A backward arc (dashed) lets an algorithm undo flow it pushed earlier. Use the buttons, the slider, or the arrow keys. You can drag the nodes.

Flow network G drag nodes to rearrange

Residual network Gf label = residual capacity

saturated edgecurrent pathresidual arc, forward: c − f backward arc: can undo fminimum cut

Augmentations so far click a row to jump there

Which algorithm is fastest on this network?

All six always find the same maximum value. What differs is how many augmentations they need. Change the network above (try the exponential trap) and watch this table.

3 · Hands on

You be the algorithm

Now you choose the augmenting paths. Click nodes in either view to build an s→t path in the residual network, one node at a time (click a node already on your path to cut it back). When you reach t, press Augment. Backward arcs are allowed. Keep going until no path exists: then you have a maximum flow. Can you finish in fewer augmentations than the algorithms?

Flow network G

Residual network Gf click nodes to build a path

4 · Why the algorithm stops (slides 4–6, 25–36)

Cuts and the max-flow min-cut theorem

An s–t cut (A, B) splits the nodes into a set A containing s and a set B containing t. Its capacity is the total capacity of edges going from A to B. Every flow must squeeze through every cut, so flow value ≤ capacity of any cut. The surprise: some cut is exactly as small as the best flow. Click nodes to move them between A and B, and slide the flow from nothing up to maximum.

Network with flow shaded = A · red = edges from A to B

All cuts of this network, smallest to largest

5 · Summary (slides 73–74)

Cheat-sheet

AlgorithmKey ideaAugmentationsRunning time
Ford–Fulkerson (arbitrary path)Augment along any s→t path in Gf≤ val(f*) ≤ nCO(mnC)
Fattest pathPath with the largest bottleneckO(m log(mC))O(m² log n log(mC))
Capacity scalingOnly use arcs with residual ≥ Δ; halve ΔO(m log C)O(m² log C)
Shortest augmenting pathBFS: fewest edges≤ mnO(m²n)
DinitzLevel graph + blocking flow in phases≤ mnO(mn²)

m = edges, n = nodes, C = largest capacity (integers). Ford–Fulkerson with arbitrary paths is not polynomial in the input size (slide 39); the other four are.

Questions to explore

  1. Greedy vs. residual. Run Greedy on the “Greedy trap”. Where does it get stuck? Then run Ford–Fulkerson and find the backward arc it uses.
  2. 2C augmentations. On the exponential trap choose worst-case path and raise C. Then choose shortest path. What changes, and why does the input size not change much?
  3. Δ. In capacity scaling, why does the last phase (Δ = 1) always find the maximum?
  4. Levels. In Dinitz on “Growing path lengths”, how does the distance to t change from phase to phase? Why can it never decrease?
  5. Min cut. After a maximum flow, which nodes can still be reached from s in Gf? Why are all edges leaving that set saturated?