79
Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao Tong University

Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Design and Analysis ofAlgorithms (X)

Max-Flow Min-Cut Theorem

Guoqiang Li

School of Software, Shanghai Jiao Tong University

Page 2: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow and Min-Cut Problems

Page 3: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

A Flow NetworkA flow network is a tuple G = (V ,E, s, t, c).• Diagraph (V ,E) with source s ∈ V and sink t ∈ V .• Capacity c(e) > 0 for each e ∈ E.

Intuition. Material flowing through a transportation network, whichoriginates at source and is sent to sink.

Page 4: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

A Flow NetworkA flow network is a tuple G = (V ,E, s, t, c).• Diagraph (V ,E) with source s ∈ V and sink t ∈ V .• Capacity c(e) > 0 for each e ∈ E.

Intuition. Material flowing through a transportation network, whichoriginates at source and is sent to sink.

Page 5: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Minimum-Cut Problem

An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈ B.

Its capacity is the sum of the capacities of the edges from A to B.

cap(A,B) =∑

e out of A

c(e)

Page 6: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Minimum-Cut Problem

An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈ B.

Its capacity is the sum of the capacities of the edges from A to B.

cap(A,B) =∑

e out of A

c(e)

Page 7: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Minimum-Cut Problem

An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈ B.

Its capacity is the sum of the capacities of the edges from A to B.

cap(A,B) =∑

e out of A

c(e)

Page 8: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Minimum-Cut Problem

An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈ B.

Its capacity is the sum of the capacities of the edges from A to B.

cap(A,B) =∑

e out of A

c(e)

Page 9: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Minimum-Cut Problem

Min-cut problem. Find a cut of minimum capacity.

Page 10: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Quiz 1

Which is the capacity of the given st-cut?

A. 11 (20 + 25− 8− 11− 9− 6)

B. 34 (8 + 11 + 9 + 6)

C. 45 (20 + 25)

D. 79 (20 + 25 + 8 + 11 + 9 + 6)

Page 11: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Maximum-Flow ProblemAn st-flow(flow) f is a function that satisfies:• For each e ∈ E: 0 ≤ f (e) ≤ c(e)• For each v ∈ V − {s, t}:

∑e in to v

f (e) =∑

e out of vf (e)

Page 12: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Maximum-Flow ProblemAn st-flow(flow) f is a function that satisfies:• For each e ∈ E: 0 ≤ f (e) ≤ c(e)• For each v ∈ V − {s, t}:

∑e in to v

f (e) =∑

e out of vf (e)

The value of a flow f is: val(f ) =∑

e out of sf (e)−

∑e in to s

f (e)

Page 13: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Maximum-Flow Problem

Max-flow problem. Find a flow of maximum value.

Page 14: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Ford-Fulkerson Algorithm

Page 15: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 16: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 17: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 18: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 19: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 20: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 21: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Toward a Max-Flow Algorithm

Greedy algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P where each edge has f (e) < c(e).• Augment flow along path P.• Repeat until you get stuck.

Page 22: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Why the Greedy Algorithm Fails

Q. Why does the greedy algorithm fail?

A. Once greedy algorithm increases flow on an edge, it neverdecreases it.

Ex. Consider flow network G.

• The unique max flow has f ∗(v,w) = 0.• Greedy algorithm could choose

s→ v→ w→ t as first augmentingpath.

Page 23: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Why the Greedy Algorithm Fails

Q. Why does the greedy algorithm fail?

A. Once greedy algorithm increases flow on an edge, it neverdecreases it.

Ex. Consider flow network G.

• The unique max flow has f ∗(v,w) = 0.• Greedy algorithm could choose

s→ v→ w→ t as first augmentingpath.

Page 24: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Why the Greedy Algorithm Fails

Q. Why does the greedy algorithm fail?

A. Once greedy algorithm increases flow on an edge, it neverdecreases it.

Ex. Consider flow network G.

• The unique max flow has f ∗(v,w) = 0.• Greedy algorithm could choose

s→ v→ w→ t as first augmentingpath.

Page 25: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Why the Greedy Algorithm Fails

Bottom line. Need some mechanism to undo a bad decision.

Page 26: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Residual NetworkOriginal edge e = (u, v) ∈ E.• Flow f (e).• Capacity c(e)

Reverse edge e reverse = (v, u)• Undo flow sent.

Residual capacity

cf (e) ={

c(e)− f (e) if e ∈ Ef (e) if e reverse ∈ E

Residual network Gf = (V ,Ef , s, t, cf )

• Ef = {e : f (e) < c(e)} ∪ {e reverse : f (e) > 0}.• Key property: f ′ is a flow in Gf iff f + f ′ is a flow in G

Page 27: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Residual NetworkOriginal edge e = (u, v) ∈ E.• Flow f (e).• Capacity c(e)

Reverse edge e reverse = (v, u)• Undo flow sent.

Residual capacity

cf (e) ={

c(e)− f (e) if e ∈ Ef (e) if e reverse ∈ E

Residual network Gf = (V ,Ef , s, t, cf )

• Ef = {e : f (e) < c(e)} ∪ {e reverse : f (e) > 0}.• Key property: f ′ is a flow in Gf iff f + f ′ is a flow in G

Page 28: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Augmenting Path

An augmenting path is a simple s t path in the residual network Gf .

The bottleneck capacity of an augmenting path P is the minimumresidual capacity of any edge in P.

Page 29: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Augmenting Path

An augmenting path is a simple s t path in the residual network Gf .

The bottleneck capacity of an augmenting path P is the minimumresidual capacity of any edge in P.

Page 30: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Augmenting PathKey Property.

Let f be a flow and let P be an augmenting path in Gf . After callingf ′ ← Augment(f , c,P), the resulting f ′ is a flow andval(f ′) = val(f ) + bottleneck(Gf ,P).

Augment(f ,c,P)

δ ← bottleneck capacity of augmenting path P;for each edge e ∈ P do

if (e ∈ E) then f (e)← f (e) + δ;else

f (e reverse )← f (e reverse )− δend

endReturn f ;

Page 31: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Augmenting PathKey Property.

Let f be a flow and let P be an augmenting path in Gf . After callingf ′ ← Augment(f , c,P), the resulting f ′ is a flow andval(f ′) = val(f ) + bottleneck(Gf ,P).

Augment(f ,c,P)

δ ← bottleneck capacity of augmenting path P;for each edge e ∈ P do

if (e ∈ E) then f (e)← f (e) + δ;else

f (e reverse )← f (e reverse )− δend

endReturn f ;

Page 32: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Quiz 2

Which is the augmenting path of highest bottleneck capacity?

A. A→ F → G→ H

B. A→ B→ C → D→ H

C. A→ F → B→ G→ H

D. A→ F → B→ G→ C → D→ H

Page 33: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Ford–Fulkerson Algorithm

Ford–Fulkerson augmenting path algorithm.

• Start with f (e) = 0 for each edge e ∈ E.• Find an s t path P in the residual network Gf .• Augment flow along path P.• Repeat until you get stuck.

Page 34: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Ford–Fulkerson Algorithm

Ford–Fulkerson(G)

for each edge e ∈ E dof (e)← 0

endGf ← residual network of G with respect to flow f ;while there exists an s t path P in Gf do

f ← Augment(f ,c,P);Update(Gf);

endReturn f ;

Page 35: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Page 36: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsLemmaLet f be any flow and let (A,B) be any cut. Then, the value of the flowf equals the net flow across the cut (A,B).

val(f ) =∑

out of A

f (e)−∑

e in to A

f (e)

Page 37: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsLemmaLet f be any flow and let (A,B) be any cut. Then, the value of the flowf equals the net flow across the cut (A,B).

val(f ) =∑

out of A

f (e)−∑

e in to A

f (e)

Page 38: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsLemmaLet f be any flow and let (A,B) be any cut. Then, the value of the flowf equals the net flow across the cut (A,B).

val(f ) =∑

out of A

f (e)−∑

e in to A

f (e)

Page 39: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Quiz 3Which is the net flow across the given cut?

A. 11 (20 + 25− 8− 11− 9− 6)

B. 26 (20 + 22− 8− 4− 4)

C. 42 (20 + 22)

D. 45 (20 + 25)

Page 40: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsLemmaLet f be any flow and let (A,B) be any cut. Then, the value of the flowf equals the net flow across the cut (A,B).

val(f ) =∑

out of A

f (e)−∑

e in to A

f (e)

Proof.

val(f ) =∑

e out of sf (e)−

∑e in to s

f (e)

=∑v∈A

( ∑e out of v

f (e)−∑

e in to vf (e)

)=

∑e out of A

f (e)−∑

e in to Af (e).

Page 41: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsLemmaLet f be any flow and let (A,B) be any cut. Then, the value of the flowf equals the net flow across the cut (A,B).

val(f ) =∑

out of A

f (e)−∑

e in to A

f (e)

Proof.

val(f ) =∑

e out of sf (e)−

∑e in to s

f (e)

=∑v∈A

( ∑e out of v

f (e)−∑

e in to vf (e)

)=

∑e out of A

f (e)−∑

e in to Af (e).

Page 42: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsTheorem [Weak Duality]Let f be any flow and (A,B) be any cut. Then, val(f ) ≤ cap(A,B).

Proof.

val(f ) =∑

e out of A

f (e)−∑

e in to A

f (e) ≤∑

e out of A

f (e) ≤∑

e out of A

c(e)

= cap(A,B)

Page 43: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsTheorem [Weak Duality]Let f be any flow and (A,B) be any cut. Then, val(f ) ≤ cap(A,B).

Proof.

val(f ) =∑

e out of A

f (e)−∑

e in to A

f (e) ≤∑

e out of A

f (e) ≤∑

e out of A

c(e)

= cap(A,B)

Page 44: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Flows and CutsTheorem [Weak Duality]Let f be any flow and (A,B) be any cut. Then, val(f ) ≤ cap(A,B).

Proof.

val(f ) =∑

e out of A

f (e)−∑

e in to A

f (e) ≤∑

e out of A

f (e) ≤∑

e out of A

c(e)

= cap(A,B)

Page 45: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Certificate of Optimality

CorollaryLet f be a flow and let (A,B) be any cut. If val(f ) = cap(A,B), then fis a max flow and (A,B) is a min cut.

Proof.• For any flow f ′ : val (f ′) ≤ cap(A,B) = val(f ).• For any cut (A′,B′) : cap (A′,B′) ≥ val(f ) = cap(A,B)

Page 46: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Certificate of Optimality

CorollaryLet f be a flow and let (A,B) be any cut. If val(f ) = cap(A,B), then fis a max flow and (A,B) is a min cut.

Proof.

• For any flow f ′ : val (f ′) ≤ cap(A,B) = val(f ).• For any cut (A′,B′) : cap (A′,B′) ≥ val(f ) = cap(A,B)

Page 47: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Certificate of Optimality

CorollaryLet f be a flow and let (A,B) be any cut. If val(f ) = cap(A,B), then fis a max flow and (A,B) is a min cut.

Proof.• For any flow f ′ : val (f ′) ≤ cap(A,B) = val(f ).• For any cut (A′,B′) : cap (A′,B′) ≥ val(f ) = cap(A,B)

Page 48: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-flow Min-Cut TheoremMax-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Page 49: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Max-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[i⇒ ii] This is the weak duality corollary.

Page 50: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Max-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[i⇒ ii] This is the weak duality corollary.

Page 51: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Max-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[i⇒ ii] This is the weak duality corollary.

Page 52: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Max-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[i⇒ ii]

This is the weak duality corollary.

Page 53: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem

Max-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[i⇒ ii] This is the weak duality corollary.

Page 54: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut TheoremMax-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[ii⇒ iii]

We prove contrapositive: ¬ iii⇒ ¬ii.• Suppose that there is an augmenting path with respect to f .• Can improve flow f by sending flow along this path.• Thus, f is not a max flow.

Page 55: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut TheoremMax-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[ii⇒ iii] We prove contrapositive: ¬ iii⇒ ¬ii.

• Suppose that there is an augmenting path with respect to f .• Can improve flow f by sending flow along this path.• Thus, f is not a max flow.

Page 56: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut TheoremMax-Flow Min-Cut TheoremValue of a max flow = capacity of a min cut.

Augmenting path theoremA flow f is a max flow iff no augmenting paths.

Proof. The following three conditions are equivalent for any flow f :

i. There exists a cut (A,B) such that cap(A,B) = val(f ).

ii. f is a max flow.

iii. There is no augmenting path with respect to f .

[ii⇒ iii] We prove contrapositive: ¬ iii⇒ ¬ii.• Suppose that there is an augmenting path with respect to f .• Can improve flow f by sending flow along this path.• Thus, f is not a max flow.

Page 57: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Max-Flow Min-Cut Theorem[ iii⇒ i ]

• Let f be a flow with no augmenting paths.• Let A be set of nodes reachable from s in residual network Gf .• By definition of A : s ∈ A.• By definition of flow f : t /∈ A.

val(f ) =∑

e out of A

f (e)−∑

e in to A

f (e)

=∑

e out of A

c(e)− 0

= cap(A,B)

Page 58: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Page 59: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Assumption. Every edge capacity c(e) is an integer between 1 and C.

Integrality invariant. Throughout Ford-Fulkerson, every edge flowf (e) and residual capacity cf (e) is an integer.

Proof. By induction on the number of augmenting paths.

TheoremFord–Fulkerson terminates after at most val (f ∗) ≤ nCaugmenting paths, where f ∗ is a max flow.

Proof. Each augmentation increases the value of the flow by at least 1.

Page 60: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Assumption. Every edge capacity c(e) is an integer between 1 and C.

Integrality invariant. Throughout Ford-Fulkerson, every edge flowf (e) and residual capacity cf (e) is an integer.

Proof. By induction on the number of augmenting paths.

TheoremFord–Fulkerson terminates after at most val (f ∗) ≤ nCaugmenting paths, where f ∗ is a max flow.

Proof. Each augmentation increases the value of the flow by at least 1.

Page 61: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Assumption. Every edge capacity c(e) is an integer between 1 and C.

Integrality invariant. Throughout Ford-Fulkerson, every edge flowf (e) and residual capacity cf (e) is an integer.

Proof. By induction on the number of augmenting paths.

TheoremFord–Fulkerson terminates after at most val (f ∗) ≤ nCaugmenting paths, where f ∗ is a max flow.

Proof. Each augmentation increases the value of the flow by at least 1.

Page 62: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Assumption. Every edge capacity c(e) is an integer between 1 and C.

Integrality invariant. Throughout Ford-Fulkerson, every edge flowf (e) and residual capacity cf (e) is an integer.

Proof. By induction on the number of augmenting paths.

TheoremFord–Fulkerson terminates after at most val (f ∗) ≤ nCaugmenting paths, where f ∗ is a max flow.

Proof. Each augmentation increases the value of the flow by at least 1.

Page 63: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

Assumption. Every edge capacity c(e) is an integer between 1 and C.

Integrality invariant. Throughout Ford-Fulkerson, every edge flowf (e) and residual capacity cf (e) is an integer.

Proof. By induction on the number of augmenting paths.

TheoremFord–Fulkerson terminates after at most val (f ∗) ≤ nCaugmenting paths, where f ∗ is a max flow.

Proof. Each augmentation increases the value of the flow by at least 1.

Page 64: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

CorollaryThe running time of Ford–Fulkerson is O(mnC).

Proof. Can use either BFS or DFS to find an augmenting path in O(m)time.

Integrality TheoremThere exists an integral max flow f ∗

Proof. Since Ford–Fulkerson terminates, theorem follows fromintegrality invariant.

Page 65: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

CorollaryThe running time of Ford–Fulkerson is O(mnC).

Proof. Can use either BFS or DFS to find an augmenting path in O(m)time.

Integrality TheoremThere exists an integral max flow f ∗

Proof. Since Ford–Fulkerson terminates, theorem follows fromintegrality invariant.

Page 66: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

CorollaryThe running time of Ford–Fulkerson is O(mnC).

Proof. Can use either BFS or DFS to find an augmenting path in O(m)time.

Integrality TheoremThere exists an integral max flow f ∗

Proof. Since Ford–Fulkerson terminates, theorem follows fromintegrality invariant.

Page 67: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Analysis of the Algorithm

CorollaryThe running time of Ford–Fulkerson is O(mnC).

Proof. Can use either BFS or DFS to find an augmenting path in O(m)time.

Integrality TheoremThere exists an integral max flow f ∗

Proof. Since Ford–Fulkerson terminates, theorem follows fromintegrality invariant.

Page 68: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Exponential Example

Q. Is generic Ford–Fulkerson algorithm poly-time in input size?

A. No. If max capacity is C, then algorithm can take ≥ C iterations.

• s→ v→ w→ t• s→ w→ v→ t• s→ v→ w→ t• s→ w→ v→ t• . . .• s→ v→ w→ t• s→ w→ v→ t

Page 69: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Exponential Example

Q. Is generic Ford–Fulkerson algorithm poly-time in input size?

A. No. If max capacity is C, then algorithm can take ≥ C iterations.

• s→ v→ w→ t• s→ w→ v→ t• s→ v→ w→ t• s→ w→ v→ t• . . .• s→ v→ w→ t• s→ w→ v→ t

Page 70: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Exponential Example

Q. Is generic Ford–Fulkerson algorithm poly-time in input size?

A. No. If max capacity is C, then algorithm can take ≥ C iterations.

• s→ v→ w→ t• s→ w→ v→ t• s→ v→ w→ t• s→ w→ v→ t• . . .• s→ v→ w→ t• s→ w→ v→ t

Page 71: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Quiz 4

The Ford–Fulkerson algorithm is guaranteed to terminate if the edgecapacities are . . .

A. Rational numbers.

B. Real numbers.

C. Both A and B.

D. Neither A nor B.

Page 72: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting Paths

Use care when selecting augmenting paths.

• Some choices lead to exponential algorithms.• Clever choices lead to polynomial algorithms.

Pathology. When edge capacities can be irrational, no guarantee thatFord–Fulkerson terminates (or converges to a maximum flow)!

Goal. Choose augmenting paths so that:

• Can find augmenting paths efficiently.• Few iterations.

Page 73: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting Paths

Use care when selecting augmenting paths.

• Some choices lead to exponential algorithms.• Clever choices lead to polynomial algorithms.

Pathology. When edge capacities can be irrational, no guarantee thatFord–Fulkerson terminates (or converges to a maximum flow)!

Goal. Choose augmenting paths so that:

• Can find augmenting paths efficiently.• Few iterations.

Page 74: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting Paths

Use care when selecting augmenting paths.

• Some choices lead to exponential algorithms.• Clever choices lead to polynomial algorithms.

Pathology. When edge capacities can be irrational, no guarantee thatFord–Fulkerson terminates (or converges to a maximum flow)!

Goal. Choose augmenting paths so that:

• Can find augmenting paths efficiently.• Few iterations.

Page 75: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting PathsChoose augmenting paths with:

• Max bottleneck capacity(“fattest”).• Sufficiently large bottleneck capacity.• Fewest edges.

Page 76: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting PathsChoose augmenting paths with:

• Max bottleneck capacity(“fattest”).

• Sufficiently large bottleneck capacity.• Fewest edges.

Page 77: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting PathsChoose augmenting paths with:

• Max bottleneck capacity(“fattest”).• Sufficiently large bottleneck capacity.

• Fewest edges.

Page 78: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Choosing Good Augmenting PathsChoose augmenting paths with:

• Max bottleneck capacity(“fattest”).• Sufficiently large bottleneck capacity.• Fewest edges.

Page 79: Design and Analysis of Algorithms (X) - SJTUliguoqiang/teaching/X... · Design and Analysis of Algorithms (X) Max-Flow Min-Cut Theorem Guoqiang Li School of Software, Shanghai Jiao

Referred Materials

• Content of this lecture comes from Section 7.1-7.2 in [KT05].