0% found this document useful (0 votes)
169 views12 pages

f22 hw7 Sol

This document contains solutions to homework problems about maximum flow algorithms. 1. It provides a 3-step algorithm to verify if a given flow f is a maximum (s,t)-flow in graph G in O(E) time: check conservation at non-terminal nodes, non-negativity, and capacity constraints on each edge and check for residual paths from s to t. 2. It describes an O(E^2) algorithm and a faster O(V*E) algorithm to determine if f is the unique maximum flow by checking for cycles of length 3 or more in the residual graph Gf. 3. It notes that detecting cycles can actually be done in optimal O(E)

Uploaded by

Peter Rosenberg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views12 pages

f22 hw7 Sol

This document contains solutions to homework problems about maximum flow algorithms. 1. It provides a 3-step algorithm to verify if a given flow f is a maximum (s,t)-flow in graph G in O(E) time: check conservation at non-terminal nodes, non-negativity, and capacity constraints on each edge and check for residual paths from s to t. 2. It describes an O(E^2) algorithm and a faster O(V*E) algorithm to determine if f is the unique maximum flow by checking for cycles of length 3 or more in the residual graph Gf. 3. It notes that detecting cycles can actually be done in optimal O(E)

Uploaded by

Peter Rosenberg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CS 473 Homework 7 Solutions Fall 2022

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 .

(a) Describe and analyze an efficient algorithm to determine whether f is a maximum


(s, t)-flow in G.

Solution: Verifying that f is a maximum flow requires three steps:


• Check that u f (u v) = w f (v w) for every node v except s and t.
P P

• Check that f (u v) ≥ 0 for every edge u v.


• Check that f (u v) ≤ c(u v) for every edge u v.
• Check that there is no path from s to t in the residual graph G f .
The first three steps can be done in O(E) time by brute force. In the last step, we
need O(E) time to build G f , plus O(E) time to perform a whatever-first search
starting at s. Thus, the overall algorithm runs in O(E) time. ■

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.

We do need to explicitly rule out cycles of length 2, which correspond to an


edges of G that the maximum flow neither saturates nor avoids. The following
figure shows a minimal example of a unique maximum flow (on the left) and
whose residual network (on the right) contains a cycle of length 2.

1/1 1/2 1 1
s t s t
1

We prove our claim as follows:


• Suppose G f contains a simple directed cycle C = v0  v1  · · ·  vℓ−1  v0 of
length ℓ ≥ 3. By definition of “simple”, all ℓ vertices vi are distinct. In
particular, if C contains the edge u v, it does not contain the reversed edge
v u. Let cmin = mine∈C c f (e) be the minimum residual capacity of any edge
in C. Then we can define a new flow f ′ by pushing (up to) cmin additional
units of flow along C, as follows:

 f (x  y) + cmin if x  y ∈ C


f (x  y) = f (x  y) − cmin if y  x ∈ C
 f (x  y)

otherwise

1
CS 473 Homework 7 Solutions Fall 2022

These cases are exclusive because C is simple. Straightforward definition


chasing implies that f ′ is a feasible flow with the same value as f , and
therefore is another maximum flow.
• Suppose there is another maximum (s, t)-flow f ′ ; by definition we have
| f | = | f ′ |. We define a flow g = f ′ − f in the residual graph G f as follows.

′ ′
 f (u v) − f (u v) if f (u v) > f (u v)

g(u v) = f (v u) − f ′ (v u) if f ′ (v u) < f (v u)

0 otherwise

See the example below.


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
5/5 0/5

8/20 11/15 0/10 0/5

2/10 0/15 6/10


0/15
s 3/10 6/10 t s 0/5 2/5 6/10 t
6/10
7/10 4/20 2/10
0/10

10/10 0/10

Top left: A maximum flow f . Top right: The residual graph G f .


Bottom left: Another maximum flow f ′ . Bottom right: The circulation g = f ′ − f .
Straightforward definition-chasing implies that g is a feasible flow with
value 0 in the residual graph G f . Thus, by the flow decomposition theorem,
we can write g as a weighted sum of cycles, each containing only edges
where g is positive. None of these cycles use both an edge u v and its
reversal v u, so every cycle has length at least 3.

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.〉〉

However, there is a faster algorithm that detects nontrivial cycles in O(V E)


time. We construct a new directed graph H whose vertices are the directed edges
of G f , and whose edges correspond to a pairs of edges in G f that can appear
consecutively in a simple path. That is, H contains the edge (u v)(v w) if
and only if u v w is a simple directed path in G f (and in particular u ̸= w).
Overall, the graph H contains V ′ = E vertices and E ′ ≤ V E edges, and we can
construct it in O(V E) time by brute force.
Every closed walk of length ℓ in H corresponds to a closed walk of length ℓ
in G f that does not contain a spur of the form u v u, and vice versa. In

2
CS 473 Homework 7 Solutions Fall 2022

particular, G f contains a simple cycle of length at least 3 if and only if H contains


a directed cycle. Equivalently, f is the unique maximum flow if and only if H
is a dag. We can check the latter condition in O(V ′ + E ′ ) = O(V E) time using
depth-first search. 〈〈This is worth 5 points.〉〉 ■

Solution (+5 extra credit): In fact, it is possible to detect nontrivial simple


cycles in O(E) time. The following algorithm is (morally) due to Donald Johnson
in 1975.
First, we compute the strong components of the residual graph G f , using (for
example) Tarjan’s algorithm or Kosaraju and Sharir’s algorithm. Recall that a
graph H is strongly connected if every vertex in H can reach every other vertex
in H; a strong component of G f is a maximal strongly connected subgraph. Each
edge of G f belongs to at most one strong component. Each simple cycle in G f
lies entirely inside one strong component, so the rest of our algorithm can search
each strong component separately.
Second, we further subdivide the strong components into biconnected com-
ponents at cut vertices. A cut vertex is any vertex v whose deletion disconnects
the graph; a graph H ′ is (strongly) biconnected if it is (strongly) connected and
has no cut vertices; the biconnected components of a graph H are its maximal
biconnected subgraphs. An algorithm of Hopcroft and Tarjan (similar to Tarjan’s
strong-component algorithm) decomposes any (strongly) connected graph into
(strongly) biconnected components in O(E) time. Each nontrivial simple cycle
in G f lies entirely inside one strongly biconnected component, so the rest of our
algorithm can search each strongly biconnected component separately.
Finally, let H be any strongly biconnected component of G f . I claim that
H contains a nontrivial simple cycle if and only if H has at least three
vertices. One direction is trivial—if H has less than three vertices, it cannot
contain a cycle with at least three vertices—so let’s prove the other. If H has
only one or two vertices, the claim is trivial, so assume otherwise. There are two
cases to consider.
• Suppose H contains an edge x  y but not its reversal y  x. Because H is
strongly connected, H contains a simple directed path from y to x, which
must have length at least 2. Adding the edge x  y to the path gives us a
simple cycle of length at least 3.
• On the other hand, suppose H is symmetric. Fix an arbitrary edge x  y.
Because H is biconnected and has at least three vertices, H contains at least
two vertex-disjoint paths from y to x; one of these paths is not just the edge
y  x. Adding the edge x  y to that path gives us a simple cycle of length at
least 3.
So the final algorithm looks like this:

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

The entire algorithm runs in O(E) time. 〈〈This is worth 10 points.〉〉 ■

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

Top left: A maximum flow f . Top right: The residual graph G f .


Bottom left: The subgraph H . Bottom right: The contracted graph G f /H .

As usual we prove this claim in two parts.


⇒ Suppose G f contains a simple cycle C = v1  v2  · · ·  vℓ  v1 , where ℓ ≥ 3.
If any edge vi  vi+1 of C lies in H with its reversal vi+1  vi , contracting that
edge turns C into a shorter simple cycle. Contracting a symmetric edge
pair vi  v j between two non-adjacent vertices turns C into a figure-8: two
simple cycles sharing a single vertex. In both cases, the induction hypothesis
implies that contracting the remaining edges of H leaves a multigraph with
at least one cycle.

4
CS 473 Homework 7 Solutions Fall 2022

⇐ Suppose G f /H contains a simple cycle C, possibly of length 1 or 2. Each edge


of C corresponds to an edge in G f . Let u0  v1 , u1  v2 , . . . , uk  v0 denote the
edges of G f corresponding to the edges of C in order. For each index i,
vertices ui and vi lie in the same component of H, and thus are connected by
a unique path in H. Because C is a simple cycle, it touches each component
of H at most once, so the various paths in H are disjoint. We conclude
that connecting the edges ui−1  vi with the paths vi ⇝ui through H yields a
simple cycle in G f that never uses both an edge and its reversal.
We can construct G f /H in O(E) time by brute force, and then we can determine
whether G f /H is a directed acyclic graph in O(E) time using (for example)
depth-first search. The overall algorithm runs in O(E) time. 〈〈This is worth 10
points.〉〉 ■

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.

Solution: To Increment the edge e, we first increase the capacity c(e) by 1,


and then perform one iteration of the Ford-Fulkerson augmenting path algorithm:
Build the residual graph G f ∗ , look for a path from s to t in G f ∗ , and if such a
path is found, push 1 unit of flow along it.
We can prove the algorithm correct as follows. Let (S, T ) be any minimum
(s, t)-cut in G, with respect to the original capacities. Increasing c(e) by 1 also
increases the capacity of (S, T ) by at most 1. The easy half of the maxflow-mincut
theorem implies that new maximum flow value is at most the new capacity of
(S, T ). Thus, incrementing c(e) increases the value of the maximum flow in G
by at most 1. Because all residual capacities are integers, it follows that a single
iteration of Ford-Fulkerson in the residual graph finds the new maximum flow.
The algorithm runs in O(E) time. ■

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.

Solution: Suppose we are asked to Decrement the edge u v. We must have


c(u v) > 0, since otherwise, decreasing c(u v) is impossible. Similarly, we can
assume f ∗ (u v) = c(u v), since otherwise, we can decrease c(u v) by 1 and
return immediately.
First, we send one unit of flow backward through u v, either along a path
from t to s or along a cycle in in the residual graph G f ∗ . Temporarily add an
edge s t to the residual graph G f ∗ , find a path from u to v in this new larger
graph, push one unit of flow along the corresponding edges of G, and finally
decrease f (u v) by 1.
Now we decrease c(u v) by 1. The current flow f is still feasible, but it may
not be a maximum flow. To restore a maximum flow, we run one iteration of
Ford-Fulkerson, to push at most one more unit of flow from s to t.
To show that this algorithm is correct, we need two prove two claims:
• There is a path from u to v in the residual graph plus s  t . Temporarily
add an edge t s to G with f ∗ (t s) = | f ∗ |. Now follow one unit of flow out
of v through an arbitrary sequence of directed edges in G + t s, traversing
each edge e at most f ∗ (e) times. Because flow is conserved at every vertex
(including s and t), this walk must eventually reach u. Reversing this walk
gives us a walk in the residual graph from u to v. Any walk from u to v
contains a path from u to v. (In fact, we can just use the walk directly.)
• Decrementing c(u  v ) decreases the maximum flow value by at most 1.
We can follow the proof from part (a). If u v crosses some minimum cut,
then decrementing c(u v) decreases the capacity of the minimum cut by 1,
and therefore decreases the value of the maximum flow by 1. Otherwise,
the minimum cut capacity does not change, so the maximum flow value also
does not change.
The algorithm runs in O(E) time. ■

Solution: Suppose we are asked to Decrement the edge u v. We must have


c(u v) > 0, since otherwise, decreasing c(u v) is impossible. Similarly, we can
assume f ∗ (u v) = c(u v), since otherwise, we can decrease c(u v) by 1 and
return immediately.
First we attempt to reroute one unit of flow through u v to another path
from u to v. We search for a path from u to v in the residual graph G f ∗ using
whatever-first search in O(E) time. If there is such a path P, we decrease f (u v)
by 1, push one unit of flow along P, and return the resulting flow. Because the
new flow has the same value as f ∗ , it is also a maximum flow.
If there is no path from u to v in G f ∗ , decreasing c(u v) must reduce the
value of the maximum flow. We temporarily add an edge t s, find a path P
from v to u in the augmented residual graph G f ∗ + t s using whatever-first
search, decrease f (u v) by 1, push one unit of flow along P, remove the edge
t s, and return the resulting flow.
We can prove that there is a path from u to v in the augmented residual graph

7
CS 473 Homework 7 Solutions Fall 2022

as follows. Because f ∗ saturates u v, any flow decomposition of f ∗ contains a


path Q from s to t through u v; the reversal of Q must be a directed path in
the residual graph. So rev(Q) + t s must be a cycle in the augmented residual
graph G f ∗ + t s. So rev(Q) + t s − v u is a path from u to v in the augmented
residual graph.
The entire algorithm runs in O(E) time. ■

Solution: Suppose we are asked to Decrement the edge x  y. We must have


c(x  y) > 0, since otherwise, decreasing c(x  y) is impossible. Similarly, we
can assume f ∗ (x  y) = c(x  y), since otherwise, we can decrease c(x  y) by 1
and return immediately.
First we attempt to reroute one unit of flow through x  y to another path
from x to y. We search for a path from x to y in the residual graph G f ∗ using
whatever-first search in O(E) time. If there is such a path P, we decrease f (x  y)
by 1, push one unit of flow along P, and return the resulting flow. Because the
new flow has the same value as f ∗ , it is also a maximum flow.
If there is no path from x to y in G f ∗ , decreasing c(x  y) must reduce the
value of the maximum flow. We find a path P from t to y and a path Q from x
to s in G f ∗ , using whatever first search. Finally, we then push one unit of flow
along the residual path P · ( y  x) · Q.
To prove that this algorithm works, we need to show that P and Q are edge-
disjoint. (Otherwise, we would push two units of flow through a common edge,
but the capacity of that edge might be 1.) Let X be the subset of vertices that x
can reach in G f ∗ , and let Y be the subset of vertices that can reach y in G f ∗ . The
subsets X and Y must be disjoint. Every path from t to y visits vertices only in Y ,
and every path from x to s visits vertices only in X . We conclude that paths P
and Q have no vertices in common, and therefore no edges in common.
The entire algorithm runs in O(E) time. ■

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

3. Let G be a flow network with integer edge capacities. An edge in G is upper-binding if


increasing its capacity by 1 also increases the value of the maximum flow in G. Similarly,
an edge is lower-binding if decreasing its capacity by 1 also decreases the value of the
maximum flow in G.

(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.

〈〈Find all upper-binding edges in G given a maximum flow f 〉〉


UpperBinding(G, f ):
UB ← ∅
build the residual graph G f
S ← vertices reachable from s in G f 〈〈O(E) via WFS〉〉
T ← vertices reachable from t in rev(G f ) 〈〈O(E) via WFS〉〉
for every edge u v in G
if u ∈ S and v ∈ T
add u v to U B
return U B

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.

〈〈Find all lower-binding edges in G given a maximum flow f 〉〉


LowerBinding(G, f ):
LB ← ∅
build the residual graph G f
for every vertex u
unmark every vertex in G f 〈〈O(V )〉〉
mark vertices reachable from u in G f 〈〈O(E) via WFS〉〉
for every edge u v in G
if v is marked
add u v to LB
return LB

Rubric: 3 points = 2 for algorithm + 1 for running time. The proof of correctness is not
necessary for full credit.

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy