Chapter 8: Network Flow

Chapter 8: Network Flow · Study Questions
Flow networkResidual networkCutsFord-FulkersonEdmonds-KarpDinicPush–relabelApplications
Sercan KÜLCÜ · Giresun University · Computer Engineering

Multiple Choice · Flow Networks

Question 1: Flow Conservation

The edges entering and leaving the intermediate vertex v are labeled flow/capacity. For the flow to be valid, what must f be on the edge v → w?

xyvzw3/45/52/6f/7

B: Conservation: in = 3 + 5 = 8, out = 2 + f → f = 6 ≤ 7, so the capacity constraint holds too. C writes down the sum of the inflows; A assumes the edge is saturated. At every vertex except the source and the sink, the flow in equals the flow out.

Output Question · Flow Networks

Question 2: Value of a Flow

Labels are flow/capacity; the edge b → s returns to the source. (a) Is the flow valid (capacity and conservation)? (b) What is |f|? (c) Which edges are saturated?

sabt4/63/31/22/42/54/4
Show answer

(a) Capacity: every f ≤ c. Conservation: into a 4, out of a 2 + 2 = 4 ✓; into b 3 + 2 = 5, out of b 1 + 4 = 5 ✓.Valid.

(b) |f| = flow out of s − flow into s = (4 + 3) − 1 = 6; this equals the flow into t, 2 + 4 = 6. Summing only the outflows (7) is wrong.

(c) s → b (3/3) and b → t (4/4) are saturated; no more flow can be sent through them.

Multiple Choice · Residual Network

Question 3: Residual Capacity

Edge u → v has capacity 7 and carries 3 units of flow (no opposite edge). Which edges does it create in the residual network, and with what capacities?

A: The forward edge has residual capacity c − f = 7 − 3 = 4; the reverse edge has c_f(v, u) = f = 3, the part of the flow that can be undone. C forgets the reverse edge; without it the algorithm cannot fix its first wrong choice. D mixes the two up.

Output Question · Residual Network

Question 4: Building the Residual Network

The flow network is given in flow/capacity form. (a) What is |f|? (b) Draw the residual network. (c) Is there an augmenting path from s to t in the residual network?

sabt3/42/51/22/23/6
Show answer

(a) |f| = flow out of s = 3 + 2 = 5 (into t: 2 + 3 = 5).

sabt133211233

(b) Forward edges c − f (s → a 1, s → b 3, a → b 1, b → t 3), reverse edges (dashed) f. a → t is saturated: only its reverse edge (t → a, 2) remains.

(c) Yes: s → b → t, bottleneck min(3, 3) = 3. The flow becomes 8; the capacity out of the source is 4 + 5 = 9 and into the sink 2 + 6 = 8, so 8 is the maximum.

Multiple Choice · Cuts

Question 5: Cut Capacity

The green vertices form the side S = {s, 2}, the blue vertices the side T = {1, 3, 4, t}. What is the capacity of the cut (S, T)?

s1234t81235610798

A: Only edges going from S to T count: s → 1 (8) + 2 → 4 (10) = 18. The edge 1 → 2 (3) goes from T to S and is not added to the capacity; if it were, B (21) would result. Since |f| ≤ c(S, T) for every flow, the maximum flow in this network cannot exceed 18.

Output Question · Cuts

Question 6: All Cuts

The edge labels are capacities. List all s–t cuts and their capacities. Which is the minimum cut, and what is the maximum flow?

sabt54236
Show answer
S sideS → T edgesc(S, T)
{s}s→a 5, s→b 49
{s, a}s→b 4, a→b 2, a→t 39
{s, b}s→a 5, b→t 611
{s, a, b}a→t 3, b→t 69

All three cuts have capacity 9 and are minimum (a minimum cut need not be unique). By the max-flow min-cut theorem the maximum flow is 9: for example s → a → t 3, s → a → b → t 2, s → b → t 4.

Step-by-Step Trace · Ford-Fulkerson

Question 7: Tracing Ford-Fulkerson (DFS)

dfs descends into the first neighbor with positive residual capacity. Which augmenting paths are found, and what is the maximum flow?

s1234t0/80/120/30/50/60/100/70/90/8

Capacities are on the edges; initially all flows are 0 and the residual network equals the original network. Neighbors are tried in increasing index order (s = 0, t = 5).

s1234t3/80/123/30/50/63/103/73/90/8

Path s → 1 → 2 → 4 → 3 → t, bottleneck min(8, 3, 10, 7, 9) = 3. |f| = 3.

s1234t6/80/123/33/50/63/100/73/93/8

Path s → 1 → 3 → 4 → t, bottleneck min(5, 5, 3, 8) = 3. The edge 3 → 4 is a reverse edge: the flow on 4 → 3 drops by 3 (canceled). |f| = 6.

s1234t8/80/123/35/50/63/100/75/93/8

Path s → 1 → 3 → t, bottleneck min(2, 2, 6) = 2. |f| = 8.

s1234t8/83/120/35/53/63/103/78/93/8

Path s → 2 → 1 → 4 → 3 → t, bottleneck min(12, 3, 6, 7, 4) = 3. The edge 2 → 1 is a reverse edge: the flow on 1 → 2 drops by 3 (canceled). |f| = 11.

s1234t8/84/120/35/53/64/104/79/93/8

Path s → 2 → 4 → 3 → t, bottleneck min(9, 7, 4, 1) = 1. |f| = 12.

s1234t8/89/120/35/53/69/104/79/98/8

Path s → 2 → 4 → t, bottleneck min(8, 6, 5) = 5. |f| = 17.

s1234t8/89/120/35/53/69/104/79/98/8

DFS cannot reach t: 3 → t and 4 → t are saturated. return 17; Ford-Fulkerson with DFS used 6 augmenting paths.

int fordFulkerson(int s, int t) {
  int maxFlow = 0;
  int[] parent = new int[V];
  while (dfs(s, t, new boolean[V], parent)) {
    int flow = Integer.MAX_VALUE;
    for (int v = t; v != s; v = parent[v])
      flow = Math.min(flow, res[parent[v]][v]);
    for (int v = t; v != s; v = parent[v]) {
      res[parent[v]][v] -= flow;   // forward
      res[v][parent[v]] += flow;   // reverse
    }
    maxFlow += flow;
  }
  return maxFlow;
}

Multiple Choice · Ford-Fulkerson

Question 8: Bad Path Choice

Edges s → a, s → b, a → t, b → t have capacity 10⁶; the middle edge a → b has capacity 1. How many augmentations does Ford-Fulkerson with DFS make if it always uses the middle edge (or its reverse)? And Edmonds-Karp?

D: The maximum flow is 2 · 10⁶, and every path through the middle (s → a → b → t or s → b → a → t) adds only 1 unit: 2 · 10⁶ augmentations. Edmonds-Karp picks the 2-edge paths s → a → t and s → b → t: 2 augmentations. The time O(E · |f*|) depends on the number's magnitude; it is not polynomial.

Output Question · Ford-Fulkerson

Question 9: Without Reverse Edges

All capacities are 1. The first augmenting path chosen is s → a → b → t. (a) If the search continues with forward edges only (no reverse edges), what is the total flow? (b) What happens in the residual network with reverse edges?

sabt11111
Show answer

(a) s → a, a → b and b → t become saturated. The remaining forward edges are s → b and a → t; you can go from s to b, but b's outgoing edge is full. It gets stuck: the flow is 1.

(b) The residual network has the reverse edge b → a (1): s → b → a → t is found as an augmenting path, and the flow on a → b is canceled. Result: s → a → t and s → b → t, flow 2 = min cut ({s}: 1 + 1).

A reverse edge does not mean "sending flow backward" but undoing flow that was sent earlier; it corrects the first wrong choice.

Step-by-Step Trace · Edmonds-Karp

Question 10: Tracing Edmonds-Karp

edmondsKarp(0, 5) finds which augmenting paths in this network? How many augmentations are needed?

s1234t0/80/120/30/50/60/100/70/90/8

Capacities are on the edges; initially all flows are 0 and the residual network equals the original network. Neighbors are tried in increasing index order (s = 0, t = 5).

s1234t0/80/120/30/50/60/100/70/90/8

BFS found a fewest-edge path: s → 1 → 3 → t (3 edges). Bottleneck min(8, 5, 9) = 5.

s1234t5/80/120/35/50/60/100/75/90/8

|f| = 5.

s1234t5/80/120/35/50/60/100/75/90/8

BFS found a fewest-edge path: s → 1 → 4 → t (3 edges). Bottleneck min(3, 6, 8) = 3.

s1234t8/80/120/35/53/60/100/75/93/8

|f| = 8.

s1234t8/80/120/35/53/60/100/75/93/8

BFS found a fewest-edge path: s → 2 → 4 → t (3 edges). Bottleneck min(12, 10, 5) = 5.

s1234t8/85/120/35/53/65/100/75/98/8

|f| = 13.

s1234t8/85/120/35/53/65/100/75/98/8

BFS found a fewest-edge path: s → 2 → 4 → 3 → t (4 edges). Bottleneck min(7, 5, 7, 4) = 4.

s1234t8/89/120/35/53/69/104/79/98/8

|f| = 17.

s1234t8/89/120/35/53/69/104/79/98/8

BFS cannot reach t; the vertices reachable from s (yellow) are {s, 1, 2, 3, 4}. Cut capacity 3 → t 9 + 4 → t 8 = 17 = |f*|. return 17; 4 augmentations (the DFS version made 6).

int edmondsKarp(int s, int t) {
  int maxFlow = 0;
  int[] parent = new int[V];
  while (bfs(s, t, parent)) {
    int flow = Integer.MAX_VALUE;
    for (int v = t; v != s; v = parent[v])
      flow = Math.min(flow, res[parent[v]][v]);
    for (int v = t; v != s; v = parent[v]) {
      int u = parent[v];
      res[u][v] -= flow;  // forward
      res[v][u] += flow;  // reverse
    }
    maxFlow += flow;
  }
  return maxFlow;
}

Output Question · Edmonds-Karp

Question 11: Which Edge Is the Bottleneck?

In the network shown the maximum flow is 17. Raising which edge's capacity by 1 makes it 18? Why does raising s → 1 not help?

s1234t8/89/120/35/53/69/104/79/98/8
Show answer

In the final residual network the set reachable from s is S = {s, 1, 2, 3, 4}; the only minimum cut is formed by the edges leaving it, 3 → t (9) and 4 → t (8) (17). Raising either of them makes the flow 18 .

None of the other edges is in the minimum cut; raising s → 1, for example, leaves the flow at 17: the bottleneck is on the sink side. The next smallest cut ({s, 2}: 18) means one increase gains at most 1.

Multiple Choice · Edmonds-Karp

Question 12: The Edmonds-Karp Bound

Which is the justification for Edmonds-Karp's O(V · E²) bound?

D: For an edge to become critical (saturated) again, its distance must grow by at least 2; since the distance is ≤ V, each edge becomes critical O(V) times → O(V · E) augmentations × O(E) per BFS. A is Ford-Fulkerson's bound, which depends on the flow value; C is the justification for Dinic.

Step-by-Step Trace · Dinic

Question 13: Tracing Dinic

How many phases does Dinic make on this network? What are the levels and the paths of the blocking flow in each phase?

s1234t0/80/120/30/50/60/100/70/90/8

Initially all flows are 0. In each phase, BFS first computes the levels (lv), then a blocking flow is found in the level graph.

s1234t0/80/120/30/50/60/100/70/90/8lv=0lv=1lv=1lv=2lv=2lv=3

Phase 1 BFS: levels s=0, 1=1, 2=1, 3=2, 4=2, t=3. Faded edges do not go up exactly one level or are saturated, so they are not used; the s–t distance is 3.

s1234t5/80/120/35/50/60/100/75/90/8lv=0lv=1lv=1lv=2lv=2lv=3

dfs path s → 1 → 3 → t, d = 5 → maxFlow = 5.

s1234t8/80/120/35/53/60/100/75/93/8lv=0lv=1lv=1lv=2lv=2lv=3

dfs path s → 1 → 4 → t, d = 3 → maxFlow = 8.

s1234t8/85/120/35/53/65/100/75/98/8lv=0lv=1lv=1lv=2lv=2lv=3

dfs path s → 2 → 4 → t, d = 5 → maxFlow = 13.

s1234t8/85/120/35/53/65/100/75/98/8lv=0lv=3lv=1lv=3lv=2lv=4

Phase 2 BFS: levels s=0, 1=3, 2=1, 3=3, 4=2, t=4. Faded edges do not go up exactly one level or are saturated, so they are not used; the s–t distance is 4.

s1234t8/89/120/35/53/69/104/79/98/8lv=0lv=3lv=1lv=3lv=2lv=4

dfs path s → 2 → 4 → 3 → t, d = 4 → maxFlow = 17.

s1234t8/89/120/35/53/69/104/79/98/8lv=0lv=3lv=1lv=3lv=2lv=−

Phase 3 BFS: only {s, 1, 2, 3, 4} is reachable, t has no level → the loop ends. return 17; 2 phases, 3 BFS runs were enough.

int dinic(int s, int t) {
  int maxFlow = 0;
  while (bfsLevel(s, t)) {   // levels
    int[] next = new int[V]; // next edge
    int d;
    while ((d = dfs(s, t, INF, next)) > 0)
      maxFlow += d;          // blocking flow
  }
  return maxFlow;
}

Multiple Choice · Dinic

Question 14: Dinic's Number of Phases

Which of the following is true for Dinic's algorithm?

B: The blocking flow saturates all shortest paths of that length; in the next BFS, t is farther away. O(V · E) per phase (with the next-edge array) × O(V) phases = O(V² · E). A describes Edmonds-Karp; C is wrong: the levels are recomputed at the start of every phase.

Step-by-Step Trace · Push–Relabel

Question 15: Tracing Push–Relabel

activeNode() returns the active vertex with the smallest index, residual(u, v) returns c − f; saturate saturates a source edge. Which push and relabel operations are performed, and what is the maximum flow?

sabt0/30/20/10/20/3h=0, e=0h=0, e=0h=0, e=0h=0, e=0

Network (flow/capacity), |V| = 4. Next to each vertex are its height h and excess flow e.

sabt3/32/20/10/20/3h=4, e=-5h=0, e=3h=0, e=2h=0, e=0

h(s) = |V| = 4; the edges leaving s are saturated: e(a) = 3, e(b) = 2. The preflow violates conservation (active vertices are yellow).

sabt3/32/20/10/20/3h=4, e=-5h=1, e=3h=0, e=2h=0, e=0

a is active but none of its residual neighbors is one level lower → relabel: h(a) = 1 + min(h(s)=4, h(b)=0, h(t)=0) = 1.

sabt3/32/21/10/20/3h=4, e=-5h=1, e=2h=0, e=3h=0, e=0

a is active; h(a) = 1 = h(b) + 1 and residual capacity exists → push δ = 1.

sabt3/32/21/12/20/3h=4, e=-5h=1, e=0h=0, e=3h=0, e=2

a is active; h(a) = 1 = h(t) + 1 and residual capacity exists → push δ = 2.

sabt3/32/21/12/20/3h=4, e=-5h=1, e=0h=1, e=3h=0, e=2

b is active but none of its residual neighbors is one level lower → relabel: h(b) = 1 + min(h(s)=4, h(a)=1, h(t)=0) = 1.

sabt3/32/21/12/23/3h=4, e=-5h=1, e=0h=1, e=0h=0, e=5

b is active; h(b) = 1 = h(t) + 1 and residual capacity exists → push δ = 3.

sabt3/32/21/12/23/3h=4, e=-5h=1, e=0h=1, e=0h=0, e=5

No active vertex is left: the preflow is a real flow. Maximum flow = e(t) = 5 (out of the source 3 + 2).

void pushRelabel(int s, int t) {
  h[s] = V;
  for (int v = 0; v < V; v++)        // preflow
    if (c[s][v] > 0) saturate(s, v);
  int u;
  while ((u = activeNode()) != -1) { // not s, t
    boolean pushed = false;
    for (int v = 0; v < V && !pushed; v++)
      if (residual(u, v) > 0 && h[u] == h[v] + 1) {
        int d = Math.min(e[u], residual(u, v));
        f[u][v] += d; f[v][u] -= d;
        e[u] -= d; e[v] += d;
        pushed = true;
      }
    if (!pushed)                     // relabel
      h[u] = 1 + minNeighborHeight(u);
  }
}

Multiple Choice · Push–Relabel

Question 16: Relabeling

The neighbors of the active vertex u in the residual network are x (h = 3), y (h = 5) and s (h = 6); the height of u is 3. What is done?

C: A push needs h(u) = h(v) + 1; with h(u) = 3 no neighbor has height 2, so no push is possible. Relabeling sets h(u) = 1 + min(3, 5, 6) = 4, after which a push to x is possible. A tries to push at equal height.

Classic Question · Applications

Question 17: Bipartite Matching

There are three workers (a₁, a₂, a₃) and three jobs (b₁, b₂, b₃): a₁ can do b₁ and b₂, a₂ can do only b₁, and a₃ can do only b₁. Each worker gets at most one job and each job at most one worker. Model the problem as a flow network; what is the largest matching?

Sa₁a₂a₃b₁b₂b₃T
Show answer

Every edge S → aᵢ, aᵢ → bⱼ (if the worker can do the job) and bⱼ → T gets capacity 1. By the integrality property the maximum flow is a 0/1-valued flow; the edges aᵢ → bⱼ that carry flow give the matching.

Maximum flow = largest matching = 2: for example a₁–b₂, a₂–b₁. Since a₂ and a₃ are connected only to b₁, they cannot both be matched.

Check: the cut whose source side is {S, a₂, a₃, b₁} has S → a₁ (1) + b₁ → T (1) = capacity 2 and is a minimum cut. Nobody is connected to b₃.

Multiple Choice · Applications

Question 18: What the Algorithms Share

Ford-Fulkerson, Edmonds-Karp, Dinic and push–relabel are applied to the same network. Which statement is wrong?

C is wrong: push–relabel never searches for an augmenting path, it does local pushes and relabels; Ford-Fulkerson and Edmonds-Karp also find different paths (6 and 4 paths in the trace examples). The value |f*| is the same for all and equals the minimum cut; the distribution may differ.

The End

Chapter 8: Network Flow: Study Questions
Lecture slides: Chapter 8: Network Flow · Lecture notes
1 / 1 Sercan KÜLCÜ. All rights reserved.