Solutions - People.csail.mit.edu

6.854 — Advanced Algorithms
Homework 4 Solutions
1
Prove, or Disprove?
(a) False: consider vertices v and w having an edge from v to w and another from w to v.
Given a flow f defined on these edges, we can increment both f ((v, w)) and f ((w, v))
by ∆ to get another valid flow. (In the net flow model, note f ((v, w)) = −f ((w, v)), so
falseness is obvious.)
(b) True: consider any pair (v, w) with both f (v, w) and f (w, v) positive. Assume without
loss of generality that f (v, w) ≤ f (w, v). Decrease both quantities by f (v, w). One is
now zero, but flow conservation and capacity bounds have been maintained.
(c) False. Consider the graph with V = {s, 1, 2, 3, t} and E = {(s, 1), (s, 2), (1, 3), (2, 3), (3, t)}.
The capacities are u(s, 1) = 2, u(s, 2) = 3, u(1, 3) = 4, u(2, 3) = 5, and u(3, t) = 1. Essentially, the edge (3, t) is a bottleneck, but you can choose whether to go through node
1 or node 2 to get the maximum flow. Thus there is no unique maximum flow even
though all directed edges have distinct capacities.
(d) False. Consider graph with V = {s, t} and E = {(t, s)}, the edge having a capacity of
1. Then, the initial graph has a max flow of 0, while the modified graph has a max flow
of 1.
(e) False. Consider graph with
V = {s, 1, 2, 3, t},
and
E = {(s, 1), (1, 2), (1, 3), (2, t), (3, t)}.
The capacities are u(s, 1) = 3, u(1, 2) = 1, u(1, 3) = 1, u(2, t) = 1, u(3, t) = 1. For this
graph a min cut is S = {s, 1}. However, if we add a value of λ = 100 to the capacity of
each edge, then the min cut becomes S = {s}
(f) True. Suppose there was no flow of value v from s to u. Then there exists an s − u cut
s ∈ S, u ∈ S̄ such that u(S, S̄) < v. Then either t ∈ S or t ∈ S̄. If t ∈ S, then there is
a cut between t and u that is less than v and there is no flow between t and u of value
1
v. If t ∈ S̄, then there is no flow between s and t of value v. In either of these cases, we
reach a contradiction, so flow must be transitive.
2
2
Dynamic Max Flow Problem
As stated in the problem, all edge capacities are integral.
(a) The key thing to note is that the value of the new maximum flow is either the value of
the old maximum flow, or incremented by one. This is true because the value of any
minimum cut can only increase by one, so that the value of the maximum flow increases
by at most one. We assume that the flow we are given is integral on all edges.
This motivates the following algorithm: increase the capacity of the edge, and look at
the new residual graph Gf . Attempt to find an augmenting path in Gf . If one exists,
augment along that path. Since the capacities are integral, the flow will be augmented
by one, and by the above observation, we have the maximum flow.
(b) Similarly, after decreasing the capacity along an edge, the capacity of any cut can go
down by at most one. Therefore, the value of the maximum flow can decrease by at
most one.
Suppose the edge whose capacity we decrement is (v, w). Given the old flow f , first
decrease the flow going across the edge by 1. Then find a shortest path from v to s that
has positive flow on it; this can be done in O(m) time. Decrease the flow on that path
by 1. Then find a shortest path from w to t, and similarly decrease the flow on that
path by 1. Now we have a valid flow f 0 of value one less than before. Now try to find
an augmenting path in the residual graph. If it exists, we augment along it by at most
1 and we have the maximum flow. If it does not, then f 0 is the maximum flow.
3
3
Critical Edges for Max Flow
(a) Not every network has an upward-critical edge. Consider the network G = ({s, v, t}, {(s, v), (v, t)}),
with the capacity of (s, v) and (v, t) equal to 1. Increasing the capacity of either edge
does not increase the maximum flow.
To find all the upward-critical edges in a network, consider the following algorithm:
• Compute a max flow f in the network
• Let U be the set of all vertices reachable from s in the residual graph Gf . (We can
find such vertices using DFS)
• Let V be the set of all vertices that can reach t in Gf
• Any edge (u, v) such that u ∈ U and v ∈ V is an upward-critical edge.
This algorithm is correct because increasing the capacity of any edge (u, v), s.t. u ∈
U, v ∈ V results in an augmenting path, so it is upward-critical. Furthermore, every
upward-critical edge has this property, so the set of edges found by the algorithm is
equal to the set of upward-critical edges. The running time of the post-process procedure
consists of two runs of BFS (O(m + n)) and naive membership check which takes O(n2 ).
(b) The set of downward-critical edges is not the same as the set of upward-critical edges.
In the example in part (a), each of the edges is downward-critical, whereas none are
upward-critical.
To compute the set of downward-critical edges, consider the following lemma.
Lemma 1. Let f be a max-flow for G, and let (u, v) be any edge in G. Consider the
residual network Gf . Then the set of edges (u, v) such that there is no path from u to v
in Gf is exactly the set of downward-critical edges.
Proof. If there is no path from u to v, then the edge (u, v) is saturated. Therefore,
f ((u, v)) = c((u, v)). Say we decrement the capacity by δ. Then if we are to keep the
max flow at its current value, the δ units of flow over capacity must be rerouted. But
note that we cannot reroute the flow because there is no path from u to v. Therefore,
(u, v) is a downward-critical edge.
Now suppose there is a path from u to v, with minimum capacity δ. If we increase the
capacity of (u, v) by δ, we can reroute the flow through the path from u to v, so that
the max-flow would remain the same. So (u, v) is not a downward-critical edge.
The algorithm then is to compute all pairs (u, v) such that (u, v) is an edge in the
graph, but there is no path from u to v in the residual graph Gf . This can be done by
first finding strongly connected components of Gf and then the DAG representation of
components (O(m + n)). Let Df denote the DAG of SSC of Gf .
4
Then, we perform topological sort on Df to get Tf . Starting from root of Tf (if there
are multiple roots, we process them separately one by one), for each (super)node v we
maintain the set of vertices u s.t v is reachable from u (O(m + n)). Once we have this
information for all nodes reachability matrix can be made in O(n2 ).
5
4
Lunchtime
(a) We give an algorithm to decide if all people can be moved out in t steps. Now, we can
increment t to find the shortest time in which all the people can move out.
The algorithm is as follows: given G, construct Gt as follows. For each v ∈ V , make t
copies of v: v1 . . . vt . Construct an edge from vi to vi+1 at time t with infinite capacity
(people can just stay in rooms at a time step). Construct an edge from vi to wi+1 with
capacity C if there exists an edge from v to w with capacity C in G. The number of
vertices and edges in Gi are respectively O(nt) and O(nt + m).
To test if all the people can get from the source to the sink in t timesteps, we check if
the max flow in Gt is equal to the number of people initially at the source. If so, we can
move all the people across this graph in t timesteps.
Lets P be the total number of people. Then the size of the graph is polynomially large
in terms of n, m, P , so the algorithm runs in pseudo-polynomial time.
(b) We can use the same overall idea: construct a graph Gt , and compute its max flow. If
its max flow is equal to the total number of people we are trying to move, then t time
units suffice to move all the people across the graph.
The construction of Gt is the same, except for the following. We create a sink s and
source t. Let S be the start vertices, and let T be the sink vertices. We create a link
from s to each x1 , for each x ∈ S with capacity equal to the number of people starting at
x. Similarly, we create a link from each xt (for each x ∈ T ) to t with infinite capacities.
(c) Again, the overall idea is the same. But when we construct Gt now, we create edges
between the layers in a different way: construct the edge linking vi to wi+δ with capacity
C if there is an edge between v and w with transit time δ. Note that here the upper
bound on the required amount of time so that all people can leave the building is P δmax .
6
5
Capacity Scaling Variant
Lemma 2. Scaling-Max-Flow-II(G) returns the max-flow of G.
Proof. Once D = 1, since GD = G by performing Ford-Fulkerson(G1 , f ), the flow returned
by the procedure is the max-flow.
Lemma 3. When the while loop terminates for some fixed D, |f ∗ | ≤ |f | + Dm.
Proof. We show that the size of min cut in the residual graph of G(fD ) is bounded by Dm.
This implies that the amount of max-flow in G(fD ) is at most Dm; thus, |f ∗ | − |f | ≤ Dm.
Consider a min-cut C in the residual graph, G(fD ). Since C is a min-cut of G(fD ), no
edge e crossing C has capacity greater than or equal to D. Thus, the total capacity of C is
bounded by Dm.
Lemma 3 implies that once we start the while loop with D/2, the difference between f ∗
and current flow is mD. Since the capacity of each edge in GD/2 is a multiple of D/2, at
most O(m) augmenting path procedure will be called by Ford-Fulkerson algorithm. Each
augmenting path procedure can be implemented by invoking shortest-path algorithm which
runs in O(m + n). Hence the total runtime is O(m2 (1 + log U )).
7