0% found this document useful (0 votes)
109 views

CS60007 Algorithm Design and Analysis 2018 Assignment 2: General Instructions

This document provides instructions for an assignment on algorithm design and analysis due on September 4, 2018. It includes 4 problems to solve: problems 1, 5, 6, and 20. General instructions are provided regarding proving correctness, computing runtime, and graph assumptions. Notation used in the problems is also defined. The document is preliminary and may contain errors, so students are asked to report any errors found.
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)
109 views

CS60007 Algorithm Design and Analysis 2018 Assignment 2: General Instructions

This document provides instructions for an assignment on algorithm design and analysis due on September 4, 2018. It includes 4 problems to solve: problems 1, 5, 6, and 20. General instructions are provided regarding proving correctness, computing runtime, and graph assumptions. Notation used in the problems is also defined. The document is preliminary and may contain errors, so students are asked to report any errors found.
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/ 8

CS60007 Algorithm Design and Analysis 2018

Assignment 2
Palash Dey and Swagato Sanyal
Indian Institute of Technology, Kharagpur

Please submit the solutions of problem 1, 5, 6, and 20. The deadline is September
4, 2018 in the class.

General Instructions
B Please prove correctness of every algorithm you design.

B Please compute running time of every algorithm you design.

B If not explicitly specified otherwise, please assume that the graphs under considera-
tion are finite, weighted, and directed graphs which does not contain any self loop.

Notation
B N = {0, 1, 2, 3, ...} is the set of natural numbers. R is the set of real numbers.

B For n ∈ N, [n] = {i ∈ N : 1 6 i 6 n}.

B For a, b ∈ R with a < b, we define [a, b] = {x ∈ R : a 6 x 6 b}, [a, b) = {x ∈ R : a 6


x < b}, (a, b] = {x ∈ R : a < x 6 b}, (a, b) = {x ∈ R : a < x < b}.

This is a preliminary version and may contain errors. Please send an email to the
instructors if you find any error. Thank you for your cooperation.

1
1. [10 Marks] Let G be a different kind of graph where we have weights on vertices
instead of weights on edges. Let us define the weight of a path to be the sum of
the weights of the vertices on the path. Can there exist any algorithm for the sin-
gle source shortest path problem in this graph? If there exists any such algorithm,
describe it. Otherwise prove why there cannot be any such algorithm.

Proof. The following algorithm solves this problem. Let G be any input graph with
weight function w : V[G] −→ R. We construct a weighted graph H from G as follows:

V[H] = {`u , ru : u ∈ V[G]}


E[H] = {(ru , `v ) : (u, v) ∈ E[G]}
= {(`u , ru ) : u ∈ V[G]}

w(v) if e = (`u , ru ) ∈ E[H] for some u ∈ V[G]
w0 (e) =
0 otherwise

We now claim that for any two vertices u, v ∈ V[G], there is a path from u to v in G
of weight λ if and only if there is a path from `u to rv in H of weight λ. To prove the
claim, in one direction, let us Ptassume that there is a path u0 (= u), u1 , . . . , ut (= v)
from u to v in G of weight i=0 w(ui ). P Then the path `u0 , ru0 , `u1 , ru1 , . . . , `ut , rut
is a path from `u to rv in H of weight ti=0 w(ui ). In the other direction, let there
be a path u0 (= `u ), u1 , . . . , ut (= rv ) from `u to rv in H. Since the only outgoing
edge on any vertex `x , x ∈ V[G], is to rx and the only incoming edge on any vertex
ry , y ∈ V[G], is from `y , we conclude that t is an even integer and for every j ∈ [t/2]
we have u2j−1 = `zj and u2j = rzj for some zj ∈ V[G]. Hence, there is a path
Pt/2 Pt/2
z1 (= u), z2 , . . . , zt/2 (= v) from u to v in G of weight i=1 w(zi ) = i=1 w0 (`zi , rzi )
which proves the claim. Hence our problem reduces to the shortest path problem
and thus can be solved in polynomial time.

2. Design an algorithm to find, for all pairs of vertices u and v, the number of paths
from u to v.
3. Reduce the following generalization of the maximum flow problem to the basic max-
imum flow problem.
(a) (Vertex capacities) In this generalization, every vertex v also have a capac-
ity c(v). A feasible flow in this setting is a flow which satisfies the following
constraint (which says that flow into any vertex can be at most its capacity) in
addition to non-negativity, capacity, and conservation constraints:
X
f(u, v) 6 c(v) for every vertex v
(u,v)∈E

The problem is to find a maximum flow in this setting.

2
(b) (Multiple source-sink pairs) In this generalization, we are given multiple
source-sink pairs (s1 , t1 ), (s2 , t2 ), . . . , (sk , tk ) for some positive integer k. Ev-
erything remains same from the basic flow problem except we now do not want
flow conservation property to hold at any vertex in {si , ti : i ∈ [k]}. The problem
is to find a maximum flow in this setting.
(c) (Demands on edges) In this generalization, we are also given a demand d(e)
for every edge e. A feasible flow in this setting is a flow which satisfies the
following constraint (which says that flow in any edge is at least its demand) in
addition to non-negativity, capacity, and conservation constraints:

f(e) > d(e) for every edge e

The problem is to find if there exists a feasible flow in this setting.


(d) (Supplies and demands on nodes) In this generalization, we are also given a
demand d(v) for every vertex v. A feasible flow in this setting is a flow which
satisfies the following constraint in addition to non-negativity and capacity:
X X
f(u, v) − f(v, w) = c(v) for every vertex v
(u,v)∈E (v,w)∈E

The problem is to find if there exists a feasible flow in this setting.

4. Consider the following problem. You are given a flow network with unit-capacity
edges: It consists of a directed graph G = (V, E), a source s ∈ V, and a sink t ∈ V;
and ce = 1 for every e ∈ E. You are also given a parameter k. The goal is to delete k
edges so as to reduce the maximum s − t flow in G by as much as possible. In other
words, you should find a set of edges F ⊂ E so that |F| = k and the maximum s − t
flow in G = (V, E \ F) is as small as possible subject to this. Give a polynomial-time
algorithm to solve this problem. This problem is taken from [KT06].

5. [15 Marks] Prove using flows that the maximum number of edge disjoint s − t paths
in an unweighted graph G is the same as the size of minimum s − t cut. This is known
as Menger’s Theorem.

Proof. Let G = (V, E) with s, t ∈ V be any unweighted graph and (U, V \ U) for some
U ⊂ V with U 6= ∅ and U 6= V be a minimum s − t cut in G. Any edge (u, v) ∈ E with
u ∈ U and v ∈ V \ U is called a (U, V \ U)-cut edge. Let P be any set of edge disjoint
s − t paths in G. We observe that any path in P can use at most one (U, V \ U)-cut
edge. Since P is any set of edge disjoint s − t paths in G, the maximum number of
edge disjoint s − t paths in G is at most the size of minimum s − t cut.
To prove the other inequality, we construct the following flow network H =
(V, E, s, t, c) : V[H] = V[G], E[H] = E[G], c(e) = 1 for every e ∈ E[H]. Since all
the capacities in H are integers (they are actually 1), there exists a maximum s − t

3
flow f which assigns integer flow values to every edge. However, since c(e) = 1
for every e ∈ E[H], we have f(e) = 0 or f(e) = 1 for every e ∈ E[H]. Using flow
decomposition theorem, there exists a collection Q of edge disjoint s − t paths in G
with |Q| = val(f) = size of minimum s − t cut. Hence, the maximum number of edge
disjoint s − t paths in G is at least the size of minimum s − t cut which proves the
statement.

6. [10+2 Marks] Prove that the number of minimum cuts in an n vertex graph is at
most n2 . Given an example of a graph where the number of minimum cuts is n2 .


 graph G, let the minimum cuts be Ui ⊂ V[G], i ∈ [`]. We need to prove


Proof. For any
that ` 6 2 . Let us denote the event that the Karger’s algorithm outputs Ui by Ei for
n

i ∈ [`]. From the analysis of Karger’s algorithm, we know the following.


h i 2
Pr Ei >
n(n − 1)

We now observe that the events Ei , i ∈ [`] are mutually exclusive. Hence, we have
the following.
h [ i 2`
Pr Ei =
n(n − 1)
i∈[`]

n

Since probability of any event is at most 1, we have ` 6 2
.

7. Let G be an undirected and weighted graph. For any two vertices u, v ∈ V with u 6= v,
a pair (A, V \ A) is called a u − v cut if u ∈ A and v ∈
/ A. The capacity of (A, V \ A) is
the number of edges in G with one end point in A and other end point not in A. Let
us denote the capacity of a minimum u − v cut by f(u, v). Then prove the following:

(a) For every u, v, w ∈ V, we have

f(u, v) > min{f(u, w), f(w, v)}

(b) For every u, v, w1 , w2 , . . . , wr ∈ V, we have

f(u, v) > min{f(u, w1 ), f(w1 , w2 ), f(w2 , w3 ), . . . , f(wr , v)}

8. Give an algorithm to find the number of vertex disjoint paths in a directed graph
between two given nodes.

9. Prove or disprove the following statements:

4
(a) If all capacities are even integers then there exists a maximum s − t flow f such
that f(e) is even for every e ∈ E.
(b) If all capacities are odd integers then there exists a maximum s − t flow f such
that f(e) is odd for every e ∈ E.

10. Let G be a graph with integral capacities. Let f be a maximum flow in G and e be any
edge in G.

(a) We increase the capacity of e by 1. Let the resulting graph be H1 .


(b) We decrease the capacity of e by 1. Let the resulting graph be H2 .

Design a O(m + n) algorithm to compute a maximum flow in H1 and H2 .

11. Prove or disprove the following statement: if the capacities of all the edges are ratio-
nal numbers in a graph, then Ford-Fulkerson algorithm terminates.

12. Construct graphs with following properties:

(a) Exponentially (as function of n) many minimum cuts and a unique maximum
flow.
(b) Many maximum flows and a unique minimum cut.
(c) Many maximum flows and many minimum cuts.

13. Prove or disprove the following statement: Let (A, V \ A) be a minimum s − t cut in a
graph G. We now increase the capacity of every edge in G by 1. The resulting graph
be H. Then (A, V \ A) is a minimum s − t cut in H too.

14. König’s Theorem states that the size of maximum matching in a bipartite graph is
the same as the size of a minimum vertex cover. Prove König’s Theorem using flow
arguments.

15. Give an example of a network where Ford-Fulkerson algorithm does not even con-
verge to some maximum flow.

16. (Flow Decomposition) Let f be a flow in a graph G. Then prove that there exists
feasible flows f1 , f2 , . . . , fk and s−t paths p1 , p2 , . . . , pk with the following properties:

(a) k 6 m
Pk
(b) val(f) = i=1 val(fi )
(c) For every i ∈ [k], e ∈ E[G], fi (e) > 0 if and only if e belongs to pi

Design an efficient algorithm to find a flow decomposition of a given flow.

5
17. Recall the linear time algorithm for finding any order statistic done in the lecture.
Remember that to compute the median we partitioned the inputs into blocks of size
5? Is the choice of 5 important? What is the complexity when the block size is chosen
to be (a)3, (b)7? If you claim that the complexity is super-linear for a particular
choice of block size, argue that there exists an input that forces the algorithm to run
in super-linear time.

18. Suppose that an algorithm uses only comparisons to find the i-th smallest element
in a set of n elements. Show that it can also find the i − 1 smaller elements and the
n − i larger elements without performing any additional comparisons.

19. Describe an O(n)-time algorithm that, given a set S of n distinct numbers and a
positive integer k 6 n, determines the k numbers in S that are closest to the median
of S.

20. You are given as input n distinct numbers x1 , . . . , xn and their respective weights
w1 , . . . , wn . The weights are positive real numbers and they add up to 1, i.e.,
P n
i=1 wi = 1. The weighted lower median (wlm) is defined to be xk where
k ∈ {1, . . . , n} is the unique index that satisfies
P 1
(a) xi <xk wi < 2 , and
P 1
(b) xi >xk wi 6 2 .

(i) [3 marks] prove that wlm is well-defined, i.e., for each input x1 , . . . , xn and
w1 , . . . , wn there is a unique k for which the above two conditions (a) and (b)
are satisfied.
(ii) [5 marks] Give an algorithm that computes wlm using sorting and runs in worst-
case O(n log n) time.
(iii) [7 marks] Suppose you are given access to an algorithm MEDIAN that takes
in n distinct numbers x1 , . . . , xn , computes their (lower) median, and runs in
O(n) time (we have seen such an algorithm in the lecture). Using MEDIAN as
a black-box 1 design an algorithm that computes wlm and runs in worst-case
O(n) time.

Solution:

(i) First we prove that there cannot be two different values of k that satisfy con-
ditions (a) and (b). Towards a contradiction, assume that k1 and k2 are two
different values of k that satisfy conditions (a) and (b). Without loss of gener-
ality, assume that xk1 < xk2 . We thus have,
1
your algorithm is allowed to call MEDIAN on various inputs, but is not allowed to modify MEDIAN any
any way.

6
P P
i. xi 6xk1 wi 6 xi <xk2 wi < 12 , and
P
ii. xi >xk1 6 21 .
P
Adding i and ii we have that n i=1 wi < 1 which is a contradiction.
Now we prove that there exists a value of k that satisfies properties (a) and (b).
To this end, arrange the xi ’s in increasing order. Let the
P order be xj11 < . . . < xjn .
Let p be the largest number for which the condition xi <xjp wi < 2 is satisfied.
Thus choosing k = jp satisfies property (a). We will prove Pthat k = jp also
satisfies property (b). Towards a contradiction, assume that xi >xjp wi > 21 . By
P P
the choice of p we also know that xi 6xjp wi = xi <xj wi > 12 . Adding the
P p+1

two inequalities we have that n 1 1


i=1 wi > 2 + 2 = 1, which is a contradiction.

(ii) Sort the xi ’s in ascending order. Let the sorted sequence be xP j1 < . . . < xjn .
Recall from part (i) that wlm is xjp for the largest p that satisfies xi <xjp wi < 21 .
This can be found in linear time by scanning the sorted list and maintaining the
cumulative sums of wi ’s. Time complexity of the algorithm is dominated by the
time complexity of sorting which is O(n log n).
(iii) We will write an algorithm WLM whose input is a set of xi ’s, their corresponding
yi ’s, and a threshold
P `. On such an input, WLM returns the largest xk for which
the condition xi <xk wi < ` holds. Note that by part (i), the required wlm is the
output of the algorithm WLM on input x1 , . . . , xn , w1 , . . . , wn , 12 . Let T(t) be the

Algorithm 1 WLM (x1 , . . . , xt , w1 , . . . , wt , `)


1: if t = 1 then
2: return x1 .
3: end if
4: m ← MEDIAN(x1 , . . . , xt ).
5: L ← {i : xi 6 m}.
6: R ← {1, . . . , t}\L.
P
7: S ← i∈L wi .
8: if S < ` then
9: return WLM((xi , wi : i ∈ R), `−S).
10: else
11: return WLM((xi , wi : i ∈ L), `).
12: end if

time taken by WLM on this input. Since m is the (lower) median of x1 , . . . , xt ,


we have that |L|, |R| 6 t+12
. MEDIAN runs in linear time. The partitioning of
the xi ’s into L and R can be done in linear time (recall quicksort). Computing S
takes time linear in |L|. We thus have T (t) 6 T ( t−1
2
) + O(t) which implies that
T (t) = O(t).

7
References
[KT06] Jon Kleinberg and Eva Tardos. Algorithm design. Pearson Education India,
2006.

You might also like