Nisarg Shah 373F19 - Nisarg Shah 1 Recap Dynamic Programming - - PowerPoint PPT Presentation

nisarg shah
SMART_READER_LITE
LIVE PREVIEW

Nisarg Shah 373F19 - Nisarg Shah 1 Recap Dynamic Programming - - PowerPoint PPT Presentation

CSC373 Week 4: Dynamic Programming (contd) Network Flow (start) Nisarg Shah 373F19 - Nisarg Shah 1 Recap Dynamic Programming Basics Optimal substructure property Bellman equation Top-down (memoization) vs bottom-up


slide-1
SLIDE 1

CSC373 Week 4: Dynamic Programming (contd) Network Flow (start)

373F19 - Nisarg Shah 1

Nisarg Shah

slide-2
SLIDE 2

Recap

373F19 - Nisarg Shah 2

  • Dynamic Programming Basics

➢ Optimal substructure property ➢ Bellman equation ➢ Top-down (memoization) vs bottom-up implementations

  • Dynamic Programming Examples

➢ Weighted interval scheduling ➢ Knapsack problem ➢ Single-source shortest paths ➢ Chain matrix product ➢ Edit distance (aka sequence alignment)

slide-3
SLIDE 3

This Lecture

373F19 - Nisarg Shah 3

  • Some more DP

➢ Traveling salesman problem (TSP)

  • Start of network flow

➢ Problem statement ➢ Ford-Fulkerson algorithm ➢ Running time ➢ Correctness

slide-4
SLIDE 4

Traveling Salesman

373F19 - Nisarg Shah 4

  • Input

➢ Directed graph 𝐻 = (𝑊, 𝐹) ➢ Distance 𝑒𝑗,𝑘 is the distance from node 𝑗 to node 𝑘

  • Output

➢ Minimum distance which needs to be traveled to start

from some node 𝑤, visit every other node exactly once, and come back to 𝑤

  • That is, the minimum cost of a Hamiltonian cycle
slide-5
SLIDE 5

Traveling Salesman

373F19 - Nisarg Shah 5

  • Approach

➢ Let’s start at node 𝑤1 = 1

  • It’s a cycle, so the starting point does not matter

➢ Want to visit the other nodes in some order, say 𝑤2, … , 𝑤𝑜 ➢ Total distance is 𝑒1,𝑤2 + 𝑒𝑤2,𝑤3 + ⋯ + 𝑒𝑤𝑜−1,𝑤𝑜 + 𝑒𝑤𝑜,1

  • Want to minimize this distance
  • Naïve solution

➢ Check all possible orderings ➢ 𝑜 − 1 ! = Θ

𝑜 ⋅

𝑜 𝑓 𝑜

(Stirling’s approximation)

slide-6
SLIDE 6

Traveling Salesman

373F19 - Nisarg Shah 6

  • DP Approach

➢ Consider 𝑤𝑜 (the last node before returning to 𝑤1 = 1)

  • If 𝑤𝑜 = 𝑑
  • Find optimal order of visiting nodes in 2, … , 𝑜 ∖ 𝑑 and then

ending at 𝑑

  • Need to keep track of the subset of nodes visited and the end

node

➢ 𝑃𝑄𝑈 𝑇, 𝑑 = minimum total travel distance when starting at 1, visiting

each node in 𝑇 exactly once, and ending at 𝑑 ∈ 𝑇

➢ The original answer is min

𝑑∈𝑇 𝑃𝑄𝑈 𝑇, 𝑑 + 𝑒𝑑,1, where 𝑇 = {2, … , 𝑜}

slide-7
SLIDE 7

Traveling Salesman

373F19 - Nisarg Shah 7

  • DP Approach

➢ To compute 𝑃𝑄𝑈[𝑇, 𝑑], we condition over the vertex

which is visited right before 𝑑

  • Bellman equation

𝑃𝑄𝑈 𝑇, 𝑑 = min

𝑛∈𝑇∖ 𝑑 𝑃𝑄𝑈 𝑇 ∖ 𝑑 , 𝑛 + 𝑒𝑛,𝑑

Final solution = min

𝑑∈ 2,…,𝑜 𝑃𝑄𝑈 2, … , 𝑜 , 𝑑 + 𝑒𝑑,1

  • Time: 𝑃(𝑜 ⋅ 2𝑜) calls, 𝑃(𝑜) time per call ⇒ 𝑃 𝑜2 ⋅ 2𝑜

➢ Much better than the naïve solution which has

Τ

𝑜 𝑓 𝑜

slide-8
SLIDE 8

Traveling Salesman

373F19 - Nisarg Shah 8

  • Bellman equation

𝑃𝑄𝑈 𝑇, 𝑑 = min

𝑛∈𝑇∖ 𝑑 𝑃𝑄𝑈 𝑇 ∖ 𝑑 , 𝑛 + 𝑒𝑛,𝑑

Final solution = min

𝑑∈ 2,…,𝑜 𝑃𝑄𝑈 2, … , 𝑜 , 𝑑 + 𝑒𝑑,1

  • Space complexity: 𝑃 𝑜 ⋅ 2𝑜

➢ But computing the optimal solution with 𝑇 = 𝑙 only requires

storing the optimal solutions with 𝑇 = 𝑙 − 1

  • Question:

➢ Using this observation, how much can we reduce the space

complexity?

slide-9
SLIDE 9

DP Concluding Remarks

373F19 - Nisarg Shah 9

  • Key steps in designing a DP algorithm

➢ “Generalize” the problem first

  • E.g. instead of computing edit distance between strings 𝑌 =

𝑦1, … , 𝑦𝑛 and 𝑍 = 𝑧1, … , 𝑧𝑜, we compute 𝐹[𝑗, 𝑘] = edit distance between 𝑗-prefix of 𝑌 and 𝑘-prefix of 𝑍 for all (𝑗, 𝑘)

  • The right generalization is often obtained by looking at the

structure of the “subproblem” which must be solved optimally to get an optimal solution to the overall problem

➢ Remember the difference between DP and divide-and-

conquer

➢ Sometimes you can save quite a bit of space by only

storing solutions to those subproblems that you need in the future

slide-10
SLIDE 10

Network Flow

373F19 - Nisarg Shah 10

slide-11
SLIDE 11

Network Flow

373F19 - Nisarg Shah 11

  • Input

➢ A directed graph 𝐻 = (𝑊, 𝐹) ➢ Edge capacities 𝑑 ∶ 𝐹 → ℝ≥0 ➢ Source node 𝑡, target node 𝑢

  • Output

➢ Maximum “flow” from 𝑡 to 𝑢

slide-12
SLIDE 12

Network Flow

373F19 - Nisarg Shah 12

  • Assumptions

➢ For simplicity, assume that… ➢ No edges enter 𝑡 ➢ No edges leave 𝑢 ➢ Edge capacity 𝑑(𝑓) is a non-

negative integer

  • Later, we’ll see what happens

when 𝑑(𝑓) can be a rational number

slide-13
SLIDE 13

Network Flow

373F19 - Nisarg Shah 13

  • Flow

➢ An 𝑡-𝑢 flow is a function 𝑔: 𝐹 → ℝ≥0 ➢ Intuitively, 𝑔(𝑓) is the “amount of material” carried on

edge 𝑓

slide-14
SLIDE 14

Network Flow

373F19 - Nisarg Shah 14

  • Constraints on flow 𝑔
  • 1. Respecting capacities

∀𝑓 ∈ 𝐹 ∶ 0 ≤ 𝑔 𝑓 ≤ 𝑑(𝑓)

  • 2. Flow conservation

∀𝑤 ∈ 𝑊 ∖ 𝑡, 𝑢 ∶ σ𝑓 entering 𝑤 𝑔 𝑓 = σ𝑓 leaving 𝑤 𝑔 𝑓

Flow in = flow out at every node other than 𝑡 and 𝑢 Flow out at 𝑡 = flow in at 𝑢

slide-15
SLIDE 15

Network Flow

373F19 - Nisarg Shah 15

  • 𝑔𝑗𝑜 𝑤 = σ𝑓 entering 𝑤 𝑔 𝑓
  • 𝑔𝑝𝑣𝑢 𝑤 = σ𝑓 leaving 𝑤 𝑔 𝑓
  • Value of flow 𝑔 is 𝑤 𝑔 = 𝑔𝑝𝑣𝑢 𝑡 = 𝑔𝑗𝑜(𝑢)
  • Restating the problem:

➢ Given a directed graph 𝐻 = (𝑊, 𝐹) with edge capacities

𝑑: 𝐹 → ℝ≥0, find a flow 𝑔∗ with the maximum value.

slide-16
SLIDE 16

First Attempt

373F19 - Nisarg Shah 16

  • A natural greedy approach

1. Start from zero flow (𝑔 𝑓 = 0 for each 𝑓). 2. While there exists an 𝑡-𝑢 path 𝑄 in 𝐻 such that 𝑔 𝑓 < 𝑑(𝑓) for each 𝑓 ∈ 𝑄 a. Find one such path 𝑄 b. Increase the flow on each edge 𝑓 ∈ 𝑄 by min

𝑓∈𝑄 𝑑 𝑓 − 𝑔 𝑓

  • Let’s run it on an example!
slide-17
SLIDE 17

First Attempt

373F19 - Nisarg Shah 17

slide-18
SLIDE 18

First Attempt

373F19 - Nisarg Shah 18

slide-19
SLIDE 19

First Attempt

373F19 - Nisarg Shah 19

slide-20
SLIDE 20

First Attempt

373F19 - Nisarg Shah 20

slide-21
SLIDE 21

First Attempt

373F19 - Nisarg Shah 21

slide-22
SLIDE 22

First Attempt

373F19 - Nisarg Shah 22

slide-23
SLIDE 23

First Attempt

373F19 - Nisarg Shah 23

slide-24
SLIDE 24

First Attempt

373F19 - Nisarg Shah 24

  • Q: Why does the simple greedy approach fail?
  • A: Because once it increases the flow on an edge, it

is not allowed to decrease it.

  • Need a way to “reverse”

bad decisions

slide-25
SLIDE 25

Reversing Bad Decisions

373F19 - Nisarg Shah 25

s t u v

𝟑𝟏/20 𝟑𝟏/30 𝟑𝟏/20 0/10 0/10

Suppose we start by sending 20 units of flow along this path s t u v

𝟑𝟏/20 𝟐𝟏/30 𝟑𝟏/20 𝟐𝟏/10 𝟐𝟏/10

But the optimal configuration requires 10 fewer units of flow on 𝑣 → 𝑤

slide-26
SLIDE 26

Reversing Bad Decisions

373F19 - Nisarg Shah 26

We can essentially send a “reverse” flow of 10 units along 𝑤 → 𝑣 s t u v

𝟑𝟏/20 𝟐𝟏/30 𝟑𝟏/20 𝟐𝟏/10 𝟐𝟏/10

So now we get this optimal flow s t u v

𝟑𝟏/20 𝟑𝟏/30 𝟑𝟏/20 𝟐𝟏/10 𝟐𝟏/10 𝟐𝟏

slide-27
SLIDE 27

Residual Graph

373F19 - Nisarg Shah 27

  • Suppose the current flow is 𝑔
  • Define the residual graph 𝐻𝑔 of flow 𝑔

➢ 𝐻𝑔 has the same vertices as 𝐻 ➢ For each edge e = (𝑣, 𝑤) in 𝐻, 𝐻𝑔 has at most two edges

  • Forward edge 𝑓 = (𝑣, 𝑤) with capacity 𝑑 𝑓 − 𝑔 𝑓
  • We can send this much additional flow on 𝑓
  • Reverse edge 𝑓𝑠𝑓𝑤 = (𝑤, 𝑣) with capacity 𝑔(𝑓)
  • The maximum “reverse” flow we can send is the maximum

amount by which we can reduce flow on 𝑓, which is 𝑔(𝑓)

  • We only add edge of capacity > 0
slide-28
SLIDE 28

Residual Graph

373F19 - Nisarg Shah 28

  • Example!

s t u v

20/20 20/30 20/20 0/10 0/10

s t u v

𝟑𝟏 𝟐𝟏 𝟑𝟏 𝟐𝟏 𝟐𝟏 𝟑𝟏

Flow 𝑔 Residual graph 𝐻𝑔

slide-29
SLIDE 29

Augmenting Paths

373F19 - Nisarg Shah 29

  • Let 𝑄 be an 𝑡-𝑢 path in the residual graph 𝐻𝑔
  • Let bottleneck(𝑄, 𝑔) be the smallest capacity across

all edges in 𝑄

  • “Augment” flow 𝑔 by “sending” bottleneck 𝑄, 𝑔

units of flow along 𝑄

➢ What does it mean to send 𝑦 units of flow along 𝑄? ➢ For each forward edge 𝑓 ∈ 𝑄, increase the flow on 𝑓 by 𝑦 ➢ For each reverse edge 𝑓𝑠𝑓𝑤 ∈ 𝑄, decrease the flow on 𝑓 by 𝑦

slide-30
SLIDE 30

Residual Graph

373F19 - Nisarg Shah 30

  • Example!

s t u v

20/20 20/30 20/20 0/10 0/10

Flow 𝑔 s t u v

𝟑𝟏 𝟐𝟏 𝟑𝟏 𝟐𝟏 𝟐𝟏

Residual graph 𝐻𝑔 Path 𝑸 → send flow = bottleneck = 10

𝟑𝟏

slide-31
SLIDE 31

s t u v

20/20 10/30 20/20 10/10 10/10

New flow 𝑔

Residual Graph

373F19 - Nisarg Shah 31

  • Example!

s t u v

𝟑𝟏 𝟑𝟏 𝟑𝟏 𝟐𝟏 𝟐𝟏

New residual graph 𝐻𝑔 No 𝒕-𝒖 path because no outgoing edge from 𝒕

𝟐𝟏

slide-32
SLIDE 32

Augmenting Paths

373F19 - Nisarg Shah 32

  • Let’s argue that the new flow is a valid flow
  • Capacity constraints (easy):

➢ If we increase flow on 𝑓, we can do so by at most the

capacity of forward edge 𝑓 in 𝐻𝑔, which is 𝑑 𝑓 − 𝑔 𝑓

  • So the new flow can be at most 𝑔 𝑓 + 𝑑 𝑓 − 𝑔 𝑓

= 𝑑(𝑓)

➢ If we decrease flow on 𝑓, we can do so by at most the

capacity of reverse edge 𝑓𝑠𝑓𝑤 in 𝐻𝑔, which is 𝑔 𝑓

  • So the new flow is at least 𝑔 𝑓 − 𝑔 𝑓 = 0
slide-33
SLIDE 33

Augmenting Paths

373F19 - Nisarg Shah 33

  • Let’s argue that the new flow is a valid flow
  • Flow conservation (more tricky):

➢ Each node on the path (except 𝑡 and 𝑢) has exactly two

incident edges

  • Both forward / both reverse ⇒ one is incoming, one is outgoing
  • Flow increased on both or decreased on both
  • One forward, one reverse ⇒ both incoming / both outgoing
  • Flow increased on one but decreased on the other
  • In each case, net flow remains 0

s t +𝑦 +𝑦 −𝑦 −𝑦 +𝑦

slide-34
SLIDE 34

Ford-Fulkerson Algorithm

373F19 - Nisarg Shah 34

MaxFlow(𝐻):

// initialize: Set 𝑔 𝑓 = 0 for all 𝑓 in 𝐻 // while there is an 𝑡-𝑢 path in 𝐻𝑔: While 𝑄 = FindPath(s, t,Residual(𝐻, 𝑔))!=None: 𝑔 = Augment(𝑔, 𝑄) UpdateResidual(𝐻,𝑔) EndWhile Return 𝑔

slide-35
SLIDE 35

Ford-Fulkerson Algorithm

373F19 - Nisarg Shah 35

  • Running time:

➢ #Augmentations:

  • At every step, flow and capacities remain integers
  • For path 𝑄 in 𝐻𝑔, bottleneck 𝑄, 𝑔 > 0 implies bottleneck 𝑄, 𝑔 ≥ 1
  • Each augmentation increases flow by at least 1
  • At most 𝐷 = σ𝑓 leaving 𝑡 𝑑(𝑓) augmentations

➢ Time for an augmentation:

  • 𝐻𝑔 has 𝑜 vertices and at most 2𝑛 edges
  • Finding an 𝑡-𝑢 path in 𝐻𝑔 takes 𝑃(𝑛 + 𝑜) time

➢ Total time: 𝑃( 𝑛 + 𝑜 ⋅ 𝐷)

slide-36
SLIDE 36

Ford-Fulkerson Algorithm

373F19 - Nisarg Shah 36

  • Total time: 𝑃( 𝑛 + 𝑜 ⋅ 𝐷)

➢ This is pseudo-polynomial time ➢ 𝐷 can be exponentially large in the input length (the number

  • f bits required to write down the edge capacities)

➢ Note: We assumed integer capacities, but this also gives a

pseudo-polynomial time algorithm for rational capacities

  • Why?
  • Q: Can we convert this to polynomial time?
slide-37
SLIDE 37

Ford-Fulkerson Algorithm

373F19 - Nisarg Shah 37

  • Q: Can we convert this to polynomial time?

➢ Not if we choose an arbitrary path in 𝐻𝑔 at each step ➢ In the graph below, we might end up repeatedly sending 1

unit of flow across 𝑏 → 𝑐 and then reversing it

  • Takes 𝑌 steps, which can be exponential in the input length
slide-38
SLIDE 38

A Brief Note

373F19 - Nisarg Shah 38

  • Two quantities

➢ Number of integers provided as input ➢ Total number of bits provided as input

  • Running time

➢ Strongly polynomial time

  • #ops polynomial in #integers but not dependent on #bits
  • Running time still polynomial in #bits

➢ Weakly polynomial time

  • #ops polynomial in #bits

➢ Pseudo-polynomial time

  • #ops polynomial in the values of the input integers (i.e. polynomial in the

number of “unary digits” required to write input)

slide-39
SLIDE 39

Ford-Fulkerson Algorithm

373F19 - Nisarg Shah 39

  • Ways to achieve polynomial time

➢ Find the shortest augmenting path using BFS

  • Edmonds-Karp algorithm
  • Runs in 𝑃 𝑜𝑛2 operations
  • “Strongly polynomial time”
  • Can be found in CLRS

➢ Find the maximum bottleneck capacity augmenting path

  • Runs in 𝑃 𝑛2 ⋅ log 𝐷 operations
  • “Weakly polynomial time”

➢ …

slide-40
SLIDE 40

Max Flow Problem

373F19 - Nisarg Shah 40

  • Race to reduce the running time

➢ 1972: 𝑃 𝑜 𝑛2 Edmonds-Karp ➢ 1980: 𝑃 𝑜 𝑛 log2 𝑜 Galil-Namaad ➢ 1983: 𝑃 𝑜 𝑛 log 𝑜 Sleator-Tarjan ➢ 1986: 𝑃 𝑜 𝑛 log

Τ

𝑜2 𝑛

Goldberg-Tarjan

➢ 1992: 𝑃 𝑜 𝑛 + 𝑜2+𝜗 King-Rao-Tarjan ➢ 1996: 𝑃 𝑜 𝑛

log 𝑜 log ൗ

𝑛 𝑜 log 𝑜

King-Rao-Tarjan

  • Note: These are 𝑃(𝑜 𝑛) when 𝑛 = 𝜕 𝑜

➢ 2013: 𝑃(𝑜 𝑛) Orlin

  • Breakthrough!
slide-41
SLIDE 41

Back to Ford-Fulkerson

373F19 - Nisarg Shah 41

  • We argued that the algorithm must terminate, and

must terminate in 𝑃 𝑛 + 𝑜 ⋅ 𝐷 time

  • But we didn’t argue correctness yet, i.e., the

algorithm must terminate with the optimal flow

slide-42
SLIDE 42

Recall: Ford-Fulkerson

373F19 - Nisarg Shah 42

MaxFlow(𝐻):

// initialize: Set 𝑔 𝑓 = 0 for all 𝑓 in 𝐻 // while there is an 𝑡-𝑢 path in 𝐻𝑔: While 𝑄 = FindPath(s, t,Residual(𝐻, 𝑔))!=None: 𝑔 = Augment(𝑔, 𝑄) UpdateResidual(𝐻,𝑔) EndWhile Return 𝑔

slide-43
SLIDE 43

Recall: Notation

373F19 - Nisarg Shah 43

  • 𝑔 = flow, 𝑡 = source, 𝑢 = target
  • 𝑔𝑝𝑣𝑢, 𝑔𝑗𝑜

➢ For a node 𝑣: 𝑔𝑝𝑣𝑢 𝑣 , 𝑔𝑗𝑜(𝑣) = total flow out of and into 𝑣 ➢ For a set of nodes 𝑌: 𝑔𝑝𝑣𝑢 𝑌 , 𝑔𝑗𝑜(𝑌) defined similarly

  • Constraints

➢ Capacity: 0 ≤ 𝑔 𝑓 ≤ 𝑑(𝑓) ➢ Flow conservation: 𝑔𝑝𝑣𝑢 𝑣 = 𝑔𝑗𝑜(𝑣) for all 𝑣 ≠ 𝑡, 𝑢

  • 𝑤 𝑔 = 𝑔𝑝𝑣𝑢(𝑡) = 𝑔𝑗𝑜(𝑢) = value of the flow
slide-44
SLIDE 44

Cuts and Cut Capacities

373F19 - Nisarg Shah 44

  • (𝐵, 𝐶) is an 𝑡-𝑢 cut if it is a partition of vertex set 𝑊 (i.e. 𝐵 ∪ 𝐶 = 𝑊,

𝐵 ∩ 𝐶 = ∅) with 𝑡 ∈ 𝐵, and 𝑢 ∈ 𝐶

  • Its capacity, denoted 𝑑𝑏𝑞 𝐵, 𝐶 , is the sum of capacities of edges leaving 𝐵
slide-45
SLIDE 45

Cuts and Flows

373F19 - Nisarg Shah 45

  • Theorem: For any flow 𝑔 and any 𝑡-𝑢 cut (𝐵, 𝐶),

𝑤 𝑔 = 𝑔𝑝𝑣𝑢 𝐵 − 𝑔𝑗𝑜(𝐵)

  • Proof (on the board): Just take a sum of the flow conservation

constraint over all nodes in 𝐵

slide-46
SLIDE 46

Cuts and Flows

373F19 - Nisarg Shah 46

  • Theorem: For any flow 𝑔 and any 𝑡-𝑢 cut (𝐵, 𝐶),

𝑤 𝑔 ≤ 𝑑𝑏𝑞(𝐵, 𝐶)

  • Proof:

𝑤 𝑔 = 𝑔𝑝𝑣𝑢 𝐵 − 𝑔𝑗𝑜 𝐵 ≤ 𝑔𝑝𝑣𝑢 𝐵 = σ𝑓 leaving 𝐵 𝑔(𝑓) ≤ σ𝑓 leaving 𝐵 𝑑(𝑓) = 𝑑𝑏𝑞(𝐵, 𝐶)

slide-47
SLIDE 47

Cuts and Flows

373F19 - Nisarg Shah 47

  • Theorem: For any flow 𝑔 and any 𝑡-𝑢 cut (𝐵, 𝐶),

𝑤 𝑔 ≤ 𝑑𝑏𝑞(𝐵, 𝐶)

  • Hence, max value of any flow ≤ min capacity of any 𝑡-𝑢 cut.
  • We will now prove:

➢ Value of flow generated by Ford-Fulkerson = capacity of some cut

  • Implications

➢ 1) Max flow = min cut ➢ 2) Ford-Fulkerson generates max flow.

slide-48
SLIDE 48

Cuts and Flows

373F19 - Nisarg Shah 48

  • Theorem: Ford-Fulkerson finds maximum flow.
  • Proof:

➢ 𝑔 = flow returned by Ford-Fulkerson ➢ 𝐵∗ = nodes reachable from 𝑡 in 𝐻𝑔 ➢ 𝐶∗ = remaining nodes 𝑊 ∖ 𝐵∗ ➢ Note: We look at the residual graph 𝐻𝑔, but define the cut in 𝐻

Graph 𝐻

𝐻𝑔

slide-49
SLIDE 49

Cuts and Flows

373F19 - Nisarg Shah 49

  • Theorem: Ford-Fulkerson finds maximum flow.
  • Proof:

➢ Claim: 𝐵∗, 𝐶∗ is a valid cut

  • 𝑡 ∈ 𝐵∗ by definition
  • 𝑢 ∈ 𝐶∗ because when Ford-Fulkerson terminates, there are no 𝑡-𝑢

paths in 𝐻𝑔, so 𝑢 ∉ 𝐵∗

Graph 𝐻

𝐻𝑔

slide-50
SLIDE 50

Cuts and Flows

373F19 - Nisarg Shah 50

  • Theorem: Ford-Fulkerson finds maximum flow.
  • Proof:

➢ Blue edges = edges going out of 𝐵∗ in 𝐻 ➢ Red edges = edges coming into 𝐵∗ in 𝐻

Graph 𝐻

𝐻𝑔

slide-51
SLIDE 51

Cuts and Flows

373F19 - Nisarg Shah 51

  • Theorem: Ford-Fulkerson finds maximum flow.
  • Proof:

➢ Each blue edge 𝑣, 𝑤 must be saturated

  • Otherwise 𝐻𝑔 would have its forward edge 𝑣, 𝑤 and then 𝑤 ∈ 𝐵∗

➢ Each red edge (𝑤, 𝑣) must have zero flow

  • Otherwise 𝐻𝑔 would have its reverse edge (𝑣, 𝑤) and then 𝑤 ∈ 𝐵∗

Graph 𝐻

𝐻𝑔

slide-52
SLIDE 52

Cuts and Flows

373F19 - Nisarg Shah 52

  • Theorem: Ford-Fulkerson finds maximum flow.
  • Proof:

➢ Each blue edge 𝑣, 𝑤 must be saturated ⇒ 𝑔𝑝𝑣𝑢 𝐵∗ = 𝑑𝑏𝑞(𝐵∗, 𝐶∗) ➢ Each red edge (𝑤, 𝑣) must have zero flow ⇒ 𝑔𝑗𝑜 𝐵∗ = 0 ➢ So 𝑤 𝑔 = 𝑔𝑝𝑣𝑢 𝐵∗ − 𝑔𝑗𝑜(𝐵∗) = 𝑑𝑏𝑞 𝐵∗, 𝐶∗ ∎

Graph 𝐻

𝐻𝑔

slide-53
SLIDE 53

Max Flow - Min Cut

373F19 - Nisarg Shah 53

  • Max Flow-Min Cut Theorem:

In any graph, the value of the maximum flow is equal to the capacity of the minimum cut.

  • Our proof already gives an algorithm to find a min cut

➢ Run Ford-Fulkerson to find a max flow 𝑔 ➢ Construct its residual graph 𝐻𝑔 ➢ Let 𝐵∗ = set of all nodes reachable from 𝑡 in 𝐻𝑔

  • Easy to compute using BFS

➢ Then (𝐵∗, 𝑊 ∖ 𝐵∗) is a min cut

slide-54
SLIDE 54

Piazza Poll

373F19 - Nisarg Shah 54

Question

  • There is a network 𝐻 with positive integer edge capacities.
  • You run Ford-Fulkerson.
  • It finds an augmenting path with bottleneck capacity 1, and after that

iteration, it terminates with a final flow value of 1.

  • Which of the following statement(s) must be correct about 𝐻?

(a) 𝐻 has a single 𝑡-𝑢 path. (b) 𝐻 has an edge 𝑓 such that all 𝑡-𝑢 paths go through 𝑓. (c) The minimum cut capacity in 𝐻 is greater than 1. (d) The minimum cut capacity in 𝐻 is less than 1.

slide-55
SLIDE 55

Why Study Flow Networks?

373F19 - Nisarg Shah 55

  • Unlike divide-and-conquer, greedy, or DP, this doesn’t seem

like an algorithmic framework

➢ It seems more like a single problem

  • Turns out that many problems can be reduced to this

versatile single problem

  • Next lecture!