3.5.16Graphs

Network flow — max-flow min-cut theorem, Ford-Fulkerson, Edmonds-Karp

2,115 words10 min readdifficulty · medium

WHAT we are modelling


WHY max-flow = min-cut (derivation from scratch)

Step 1 — Flow across any cut equals f|f|.

Take any cut (S,T)(S,T). Sum the conservation equation over all nodes in SS. Internal edges (both endpoints in SS) appear once as +f+f and once as f-f and cancel. What survives is only flow crossing the cut: f=uS,vTf(u,v)    uS,vTf(v,u)|f| = \sum_{u\in S,\,v\in T} f(u,v) \;-\; \sum_{u\in S,\,v\in T} f(v,u) Why this step? Conservation forces everything inside SS to balance, so the net out of SS must equal the net out of ss, which is f|f|.

Step 2 — Weak duality: every flow ≤ every cut. f=f(forward)cf(backward)0    c(forward)=c(S,T)|f| = \underbrace{\sum f(\text{forward})}_{\le\, c} - \underbrace{\sum f(\text{backward})}_{\ge\, 0} \;\le\; \sum c(\text{forward}) = c(S,T) Why? Forward flows are capped by capacity; backward flows are subtracted and are 0\ge 0. So any flow value is bounded by any cut capacity. Hence maxfminc(S,T)\max|f| \le \min c(S,T).

Step 3 — Equality is achievable (the max-flow min-cut theorem).

When a flow is maximum, there is NO augmenting path in the residual graph (defined next). Let S=S= all nodes reachable from ss in the residual graph, TT = the rest. Then tSt\notin S. For this cut:

  • every forward edge uvu\to v (uS,vTu\in S,v\in T) is saturated (f=cf=c), else vv would be reachable;
  • every backward edge carries f=0f=0, else it would give a residual edge into TT.

Plug into Step 1: f=c(forward)0=c(S,T)|f| = \sum c(\text{forward}) - 0 = c(S,T). So this flow equals a cut capacity, and by Step 2 both are optimal. \blacksquare


The residual graph (the engine of all algorithms)

An augmenting path is any sts\to t path in the residual graph. Its bottleneck is the minimum cfc_f along it; pushing that much strictly increases f|f|.


Ford–Fulkerson (the method)


Edmonds–Karp (a smart path rule)

Figure — Network flow — max-flow min-cut theorem, Ford-Fulkerson, Edmonds-Karp

Worked Example 1 — push & augment by hand

Network: sas\to a (cap 3), sbs\to b (2), aba\to b (1), ata\to t (2), btb\to t (3).

Path 1: sats\to a\to t, bottleneck =min(3,2)=2=\min(3,2)=2. Push 2. Why? ata\to t is the limiter. Path 2: sbts\to b\to t, bottleneck =min(2,3)=2=\min(2,3)=2. Push 2. Path 3: sabts\to a\to b\to t, residual: sas\to a has 32=13-2=1, ab=1a\to b=1, bt=32=1b\to t=3-2=1. Bottleneck =1=1. Push 1. Now f=2+2+1=5|f| = 2+2+1 = 5. Why no more? ss's out-capacity is 3+2=53+2=5, all saturated — this is the min cut S={s}S=\{s\}, c=5c=5. Max flow = 5.

Worked Example 2 — backward edge saves the day

sas\to a (1), sbs\to b (1), aba\to b (1), ata\to t (1), btb\to t (1).

Greedy picks sabts\to a\to b\to t, bottleneck 1. Why might we panic? Now ata\to t and sbs\to b look unusable. But residual has backward bab\to a (cap 1). New path: sbats\to b\to a\to t? — sbs\to b(1), backward bab\to a(1), ata\to t(1). Push 1. Total =2=2 = min cut. Why this step? The backward edge undid the bad commitment aba\to b, freeing ata\to t. ✔



Recall Feynman: explain to a 12-year-old

Imagine water pipes from a tap to a bucket. Each pipe can only carry so much. You want maximum water reaching the bucket. The limit is the weakest place in the network — find the cheapest set of pipes to cut so no water gets through, and that's exactly the max water you can send. The algorithm keeps finding "still-open routes," pushes water, and is even allowed to take water back from a route it tried earlier and send it a better way. When no open route is left, you're done — you've hit the bottleneck.


Flashcards

What does a flow network require on each edge and which two special nodes?
A capacity c(u,v)0c(u,v)\ge0; a source ss and a sink tt.
State the two constraints a valid flow must satisfy.
Capacity (0fc0\le f\le c) and conservation (in-flow = out-flow at every non-s,ts,t node).
Define the capacity of an s–t cut (S,T)(S,T).
c(S,T)=uS,vTc(u,v)c(S,T)=\sum_{u\in S,v\in T} c(u,v) — only forward STS\to T edges.
State the max-flow min-cut theorem.
maxf=minc(S,T)\max |f| = \min c(S,T); max flow value equals the minimum cut capacity.
What are the three equivalent conditions for a flow being maximum?
(a) ff max, (b) no augmenting path in residual graph, (c) f=c(S,T)|f|=c(S,T) for some cut.
What is the residual capacity of edge (u,v)(u,v), and what backward edge appears?
cf(u,v)=c(u,v)f(u,v)c_f(u,v)=c(u,v)-f(u,v); plus backward edge vuv\to u with capacity f(u,v)f(u,v).
Why do we need backward residual edges?
To undo/re-route previously committed flow so greedy mistakes can be corrected.
What is an augmenting path and how much flow does it carry?
An sts\to t path in the residual graph; carries its bottleneck = min residual capacity along it.
Ford-Fulkerson complexity with integer capacities?
O(Ef)O(E\cdot|f^*|) — depends on the max-flow value (can be slow).
What rule defines Edmonds-Karp and what's its complexity?
Always augment along the BFS-shortest path; O(VE2)O(VE^2), independent of capacities.
Why is Edmonds-Karp capacity-independent?
BFS distances never decrease; each edge is saturated O(V)O(V) times → O(VE)O(VE) augmentations × O(E)O(E) BFS.
How do you recover the min cut after running max flow?
SS = nodes reachable from ss in the final residual graph; TT = rest. Forward edges across are saturated.
Why does flow across any cut equal f|f|?
Summing conservation over SS cancels internal edges, leaving net flow out of SS = net flow out of ss = f|f|.

Connections

  • Graphs — base data structure & traversal
  • BFS — the shortest-augmenting-path engine of Edmonds-Karp
  • Bipartite Matching — solved as unit-capacity max flow
  • Linear Programming Duality — max-flow/min-cut is its combinatorial special case
  • Dinic's Algorithm — faster O(V2E)O(V^2E) via level graphs + blocking flows
  • Menger's Theorem — edge/vertex disjoint paths = a flow corollary

Concept Map

has

has

value

capacity

Step1 flow across cut

Step2 weak duality

equality achievable

no augmenting path

defines

drives

Flow network G

Capacity constraint

Flow conservation

Feasible flow f

|f| net leaving s

s-t cut S,T

c of S,T forward edges

every flow <= every cut

Max-Flow Min-Cut theorem

Residual graph

Ford-Fulkerson / Edmonds-Karp

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Socho ek paani ke pipe ka network hai — ek source (tap) ss se ek sink (bucket) tt tak. Har pipe ki ek max capacity hai. Sawaal: kitna paani per second ss se tt tak bhej sakte ho? Iska jawab network ke sabse weak hisse pe depend karta hai — wo minimum set of pipes jinhe kaat do toh paani ruk jaaye. Yahi hai max-flow = min-cut ka magic: maximum flow ki value bilkul minimum cut ki capacity ke barabar hoti hai.

Algorithm kaise chalta hai? Ford-Fulkerson bolta hai: jab tak source se sink tak koi augmenting path (residual graph mein khula rasta) milta rahe, usme bottleneck (minimum bachi capacity) ke barabar paani push karte raho. Sabse zaroori cheez hai backward edges — yeh tumhe purana galat decision undo karne dete hain. Jaise pehle ek route pe paani bhej diya tha jo aage jaake fas gaya, toh backward edge se wapas le ke better route pe bhej sakte ho. Isliye greedy galti nahi karta.

Edmonds-Karp sirf ek smart twist hai: hamesha BFS se shortest path chuno augment karne ke liye. Isse complexity capacity values pe depend nahi karti, fixed O(VE2)O(VE^2) ho jaati hai — bahut reliable. Plain Ford-Fulkerson galat path choose kare toh slow ho sakta hai (O(Ef)O(E\cdot|f|)).

Yeh topic kyun important hai? Bipartite matching, image segmentation, scheduling, network reliability — sab ke andar yahi max-flow chhupa hota hai. Aur jab interview mein poochhe "max flow kaise prove karoge done?", jawab yaad rakho: residual graph mein koi augmenting path na bache, tabhi flow maximum hai, aur reachable nodes ka set SS ban jaata hai min cut.

Go deeper — visual, from zero

Test yourself — Graphs

Connections