f22 hw7 Sol
f22 hw7 Sol
1. Suppose you are given a directed graph G = (V, E), two vertices s and t, a capacity function
c : E → R+ , and a second function f : E → R. Do not assume anything about the function f .
Rubric: 5 points = 1 for each step + 1 for time analysis. No penalty for implicitly assuming
that flow networks are connected, which implies that V = O(E).
(b) Describe and analyze an efficient algorithm to determine whether f is the unique
maximum (s, t)-flow in G.
Solution: First we verify that f is a maximum (s, t)-flow in G, using the algo-
rithm from part (a). Assume f is a maximum flow, since otherwise we are already
done.
Now we claim that f is the unique maximum flow in G if and only if the
residual network G f contains no simple directed cycles of length at least 3.
1/1 1/2 1 1
s t s t
1
1
CS 473 Homework 7 Solutions Fall 2022
10/20 5/15 10 5
0/15 10 10
15
s 5/10 0/10 t s 5 5 10 t
10
5/10 10/20 10
10
10/10 10
5/5 0/5
10/10 0/10
The simplest method to find nontrivial cycles in the residual graph is es-
sentially brute force. For each edge u v in the residual graph, we remove the
reversed edge v u from G f (if it exists), and then look for a path from v to u
using whatever-first search. If we find a path from u to v, adding the edge u v
completes the cycle. The resulting algorithm runs in O(E 2 ) time. 〈〈This is worth
4 points.〉〉
2
CS 473 Homework 7 Solutions Fall 2022
3
CS 473 Homework 7 Solutions Fall 2022
UniqueMaxFlow(G, f ):
construct the residual graph G f 〈〈Ford Fulkerson O(E)〉〉
compute the strong components of G f 〈〈Tarjan O(E)〉〉
for each strong component H of G f
compute the biconnected components of H 〈〈Hopcroft Tarjan O(EH )〉〉
for each biconnected component H ′ of H
if H ′ has more than two vertices
return False
return True
Solution (+5 extra credit): First, let H be the subgraph of G f induced by all
pairs of opposing edges u v and v u. Because H is symmetric, we can treat it as
an undirected graph. We can test whether this undirected graph contains a cycle
using whatever-first search in O(E) time. If so, then G f contains a nontrivial
simple cycle, so we can report that f is not the only maximum flow. Otherwise,
H is a forest.
Let G f /H denote the (multi-)graph obtained from G f by contracting every
edge in H. Each vertex of G f /H corresponds to either a component of the forest H
or an isolated vertex of G f that is not in H; every edge of G f /H corresponds to
an edge of G f whose reversal is not in G f .
I claim that G f contains a nontrivial simple cycle if and only if G f /H
contains a cycle. In particular, the cycle in G F /H could have length 1 (a self-
loop) or 2. See the figure below for an example.
5/5 5
10/20 5/15 10 5
0/15 10 10
15
s 5/10 0/10 t s 5 5 10 t
10
5/10 10/20 10
10
10/10 10
4
CS 473 Homework 7 Solutions Fall 2022
Rubric: 5 points = 2 points for “G f has no nontrivial simple cycles” + 2 points for algorithm
+ 1 for O(V E) running time. Proof of correctness is not required.
• Max 4 points for O(E 2 ) time.
• Max 10 points(!) for O(E) time.
• Only 1 point for “G f is a dag”.
5
CS 473 Homework 7 Solutions Fall 2022
2. Suppose you are given a flow network G with integer edge capacities and an integer
maximum flow f ∗ in G. Describe algorithms for the following operations. Both algorithms
should modify f ∗ so that it is still a maximum flow, but more quickly than recomputing a
maximum flow from scratch.
(a) Increment(e): Increase the capacity of edge e by 1 and update the maximum flow.
Rubric: 5 points = 4 for algorithm + 1 for time analysis. Proof of correctness is not required
for full credit. This is neither the only correct algorithm nor the only proof of correctness for
this algorithm.
6
CS 473 Homework 7 Solutions Fall 2022
(b) Decrement(e): Decrease the capacity of edge e by 1 and update the maximum flow.
7
CS 473 Homework 7 Solutions Fall 2022
Rubric: 5 points = 4 for algorithm + 1 for time analysis. Proof of correctness is not re-
quired for full credit. These are neither the only correct algorithms nor the only proofs of
correctness for these algorithms.
8
CS 473 Homework 7 Solutions Fall 2022
(a) Does every network G have at least one upper-binding edge? Prove your answer is
correct.
Solution: NO. Consider the following example. The unique maximum flow
saturates every edge; increasing the capacity of any single edge does not change
the unique maximum flow.
u
1 1
s t
2 2
v
Rubric: 2 points.
9
CS 473 Homework 7 Solutions Fall 2022
(b) Does every network G have at least one lower-binding edge? Prove your answer is
correct.
Solution: NO!
The following network does not contain a directed path from s to t, so
its maximum flow is zero everywhere. Maximum flow values are always non-
negative, so there’s no way to make this one smaller!
s
1 u
1 v
1 t
Rubric: 2 points.
Solution: YES!
Fix an arbitrary flow network G. Let (S, T ) be any minimum (s, t)-cut in G.
Let u v be any edge of G such that u ∈ S and v ∈ T . Decreasing c(u v) by 1
also decreases the capacity of the cut (S, T ) by 1, and therefore decreases the
minimum cut capacity by at least 1, and therefore decreases the maximum flow
value by at least 1. Thus, u v is lower-binding.
It remains only to prove that at least one edge crosses the cut in the correct
direction. Let’s make the reasonable assumption that the maximum flow
value in G is positive. There must be a directed path P from s to t in G. Let
u v be the last edge in P whose tail vertex u lies in S. We immediately have
v ̸∈ S and therefore v ∈ T , and we’re done. ■
Rubric: 2 points = 1 for showing every edge from S to T is lower-binding + 1 for proving
there is an edge from S to T . No penalty for implicitly assuming G carries non-zero flow.
10
CS 473 Homework 7 Solutions Fall 2022
(c) Describe an algorithm to find all upper-binding edges in G, given both G and a
maximum flow in G as input, in O(E) time.
Solution: Let f be the given maximum flow, and let G f denote its residual
graph.
Let S be the set of all vertices reachable from s in G f , and let T be the set of all
vertices that can reach t in G f . The subsets S and T must be disjoint. (However,
but (S, T ) is not necessarily a cut! There could be vertices that s cannot reach
and that cannot reach t.) An edge u v in G is upper-binding if and only if u ∈ S
and v ∈ T .
Let u v be any edge of G with u ∈ S and v ∈ T . The edge u v cannot be an
edge in the residual graph, because otherwise there would be a residual path
from s to v through u v. So we must have f (u v) = c(u v). However, if we
increase c(u v), the residual capacity c f (u v) becomes positive, so the edge
u v reappears in the residual graph. In the new residual graph, there is a path
from s to v through u v, and then from v to t (by definition of T ). Thus, f is
no longer a maximum flow.
On the other hand, suppose either u ̸∈ S or v ̸∈ T . If u v is not saturated,
then increasing its capacity does not change the residual graph G f , so there
is still no path in G f from s to t. If u v is saturated, then increasing c(u v)
adds u v to the residual graph G f . But if u ̸∈ S, the updated residual graph
has no edges leaving S, and if v ̸∈ T , the updated residual graph has no edges
entering T . In both cases, there is no path from s to t in G f + u v. In all cases
we conclude that f is still a maximum flow.
We can compute S in O(E) time using whatever-first search in G f , and we
can compute T in O(E) time using whatever-first search in the reversal of G f .
We can check the upper-binding conditions for any single edge in O(1) time.
Thus, the overall algorithm runs in O(E) time.
Rubric: 3 points = 2 for algorithm + 1 for running time. The proof of correctness is not
necessary for full credit.
11
CS 473 Homework 7 Solutions Fall 2022
(d) Describe an algorithm to find all lower-binding edges in G, given both G and a
maximum flow in G as input, in O(V E) time.
Solution: Let f be the given maximum flow. Our solution to problem 2(b)
implies that an edge u v in G is lower-binding if and only if there is no path
from u to v in the residual graph G f . In particular, f must saturate the edge
u v, which implies that u v has no residual capacity.
For each vertex u, we find all vertices reachable from u in G f in O(E) time
using whatever-first search; then we can find all lower-binding edges leaving u
in O(V ) time. The entire algorithm runs in O(V E) time.
Rubric: 3 points = 2 for algorithm + 1 for running time. The proof of correctness is not
necessary for full credit.
12