Algorithms and Data Structures Sample 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Submit Assignment For Help

Go To Code Directly
Massachusetts Institute
of Technology
info@programminghomeworkhelper.com Handout 7
6.854J/18.415J: Advanced Algorithms Friday, October 7, 2005
David Karger

Problem Set 5

Due: Wednesday, October 12 2005.

Problem 1. In class we proved a running time bound of O(m3/2 ) for finding a maximum
flow in a unit­capacity graph with m edges using blocking flows. We will prove some related
bounds.

(a) Consider an arbitrary unit­capacity graph, and let d be the distance between the

source and sink. Prove that the value of the maximum flow is at most n2 /d2 .

Conclude that O(n2/3 ) blocking flows in time O(mn2/3 ) suffice to find a maximum

flow. Hint: argue that there are two adjacent layers in the admissible graph with

few vertices in each. How much flow can cross between the two layers?)

(b) Consider a graph in which all edges are unit capacity, except for the edges incident

on p vertices which have arbitrary integer capacities. Extend the unit­capacity

flow bounds to give good bounds in terms of m, n, and p on the number of

blocking flows needed to find a maximum flow.

Problem 2. You are TAing a class with s students and r recitations. The students tell
you which recitations they can fit into their schedules. However, each recitation has room
for only k students. (Conversely, each student only has to attend one recitation.) Your goal
is to assign the most students to recitations within these constraints.

(a) Suppose√first that k = 1 (personal tutors!). How can you easily solve this problem

in O(m n) time?

(b) Now suppose k is arbitrary. How can you solve this problem with maximum

flow?


(c) Argue that an O(m n) time bound can be achieved for your network from part

(b), as in unit networks.

Problem 3. Consider a matrix of numeric data where each entry is fractional, but each
row and column sum is an integer. Prove that you can “round off ” this matrix, rounding
each entry to the next integer above or below, without changing the row or column sums.
Hint: the matrix can be thought of as describing (most of) a flow in a bipartite graph.
Recall that integer flow problems have integer solutions.

https://www.programminghomeworkhelper.com/
Massachusetts Institute of Technology Handout 12
6.854J/18.415J: Advanced Algorithms Wednesday, October 17, 2005
David Karger

Problem Set 5 Solutions

Problem 1. (a) Consider the admissible graph. Let Li denote the vertices located
in the layer i (with distance i from the source). We note that L0 = s and Ld = t.
Then we take the summation of number of elements in all pairs of layers

d
|Li | + |Li+1 | ≤ 2n .
i=1

We conclude the inequality because we count each layer at most twice. By pigeon-
holing, when we add d elements to get 2n, there must be at least one element
of value ≤ 2n/d. Thus, we conclude that |Li | + |Li+1 | ≤ 2n/d for some i, or
(|Li | + |Li+1 |)/2 ≤ n/d.
The number of edges between layers i and i + 1 is at most1
� �2 � �
|Li | + |Li+1 | n 2
|Li | |Li+1 | ≤ ≤ .
2 d

Since the full graph has no edges jumping layers that are in the admissible graph
(otherwise, the layers are incorrect in the admissible graph), we conclude that
the cut between layers Li and Li+1 has a capacity ≤ (n/d)2 , as each edge has
unit capacity. Thus, the max flow is at most (n/d)2 .
After k blocking flows, s and t are at a distance of k from eachother. The max
flow of the residual graph is (n/k)2 from above, thus we need to do at most (n/k)2
more blocking flows. Setting k = n2/3 , we get the total number of blocking flows
is O(k + (n/k)2 ) = O(n2/3 + (n/n2/3 )2 ) = O(n2/3 + (n1/3 )2 ) = O(n2/3 ).

Problem 2.
(a) We represent the problem as a bipartite graph G with vertex set Students ∪
Recitations and unit-capacity √
edges representing availability of students to attend
recitations. Now use the O(m n) bipartite matching algorithm to find a maximal
matching.
(b) We reduce the problem to a max flow as follows. Expand the graph G by adding
a sink s, a source t, unit-capacity edges from s to each student, and edges from
each recitation to t with capacity k. Any max flow in this graph gives an optimal
assignment of students to recitations.
1

First step of inequality follows from ab ≤ (a + b)/2, or geometric mean is at most arithmetic mean.
2 Handout 12: Problem Set 5 Solutions

(c) Suppose we remove  blocking flows, so that the distance between source and sink
is ≥ . Each path in the residual graph has length ≥  and thus passes through
≥ −1
2
students (since the path must alternate student, recitation, student, recita-
tion, etc., before reaching the sink). Therefore, there exist ≤ 2|# students|
−1
= O( n )
n
disjoint
√ paths from source√ to sink, so  additional blocking flows suffice. Setting
 = n, this gives O( n) total blocking flows.
Each blocking flow can be computed in O(m) time using the same advance-retreat
DFS algorithm as for unit capacity graphs. This is because the only non-unit
capacity edges are the edges from recitations to the sink, and we only advance
to the sink on the√last step of the blocking-flow algorithm. The overall running
time is thus O(m n).

Problem 3. Let A = (aij ) be an n × n matrix


with fractional entries such that all row and column sums are integral. Without loss of
generality, we assume that 0 ≤ aij < 1 for all i, j ∈ {1, ..., n}. (We can subtract aij  from
each aij , perform the procedure below, and add back the same amount afterwards.)
Consider the graph G with vertex set {s, t} ∪ {vij : i, j ∈ {1, ..., n}} ∪ {r1 , ..., rn } ∪ {c1 , ..., cn }
where the r’s and c’s represent the rows and columns of A, respectively. For all i, j ∈
{1, ..., n}, let there be edges:

• (s, ri) with capacity j � aij � ,

• (cj , t) with capacity i� ai� j ,
• (ri , vij ) and (cj , vij ) with capacity aij , i.e., 0 if aij = 0 and 1 otherwise.

Consider the s-t cut (S, T ) where S = {s}. Clearly the value of this cut is i,j aij . Now
consider the flow f where:

• f (s, ri) = j � aij � ,

• f (cj , t) = i� ai� j ,
• f (ri, vij ) = f (vij , cj ) = aij .

f has value i,j aij , the same as the min cut. Therefore, f is a max flow.
Note that G has integral capacities, so G has an integral max flow g. Let B = (bij ) be the
n × n matrix where bij = g(ri, vij ). B is the desired integral matrix.

You might also like