exbook[1] | Time Complexity | Applied Mathematics

473 Algorithms - Exercises

Version 1.0

Sariel Har-Peled February 23, 2006

2

Contents
1 Exercises - Prerequisite 1.1 Graph Problems . . . . . . . . . . . 1.2 Recurrences . . . . . . . . . . . . . 1.3 Counting . . . . . . . . . . . . . . 1.4 O notation and friends . . . . . . . 1.5 Probability . . . . . . . . . . . . . . 1.6 Basic data-structures and algorithms 1.7 General proof thingies. . . . . . . . 1.8 Miscellaneous . . . . . . . . . . . . 5 5 7 9 9 11 13 15 16 17 17 17 18 18 18 18 19 19 19 19 19 20 20 20 20 21 21 21 22 22 22 23 24 24 25 25

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

2

Exercises - NP Completeness 2.1 Equivlance of optimization and decision problems . . . . . . . . . . . . 2.1.1 Beware of Greeks bearing gifts . . . . . . . . . . . . . . . . . . 2.1.2 Partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Showing problems are NP-C . . . . . . . . . . . . . . . . . . . 2.2.1 Graph Isomorphisms . . . . . . . . . . . . . . . . . . . . . . . 2.2.2 NP Completeness collection . . . . . . . . . . . . . . . . . . . 2.2.3 LONGEST-PATH . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.4 EXACT-COVER-BY-4-SETS . . . . . . . . . . . . . . . . . . 2.3 Solving special subcases of NP-C problems in polynomial time 2.3.1 Subset Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.2 2SAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.3 2-CNF-SAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.4 Hamiltonian Cycle Revisited . . . . . . . . . . . . . . . . . . . 2.3.5 Partition revisited . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.6 Why Mike can not get it. . . . . . . . . . . . . . . . . . . . . . 2.3.7 NP-Completeness Collection . . . . . . . . . . . . . . . . . . . 2.3.8 Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.9 Partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.10 Minimum Set Cover . . . . . . . . . . . . . . . . . . . . . . . 2.3.11 Bin Packing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.12 Knapsack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.13 Vertex Cover . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.14 Bin Packing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.15 Minimum Set Cover . . . . . . . . . . . . . . . . . . . . . . . 2.3.16 k-Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.17 MAX 3SAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . .

. . .19 2. . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . .7 Flooding . . . 3.22 2.13 Transitivity . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . 3. . 3. . . . . . . . .17 Perfect Matching . . . .1. . . . . . . . . . . . . . . . . .22 Go to school! . . . . . . . . . . . . . . . . . . . . . . . . . . yeh. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . .6 Follow the stars . . . . . . . . . . . . . yeh. . . . . . . . . . . . . . . . . . . .8 Capacitation. . . . . . . . . . . . . . . . . . . . . . . .Network Flow 3. . . .3.21 Scalar Flow Product . . GRAPH-ISOMORPHISM . . . . . . . . . . . . . . . .1 The good. . . . . . . . . . . .3. . . . . . . . . .15 Edge Connectivity . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . PLANAR-3-COLOR . . 3. . . . . . . .3. 3SUM . . . . . . . . .11 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . .1.1. . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . .21 2. . . . . . . . and the middle. . . . . . . . .3. . . . . . . . . . . . . . . . . . . 3. 3.3 Minimum Flow . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . .1 Network Flow . . . . . .20 Independence Matrix . . . . . . .3. . . . . . . . . . . . . . . . . . .10 Even More Capacitation . . . . . . .1. . . . . . . . 3. . .3. . . .18 Number of augmneting paths . . . 3.12 Unique Cut . . . . . . .18 2. . . . .1. DEGREE-4-PLANAR-3-COLOR . . . . the bad. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Census Rounding . . 4 . . . . . . Polynomially equivalent. . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . .26 3 Complexity . . . 3. . . . . .16 Maximum Flow By Scaling . . . . . . . . . . . . . . . . . . 3. . . . .1. . . . . . . .4 Prove infeasibility. . . . . . . . . . . . .9 Fast Friends . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . .1. . . . . Primality and Complexity . . . . .1. . . . . . .1. . . . . . . .1. . . . . . . . 3. . . . . . . . . . . . . . . . . 26 26 26 26 27 27 27 27 28 29 29 29 29 30 30 31 31 32 32 32 33 33 33 33 34 34 34 35 36 36 36 36 36 37 Exercises . . . . . . . . . . . . . Poly time subroutines can lead to exponential algorithms Polynomial time Hmiltonian path . . . . . . . .24 2. . . . . . . yeh . . . . . .23 2. . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . .25 2. . . .1. . . . . . . . . . . . . . . . . . . . .2 Ad hoc networks . . . . .1. . . . . . . . . . . . . . . . . . .20 2. .3. . . . . . . .1. . . . . 3. . . . . . . . . 3. . . . 3. .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . .3. . . . . . . . . . . . . . . .1. . . . . . .1. . . . . . . . . . . .23 The Hopcroft-Karp Bipartite Matching Algorithm . . . . . . 3. . .19 Minimum Cut Festival . .1. . . . . . . . . . . . .5 Cellphones and services. . . . . . . . . . . . . . . . . . . .1. . .

[20 Points] A tournament is a directed graph with exactly one edge between every pair of vertices.Exercises Sariel Har-Peled February 23. such that no two vertices that are connected by an edge have the same color.1 Graph Problems 1. 2. (a) [5 Points] Prove or disprove that if in a graph G the maximum degree is k. 2006 Version: 1.0 This chapter include problems that are prequisite. Prove that every tournament contains at least one Hamiltonian path. G! G! [20 Points] A coloring of a graph G by α colors is an assignment to each vertex of G a color which is an integer between 1 and α. 5 £ ¤ ¥   4 .Chapter 1 Exercises . that visits every vertex exactly once. 2 ¢ ¡ 3 1 6 5 A six-vertex tournament containing the Hamiltonian path 6 → 4 → 5 → 2 → 3 → 1. Their main purpose is to check whether you are read to take the 473 algorithms class. If you do not have the prerequisites it is your responsibility to fill in the missing gaps in your education. 1. where each edge points from the winner to the loser. joined end to end.Prerequisite 473G .) A Hamiltonian path is a sequence of directed edges. A    . then the vertices of the graph can be colored using k + 1 colors. (Think of the nodes as players in a round-robin tournament.Algorithms .

e. Canada).e. Prove (by induction) that a DAG (i. 3. u. contains a path between u and v. as in the following picture (for n = 3): 6 . E) is a partition of V into two disjoint sets S and T . v2 . (b) Prove that a graph is connected if and only if for every partition of its vertices into two nonempty sets. Recall that a walk is a list of the form v0 . . (Note. and two verticality next to it).. The epidemic started when m contaminated cows were dlivered to (some) of the farms. 4. [10 Points] (a) Use induction to prove that in a simple graph. Prove that if all the non-trivial cuts (i. .. v.. A cut is mixed if there exists s.. a mad cow decease was spreading among cow farms. e1 . v1 . e2 . vk . where k is the maximum degree in G. For a farm. naturally. that your algorithm should be as fast as possible. t ∈ T such that (s → t) ∈ E and (t → s ) ∈ E. • [5 Points] Show that if m = n then there is a scenario such that all the farms in the n × n grid get contaminated. A farm in the middle of the grid has four neighboring farms (two horizontally next to it. . there exists an edge that has endpoints in both sets. neither S nor T are empty) are mixed then the graph is not a neat graph. . organized. M C D [20 Points] In a land far far away (i. [10 Points] Consider a 2n ×2n chessboard with one (arbitrarily chosen) square removed. if the graph is provided using adjacency lists. What is the running time of you algorithm.e.. .(b) [5 Points] Provide an efficient coloring algorithm for a graph G with n vertices and m edges that uses at most k + 1 colors. We are interested in how the disease spread if we wait enough time. (d) [5 Points] A cut (S . vn such that if the edge vi → v j is in E(G) then i < j. in which ei has endpoints vi−1 and vi . C  .. E) is a neat graph if there exist an ordering of the vertices of the graph V(G) = v1 . T ) in a directed graph G = (V. if two or more of its neighboring farms have the disease than the cows in the farm would get the disease. v2 . ek . s ∈ S and t.as a n × n grid. every walk between a pair of vertices. 5.) (c) [5 Points] A directed graph G = (V. What is the running time of your algorithm if the graph is given with an adjacency matrix. The cow farms were. directed acyclic graph) is a neat graph. Once one cow in a farm has Mad Cow disease then all the cows in this farm get the disease. • [15 Points] Prove that if m ≤ n − 1 then (always) not all the farms are conaminated.

R [20 Points] Solve the following recurrences. State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). 1. Assume reasonable but nontrivial base cases if none are supplied.Prove that any such chessboard can be tiled without gaps or overlaps by L-shapes consisting of 3 squares each. . What is the running time of your algorithm? 7. Assume reasonable but nontrivial base cases if none are supplied. please don’t turn in proofs). T 2 and T 3 ). but you should do them anyway just for practice. and give the inorder sequence of nodes. whose nodes are labeled by letters of the alphabet. √ (a) [2 Points] A(n) = A n/3 + log n + n (b) [2 Points] B(n) = min 3 + B(k) + B(n − k) . Prove that the graph G = T 1 ∪ T 2 ∪ T 3 is colorable using six colors (e is an edge of G if and only if it is an edge in one of trees T 1 . please don’t turn in proofs). Professor George O’Jungle has a favorite 26-node binary tree. More exact solutions are better. The preorder and postorder sequences of nodes are as follows: preorder: M N H C R S K W T G D X I Y A J P O E Z V B U L Q F postorder: C W T K S G R H D N A O E P J Y Z I B Q L F U V X M Draw Professor O’Jungle’s binary tree. (b) [5 Points] Describe an efficient algorithm for computing this coloring. You do not need to turn in proofs (in fact. . C [10 Points] (a) [5 Points] Let T 1 . 0<k<n (c) [2 Points] C(n) = 3C( n/2 − 5) + n/ log n (d) [2 Points] D(n) = − 1) + 1 √ (e) [2 Points] E(n) = E( 3n/4 ) + n n n−3 D(n (f) [2 Points] F(n) = F( log n ) + log n √ √ (g) [2 Points] G(n) = n + n · G( n ) (h) [2 Points] H(n) = log(H(n − 1)) + 1 √ (i) [2 Points] I(n) = 5I n +1 (j) [2 Points] J(n) = 3J(n/4) + 1 2. vn }. T 2 and T 3 be three trees defined over the set of vertices {v1 . 7 . 6. State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). R II [20 Points] Solve the following recurrences.2 Recurrences 1. You do not need to turn in proofs (in fact. More exact solutions are better. . . but you should do them anyway just for practice.

Assume reasonable but nontrivial base cases if none are supplied. R III [20 Points] Solve the following recurrences. where F(1) = 1 and F(2) = 2. but you should do them anyway just for practice. You do not need to turn in proofs (in fact.] (i) I(n) = (n − 1)(I(n − 1) + I(n − 2)). [Hint: 1 2 (g) G(n) = G(n/2) + G(n/4) + G(n/6) + G(n/12) + n √ √ (h) H(n) = n + n · H( n) (j) J(n) = 8J(n − 1) − 15J(n − 2) + 1 + 1 4 + 1 6 + 1 12 = 1. (a) A(n) = A(n/2) + n (b) B(n) = 2B(n/2) + n (c) C(n) = n + (d) D(n) = (f) F(n) = 1 2 C(n − 1) + C(3n/4) D(k) + D(n − k) + n n/3<k<2n/3 max (e) E(n) = 2E(n/2) + n/ lg n F(n−1) F(n−2) . State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). please don’t turn in proofs). simplify your answers as much as possible. [10 Points] Evaluate the following summations. n i i (a) [2 Points] i=1 j=1 k= j n i i 1 i 1 j 1 k 8 (b) [2 Points] i=1 j=1 k= j n i i (c) [2 Points] i=1 j=1 k= j . 0<k<n (c) [1 Points] C(n) = 3C( n/2 − 5) + n/ log n (d) [1 Points] D(n) = − 1) + 1 √ (e) [1 Points] E(n) = E( 3n/4 ) + 1/ n n n−5 D(n (f) [1 Points] F(n) = F( log2 n ) + log n √ √ (g) [1 Points] G(n) = n + 7 n · G( n ) (h) [1 Points] H(n) = log2 (H(n − 1)) + 1 (i) [1 Points] I(n) = I n1/4 + 1 (j) [1 Points] J(n) = J n − n/ log n + 1 3. Significant partial credit will be given for answers in the form Θ( f (n)) for some recognizable function f (n).(a) [1 Points] A(n) = A n/3 + 5 + log n + n log log n (b) [1 Points] B(n) = min 3 + B(k) + B(n − k) . where F(0) = F(1) = 1 4.

[Hint: What is β5 ?] (c) Suppose γ0 = p. 1. and δn = (δn−2 δn−1 ) for all n ≥ 2. and a 2 × 2 × 10 box filled with ten slabs. [Hint: There is only one such function. This problem asks you to simplify some recursively defined boolean formulas as much as possible. and βn = (βn−2 ⇔ βn−1 ) for all n ≥ 2. [Hint: What is γ5 ?] (d) Suppose δ0 = p. δ1 = q. Simplify γn as much as possible. A 2 × 10 rectangle filled with ten dominos.] 1. and αn = (αn−2 ∧ αn−1 ) for all n ≥ 2. 2 × 1 × 2. or 2 × 2 × 1. How many different ways are there to fill a 2 × 2 × n box with n slabs? Set up a recurrence relation and give an exact closed-form solution.3 1. Simplify βn as much as possible. In each case. γ1 = q. please don’t turn in proofs). but you should 9 . (a) Suppose α0 = p. S  [20 Points] Sort the following 25 functions from asymptotically smallest to asymptotically largest. α1 = q. Simplify αn as much as possible. where is some boolean function with two arguments.n i j (d) [2 Points] i=1 j=1 k=1 n i j 1 k 1 j·k (e) [2 Points] i=1 j=1 k=1 5. prove that your answer is correct. [Hint: What is α5 ?] (b) Suppose β0 = p. Each proof can be just a few sentences long. but it must be a proof. Find a boolean function such that δn = δm if and only if n − m is a multiple of 4. How many different ways are there to completely fill a 2 × n rectangle with n dominos? Set up a recurrence relation and give an exact closed-form solution. indicating ties if there are any. and γn = (γn−2 ⇒ γn−1 ) for all n ≥ 2. Counting (a) A domino is a 2 × 1 or 1 × 2 rectangle. You do not need to turn in proofs (in fact.4 O notation and friends 1. β1 = q. (b) A slab is a three-dimensional box with dimensions 1 × 2 × 2.

do them anyway just for practice.5 cos n + 2 lg∗ 22 n n lg(lg n) 2lg ∗ n2. please don’t turn in proofs). n5. the functions n2 . (b) If f1 (n) = O(g1 (n)) and f2 (n) = O(g2 (n)). .5 − (n − 1)4.5 cos n + 2 lg∗ 22 2n n lg(lg∗ n) 2lg n n3/(2 lg n) nlg lg n n2. (a) Prove that 2 lg n + lg n = Θ(n2 ). 10 = Θ 22 lg lg n . fi (n) = o( n) (namely. n. O  . the functions n2 . [10 Points] √ (a) Let fi (n) be a sequence of functions. n4. n3 could be sorted either as n 2 2 n n 2 ≡ n2 n3 . indicating ties if there are any. [Hint: When considering two functions f (·) and g(·) it is sometime useful to 2 ≡ n consider the functions ln f (·) and ln g(·). Let g(n) = n i=1 fi (n). write f (n) g(n) to mean f (n) = o(g(n)) and f (n) ≡ g(n) to mean f (n) = n3 or as n2 ≡ n Θ(g(n)). For example.2 lg(n!) √ n n lg∗ (n/7) (lg ∗ 1 + lg lg n n4 n 1 i=1 i2 1 154n 1 + 154 n(lg n)3 ∗ n)lg n e n 1 i=1 i n3/(2n) n1/ lg lg n n3/(2 lg n) nlg lg n lg lg(n!) lg(200) n (lg(7 + n))lg n n1/1234 To simplify notation. Prove or disprove: • f1 (n) + f2 (n) = O(g1 (n) + g2 (n)) • f1 (n) ∗ f2 (n) = O(g1 (n) ∗ g2 (n)) • f1 (n) f2 (n) = O(g1 (n)g2 (n) ) 4. but you should do them anyway just for practice. write f (n) g(n) to mean f (n) = o(g(n)) and f (n) ≡ g(n) to mean f (n) = Θ(g(n)). S  .5 − (n − 1)5. such that for every i. lg n lg lg n (b) Prove or disprove: 2 (c) Prove or disprove: 22 =Θ2 lg n .1 (lg n)! √ e n 12 + lg lg(n) lg(201) n lg∗ (n/8) (lg∗ n)lg n n i=1 i 1 + lg lg lg n n5 n 2 i=1 i 1 15n 1 + 154 n(lg n)4 n7/(2n) n1/ lg lg n (lg(2 + n))lg n n1/125 To simplify notation. fi (n) √ n = Prove or disprove: g(n) = o(n3/2 ). You do not need to turn in proofs (in fact. n. S  II [20 Points] Sort the following 25 functions from asymptotically smallest to asymptotically largest.] 2. For example. limn→∞ 0). n . n3 could be sorted either as n n2 ≡ n n3 or as 2 2 n 2 n n3 . n . 3.

Suppose X is the number on the box that has the smallest number among all nonempty boxes. your answers are probably wrong!] 2. . we say there is a match. j in the ranges {1.] (e) [5 Points] Prove that the expected number of iterations performed by the algorithm is O(n5 ). then the expected number of iterations till the next swap is ≤ n2 /2. randomly selecting one of the neighbors of vi−1 and setting vi to be this vertex. and in the i-th stage. (f) Prove that logk n = o(n1/k ) for any positive integer k. if A[min(i. than the probability for a swap in the next iteration is at least ≥ 2/n2 . [20 Points] There are n balls (numbered from 1 to n) and n boxes (numbered from 1 to n). (e) Prove or disprove: If f (n) = O(g(n)).5 Probability 1. the array A is sorted. . 1. IS(A) sorts the array using an iterative algorithm. (There might be an easy solution. [Hint: Use linearity of expectation. the array A is sorted. In each iteration. [Hint: use geometric random variable. 11 . The algorithm magically stop once the array is sorted. (d) [5 Points] Prove that if A is not sorted.] 3. (a) [5 Points] Prove that after (at most) n! swaps performed by the algorithm. . What is the expectation of X? (b) [4 Points] What is the expected number of bins that have exactly one ball in them? (Hint: Compute the probability of a specific bin to contain exactly one ball and then use some properties of expectation. A walk v0 . n}. v1 . . I S [20 Points] There is an array A with n unsorted distinct numbers in it. [10 Points] A random walk is a walk on a graph G. What is the expected number of matches? (d) [4 Points] What is the probability that there are exactly k matches? (1 ≤ k < n) [Hint: If you have to appeal to “intuition” or “common sense”. j)] > A[max(i. . . (a) [4 Points] A box may contain more than one ball. vm is of length m. it picks randomly (and uniformly) two indices i. generated by starting from a vertex v0 = v ∈ V(G). j)] it swaps A[i] and A[ j]. but I don’t see it. then log( f (n)) = O(log(g(n))). If the number written on a ball is the same as the number written on the box containing the ball.(d) Prove or disprove: If f (n) = O(g(n)). .) (c) [8 Points] We put the balls into the boxes in such a way that there is exactly one ball in each box. Next. (b) [5 Points] Prove that after at most (say) 6n3 swaps performed by the algorithm. .) (c) [5 Points] Prove that if A is not sorted. then 2 f (n) = O(2g(n) ). We put each ball in a randomly selected box. for i > 0.

. R? [10 Points] We toss a fair coin n times.) Penn shuffles the deck until each each of the 52! possible orderings of the cards is equally likely. 8.) (b) [8 Points] We put the balls into the boxes in such a way that there is exactly one ball in each box. your answers are probably wrong! 12 . 9. Suppose X is the number on the box that has the smallest number among all nonempty boxes. Penn and Teller have a special deck of fifty-two cards.e. . if and only if. v) > 0. the toss sequence HHHTTHTH has 5 runs. v ∈ V(G). how many cards does Penn give Teller? (b) On average. 7. since if you flip coins too many times in the shop. 2. we say there is a match. T n . You have a coin. you might be arrested. your answers are probably wrong!] 6. what is the largest-numbered card that Penn gives Teller? [Hint: Solve for an n-card deck and then set n = 52. .] In each case. visits v (i. There n different types of green tea that you are considering: T 1 . with no face cards and nothing but clubs—the ace. He then takes cards one at a time from the top of the deck and gives them to Teller. 6.) 5. If the number written on a ball is the same as the number written on the box containing the ball. (Your algorithm should minimize the number of coin flips it uses. . Compute the expected number of coin flips your algorithm uses. you decide that you want to choose the ith tea with probability pi (of course. 4. . v) = 1. v ∈ V(G). 12. What is the expected number of “runs”? Runs are consecutive tosses with the same result. . What is the expectation of X? (It’s OK to just give a big expression. give exact answers and prove that they are correct. 11. we have Pu (n − 1. n pi = 1). . Because of the different prices of the different teas. starting from u. . 10. 4. vi = v for some i). 7. we have limm→∞ Pu (m. What is the expected number of matches? (c) [4 Points] What is the probability that there are exactly k matches? (1 ≤ k < n) [Hint: If you have to appeal to “intuition” or “common sense”. (a) [8 Points] A box may contain more than one ball. and you decide to randomly choose one of them using random coin flips. We put each ball in a randomly selected box. what is the smallest-numbered card that Penn gives Teller? (c) On average. i=1 Describe an algorithm that chooses a tea according to this distribution. 52 of clubs. For example. stopping as soon as he gives Teller the five of clubs. [20 Points] There are n balls (numbered from 1 to n) and n boxes (numbered from 1 to n). (b) Prove that a graph G with n vertices is connected if and only if for any pair of vertices u. If you have to appeal to “intuition” or “common sense”. for any two vertices u. 5. R E [10 Points] You are in a shop trying to buy green tea. let Pu (m. (a) On average.(a) For a vertex u ∈ V(G). 3.. using only coin flips. Prove that a graph G with n vertices is connected. v) be the probability that a random walk of length m. (They’re big cards.

Can you imagine any reason why WE would be preferable to FE? 13 .. Each operation should take time O(log n). where h is the maximum height of the tree during all the execution of the algorithm. (d) [3 Points] Given a query [a. describe separately the changes made in detail. printout) all the elements stored in T in the range [a. (b) [2 Points] Given a query k.e. provide bounds on the running times of those algorithms. the following algorithms terminate and produce identical output. Each temperature is a real number between −100 and 150. b]. [10 Points] Prove that for any nonnegative parameters a and b. b]. deletions. then no matter what Bob rolls. insert(22. d2 ) report what is the average of all temperatures that were measured between date d1 and date d2 . For example. he pays Alice $1.8. Alice and Bob each have a fair n-sided die. your answer is probably wrong! 1. then a 5.) (a) [2 Points] Find the smallest element stored in T in O(h) time. the game will end immediately. Each time Bob rolls. E . Also. 1. [10 Points] Suppose we have a binary search tree. Bob then repeatedly throws his die until he rolls a number at least as big as the number Alice rolled. (For example. find the k-th smallest element stored in T in O(h) time. then a 1. 3. d) — Insert the temperature t that was measured on date d. and Alice will get $1. searches. where u is the number of elements printed out. then a 3. For each of the following. etc). (c) [3 Points] Given a query [a. The operations on the data structure are as follows: Insert(t. in O(h) time. Implementing some of those operations would require you to modify the information stored in each node of the tree. where n is the number of dates stored in the data structure. and Bob rolls a 4. that under the modified version of the binary search tree. b]. Alice rolls her die once. Average(d1 . in O(h + u) time. (Note. and the way insertions/deletions are being handled in the tree. [10 Points] 2. the game ends and Alice gets $4. find the number of elements stored in T with their values being in the range [a. and the algorithms for answering those queries. ”1/20/03”). If Alice rolls a 1. B   . report (i. You perform a long sequence of operations on the binary tree (insertion. if Alice rolls a 5.) Exactly how much money does Alice expect to win at this game? Prove that your answer is correct. and the maximum depth of the tree during those operations is at most h. b]. insertion and deletion should still take O(h) time.6 Basic data-structures and algorithms Describe a data structure that supports storing temperatures. If you have to appeal to ‘intuition’ or ‘common sense’. You can assume that a date is just an integer which specifies the number of days since the first of January 1970. Modify the binary search tree T so that it supports the following operations.

Describe an algorithmx that rearranges the items into four clusters in O(n) time using only O(1) extra space. but there was too little room in the hallway for more than one student to move at a time. where each item has one of four possible values. a) else if b = 0 return a else return SE(b. Ravenclaw. a failed experiment by Fred and George Weasley filled almost all of Hogwarts with sticky brown goo. The student puts the Hat on their head. This year. b) : if b = 0 return a else return FE(b. T    . b) : if b = 0 return a if a = 0 return b if a is even and b is even return 2∗WE(a/2. you are given an array of n items. b) 4. b) : if b > a return SE(b. mere moments before the annual Sorting. G Harry H Ann R Bob R Tina G Chad G Bill R Lisa G Ekta H Bart H Jim R John S Jeff R Liz R Mary H Dawn G Nick S Kim H Fox G Dana G Mel G Harry G Ekta G Bill G Chad G Nick G Mel G Dana H Fox H Ann H Jim H Dawn H Bart R Lisa R Tina R John R Bob R Liz R Mary S Kim S Jeff x Since you’ve read the Homework Instructions. where there was so little room to move that the students had to stand in a long line. the students tried to group together by house. a − b) FastEuclid(a. Hufflepuff. After everyone learned what house they were in. the Sorting Hat took CS Course many years ago. Fortunately. b/2) if a is even and b is odd return WE(a/2. b) if a is odd and b is even return WE(a. Right? 14 . upon their arrival at Hogwarts School of Witchcraft and Wizardry. Every year. so it knew how to group the students as quickly as possible. b/2) if b > a return WE(b − a. you know what the phrase ‘describe an algorithm’ means.SlowEuclid(a. possibly with a pointer to some additional data. As a result. a mod b) WeirdEuclid(a. or Slytherin) by the Hogwarts Sorting Hat. What method did the Sorting Hat use? (a) More formally. a) else return WE(a − b. new students are sorted into one of four houses (Gryffindor. and the Hat tells the student which house they will join. the Sorting had to take place in the basement hallways.

a becoming like horn. they ask you to play the following game: At every point in time. How fast is your algorithm? (A faster algorithm would get more credit) (c) Describe a faster algorithm (if possible) for the case when O(k) extra space is allowed. Normally. Bottom: A corrupted linked list. For full credit. your algorithm should run in O(n) time. so that the last node has a pointer back to some other node in the list instead. The game terminates when you have n non-empty sacks. as tight as possible. . How fast is your algorithm? (d) Provide a fast algorithm that uses only O(1) additional space for the case where there are k possible values.e. 3} and the game ends. 2. and an infinite supply of empty sacks. Gates? Cornification . (a) [5 Points] Prove that the game terminates if you start from a configuration where all the cobs are in a single sack. 2. Cz [20 Points] During the sweetcorn festival in Urbana. . one sack has 1 cob. . Mr. For example.Conversion into. Source: Webster’s Revised Unabridged Dictionary 15 . your code is always completely 100% bug-free. we would have the following sequence of steps: {2. S  ? Suppose you have a pointer to the head of singly linked list. Isn’t that right. if we started with {1. they give you several sacks with a total of (n + 1)n/2 cobs of corn in them. Next. 1.. {1. your list might have been corrupted by a bug in somebody else’s codey . n. and you put this set of cobs into a new sack. you had been kidnapped by an extreme anti corn organization called Al Corona. 1. Unfortunately. Top: A standard linked list. y z After all. . (c) [5 Points] (hard) Prove that the game terminates if you start from an arbitrary configuration where the cobs might be in several sacks. each node in the list only has a pointer to the next element. on the number of steps in the game till it terminates in the case where you start with a single sack. . with the ith sack having i cobs in it. 5. . and use O(1) extra space (not counting the list itself).e. Your algorithm must not modify the list. 5} (i. . (b) [5 Points] Provide a bound. 4}.. k) that rearranges the items using only O(log k) extra space. .7 General proof thingies. Describe an algorithm that determines whether the linked list is corrupted or not. where n is the number of nodes in the list. and the last node’s pointer is N. the other 5). you take a cob from every non-empty sack. horn. for i = 1.(b) Describe an algorithm for the case where there are k possible values (i. 1. To punish you. or formation of.

F1 = 1. the rubber band is n + t inches long. the ant walks one inch to the right. so stretching the rubber band also pulls the ant to the right. by showing that the two sides of the equation count exactly the same thing in two different ways. starting at the left end. t=0 t=1 t=2 Every second. give an answer of the form f (n) + Θ(1) for some explicit function f (n). Once every second. Miscellaneous An ant is walking along a rubber band. The rubber band stretches uniformly. (b) (c) n i=0 F i = F n+2 2−F Fn n+1 F n−1 −1 = (−1)n+1 (d) If n is an integer multiple of m. and then the rubber band is stretched an inch longer. so after t seconds. There is a correct one-sentence proof. as tight as possible. S  . 16 . Recall the standard recursive definition of the Fibonacci numbers: F0 = 0. 3. (a) Prove the following identity by induction: 2n = n n k=0 n n . 1. and then you make the rubber band one inch longer by pulling on the right end. (a) How far has the ant moved after t seconds. The initial length of the rubber band is n inches. on the number of steps in the game till it terminates in the general case. k n−k (b) Give a non-inductive combinatorial proof of the same identity. and Fn = Fn−1 + Fn−2 for all n ≥ 2.8 1. [Hint: What fraction of the rubber band’s length has the ant walked?] (b) How long does it take the ant to get to the right end of the rubber band? For full credit. Prove the following identities for all positive integers n and m. the ant walks an inch. 2. then Fn is an integer multiple of Fm . (a) Fn is even if and only if n is divisible by 3. as a function of n and t? Set up a recurrence and (for full credit) give an exact closed-form solution.(d) [5 Points] Provide a bound.

Exercises Sariel Har-Peled February 23.” a collection C of subsets of A. a j ∩ c = 1 (that is. how to solve in polynomial time the optimization version of this problem (i.e. a j of possible diagnoses from A. E2 ). |e| = |E2 |. a subset V ⊆ V1 and a subset E ⊆ E1 such that |V| = |V2 |. to compute the subgraph isomorphism (i. E1 ) and H = (V2 . for every pair ai . representing binary “tests.1 Equivlance of optimization and decision problems Beware of Greeks bearing gifts (The expression “beware of Greeks bearing gifts” is Based on Virgil’s Aeneid: “Quidquid id est. G = (V1 . v} ∈ E2 if and only if { f (u).1 2. 2.Chapter 2 Exercises . timeo Danaos et dona ferentes”. you are given G and H. I fear Greeks even when they bring gifts. Problem: S I Instance: Two graphs. came to visit you on labor day. that is.. 1. a test c that “distinguishes” between ai and a j )? Show how to use this black box. [10 Points] The second box was a black box for solving S I. [10 Points] The first black box.NP Completeness 473G . f (v)} ∈ E? Show how to use this black box. 17 . and there exists a one-to-one function f : V2 → V satisfying {u. Question: Does G contain a subgraph isomorphic to H. Question: Is there a subcollection C ⊆ C with |C | ≤ J such that.. finding and outputting the smallest possible set C ). there is some test c ∈ C for which ai . the brother of the P satyr.e.02 2.Algorithms .1.”. and left you with two black boxes. which means literally “Whatever it is.” and a positive integer J ≤ |C|. and you have to output f ) in polynomial time. was a black box that can solves the following decision problem in polynomial time: Problem: M T C Instance: A finite set A of “possible diagnoses.) The  faun. 2006 Version: 1.

E1 ).2 2. . Problem: LARGEST COMMON SUBGRAPH Instance: Graphs G = (V1 . [5 Points] Show that the following problem is NP-C. . E2 ). Question: Do there exists subsets E1 ⊆ E1 and E2 ⊆ E2 with |E1 | = |E2 | ≥ K such that the two subgraphs G = (V1 . [5 Points] Problem: MINIMUM SET COVER Instance: Collection C of subsets of a finite set S and an integer k. and a positive integer K.2. v} ∈ E2 if and only if { f (u). Question: Are there k sets S 1 . E2 ).2.1. a partition of S if such a solution exists. as a token of appreciation. the uncle of the deduction fairy. positive integer K. [5 Points] Problem: BIN PACKING Instance: Finite set U of items. . and there exists a one-to-one function f : V2 → V satisfying {u. Describe a polynomial time algorithm that computes. H = (V2 . f (v)} ∈ E? 2. [5 Points] 18 . s∈T s∈S \T 2. a subset V ⊆ V1 and a subset E ⊆ E1 such that |V| = |V2 |.1 Showing problems are NP-C Graph Isomorphisms 1. . S k in C such that S ⊆ ∪k S i ? i=1 2. such that s= s.2. . i. E2 ) are isomorphic? 2.e. had visited you on winter break and gave you. Problem: SUBGRAPH ISOMORPHISM Instance: Graphs G = (V1 . . U K such that the sum of the sizes of the items inside each Ui is B or less? 3. [5 Points] Show that the following problem is NP-C. a size s(u) ∈ Z + for each u ∈ U. an integer bin Z capacity B. . Question: Does G contain a subgraph isomorphic to H. using the black box. H = (V2 . Question: Is there a partition of U int disjoint sets U1 . Let S be a given set of n integer numbers. your algorithm should output a subset T ⊆ S . E1 ).2 NP Completeness collection 1.2 Partition The P satyr. a black-box that can solve P in polynomial time (note that this black box solves the decision problem). E1 ) and H = (V2 . |E| = |E2 |.. . Namely.

19 . show that EXACT-COVER-BY-4-SETS is also NP-C. does C contain an exact cover for X. Question: Is there a way of placing the rectangles of RECT S inside R.4 EXACT-COVER-BY-4-SETS The EXACT-COVER-BY-3-SETS problem is defines as the following: given a finite set X with |X| = 3q and a collection C of 3-element subsets of X. 2.3. and all the rectangles have their edges parallel of the edges of R? 4. so that no pair of the rectangles intersect.2 2SAT Given an instance of 2SAT (this is a problem similar to 3SAT where every clause has at most two variables). where M = max s∈S s. 2. a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C. t: .3 LONGEST-PATH Show that the problem of deciding whether an unweighted undirected graph has a path of length greater than k is NP-C.3.an integer number Question: Is there a subset X ⊆ S such that x=t? x∈X Given an instance of S S. that is. [5 Points] Problem: HITTING SET Instance: A collection C of subsets of a set S . 2. Question: Does S contain a hitting set for C of size K or less. that is. a positive integer K.set of positive integers. and M. provide an algorithm that solves it in polynomial time in n.Problem: TILING Instance: Finite set RECT S of rectangles and a rectangle R in the plane.3 2. a subcollection C ⊆ C such that every element of X occurs in exactly one member of C ? Given that EXACT-COVEqR-BY-3-SETS is NP-C.2.2.1 Solving special subcases of NP-C problems in polynomial time Subset Sum Problem: S S Instance: S . one can try to solve it by backtracking. Why this does not imply that P = NP? 2.

Given this proof. k k Let Cn denote the graph where {i. What is wrong with this proof? 3. using polynomial number of calls to the black-box (if such an assignment exists). and M = max s∈S s. . . and E(Cn ) = {{1. 2. [1 Points] Prove that if a formula F is not satisfiable.3. we provide the following proof to the verifier: We list every possible assignment.) 1. Describe a polynomial time algorithm (in n) that outputs a Hamiltonian cycle if such a cycle exists in G. .3. 2. (ii) F is a 2SAT formula. 2} . describe a polynomial time algorithm that computes a subformula F of F. the verifier can easily verify it in polynomial time in L. it evaluates to FALSE. (iii) F is satisfiable iff there is a satisfying assignment for F with xi = b. [6 Points] Describe a polynomial time algorithm that solves the 2SAT problem (using (b)).3. [10 Points] Problem: N-3SAT Instance: A 3CNF formula F Question: Is F not satisfiable? (Namely. n}. {n − 1. 2. {2. 20 . Prove that N-3SAT is co − NP. (Duh?) We refer to F as a subformula of F.1. then the formula F is not satisfiable. 1}}). How fast is your algorithm? 2. Here is a proof that N-3SAT is in NP: If the answer to the given instance is Yes.3 2-CNF-SAT Prove that deciding satisfiability when all clauses have at most 2 literals is in P. of length L. such that n = |S |. and (iv) F is a subformula of F. and for each assignment.. [3 Points] Given an assignment xi ← b to one of the variables of a 2SAT instance F (where b is either 0 or 1). How fast is your algorithm? 3. such that (i) F does not have the variable xi in it. Show a polynomial time (in n and M) algorithm that solves partition. How fast is your algorithm. V(Cn ) = {1. as a function of n and k? 2. . 3} . j} ∈ E(Cn ) iff i and j are in distance at most k in Cn . and F is formed by adding clauses to F . we list the output (which is FALSE). such that G is a subgraph of Cn . .3. .6 Why Mike can not get it. Show that given a black-box that can solves N-3SAT. k Let G be a graph. for all inputs for F. 2.5 Partition revisited Let S be an instance of partition.e.4 Hamiltonian Cycle Revisited Let Cn denote the cycle graph over n vertices (i. . QED. n} {n. one can find the satisfying assignment of a formula F in polynomial time. where k is a small constant. .

Z Question: Is there a subset A ⊆ A such that s(a) = a∈A a∈A\A s(a)? Show that PARTITION is NP-C. Z Question: Is there a subset A ⊆ A such that a∈A s(a) = B? Now let’s consider the following problem: Problem: PARTITION Instance: A finite set A and a “size” s(a) ∈ Z + for each a ∈ A. an integer B.3. Question: Are there k sets S 1 . such that for any edge i j ∈ E. . . .9 Partition We already know the following problem is NP-C: Problem: SUBSET SUM Instance: A finite set A and a “size” s(a) ∈ Z + for each a ∈ A. Problem: MINIMUM SET COVER 1. . Instance: Graph G = (V. . E) and integer k Question: Does G contains a spanning tree T where every node in T is of degree at most k? 2. Problem: H P 3. E) be an undirected graph over n vertices. Instance: Collection C of subsets of a finite set S and an integer k. every vertex have a unique number).7 NP-Completeness Collection [20 Points] Prove that the following problems are NP-Complete. we have |π(i) − π( j)| ≤ 20. a positive integer K.8 Independence [10 Points] Let G = (V. Instance: Graph G = (V.2. S k in C such that S ⊆ ∪k S i ? i=1 Problem: HITTING SET 2.3.) Problem: M D S T4. a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C. that is. 21 . 2. Instance: A collection C of subsets of a set S .3.e. Either prove that it is NP-Hard to find the largest independent set in G. or provide a polynomial time algorithm. Question: Does S contain a hitting set for C of size K or less. E) Question: Does G contains a Hamiltonian path? (Namely a path that visits all vertices of G. . . n} (i. Assume that you are given a numbering π : V → {1. ..

2. 3. Problem: KNAPSACK Instance: A finite set U. and all the rectangles have their edges parallel of the edges of R? 2. [5 Points] Show that the following problem is NP-C. Z Z Question: Is there a subset U ⊆ U such that u∈U s(u) ≤ B and u∈U v(u) ≥ B. such that p ∈ I. . .12 Knapsack 1. a size s(u) ∈ Z + for each u ∈ U. that is. and a positive integer K. . a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C. Question: Is there a way of placing all the rectangles of RECT S inside R. Question: Are there k sets S 1 . Problem: TILING Instance: Finite set RECT S of rectangles and a rectangle R in the plane. a ”size” s(u) ∈ Z + and a ”value” v(u) ∈ Z + for each Z Z u ∈ U. a positive integer K. Question: Does S contain a hitting set for C of size K or less.2.3. and a value goal K ∈ Z +. [5 Points] Prove that MINIMUM SET COVER problem is NP-C 2. .10 Minimum Set Cover [15 Points] Problem: MINIMUM SET COVER Instance: Collection C of subsets of a finite set S and an integer k. . Question: Is there a partition of U into disjoint sets U1 . [5 Points] Show that the following problem is NP-C. . . so that no pair of the rectangles intersect in their interior. [5 Points] Show that the BIN PACKING problem is NP-C 2.3. such that for every interval I ∈ I there is a point p ∈ X. Problem: HITTING SET Instance: A collection C of subsets of a set S . show a O(n log n) time algorithm that computes the smallest set of points X on the real line. [5 Points] Prove that the following problem is NP-C. 22 .11 Bin Packing Problem: BIN PACKING Instance: Finite set U of items. S k in C such that S ⊆ ∪k S i ? i=1 1. . U K such that the sum of the sizes of the items inside each Ui is B or less? 1.3. [5 Points] Hitting set on the line Given a set I of n intervals on the real line. a size constraint B ∈ Z +. an integer bin capacity Z B.

you are given the processing times. a graph G = (V. each one of the remaining connected components has at most (2/3)n vertices. In your free time you can try and improve this constant. where Kopt is the cardinality of the smallest vertex cover of G. Scheduling with profits and deadlines Suppose you have one machine and a set of n tasks a1 . [5 Points] Show that the following problem is NP-C. an . such that X is a vertex cover.{ 3. if there are k vertices of G. (More formally. If you complete task a j by its deadline d j . if for any subset of vertices S ⊆ V. a number Z + + m ∈ Z of ”processors”. 2. and a deadline d j . 2001.pdf. On the importance of being biased..2. Z Z Question: Is there a partition A = A1 A2 · · · Am of A into m disjoint sets such that max{ a∈Ai l(a) : 1 ≤ i ≤ m} ≤ D? 3.3.math. and |C| ≤ 2Kopt . such that if we remove them from G. a profit p j . and task a j must run uninterruptedly for t j consecutive time units to complete. a ”length” l(a) ∈ Z + for each a ∈ A. As an optimization problem. E) and a positive integer K ≤ |V|. E) is k-separable. Namely.. Question: Is there a vertex cover of size K or less for G. your algorithm should output a set X ⊆ V.13 Vertex Cover Problem: VERTEX COVER Instance: A graph G = (V. one can compute the optimal VERTEX COVER in nO(k) time. Dinur and S. and a ”deadline” D ∈ Z . Show that VERTEX COVER is NP-C. The machine can process only one task at a time. But you receive no profit if you complete it after its deadline. { 23 . profits and deadlines for a set of n tasks.ias. (a) [3 Points] State this problem as a decision problem.) that doing better than 1.edu/˜iritd/mypapers/vc. Present a linear time algorithm that solves this problem for the case that G is a tree. Safra. such that each connected component of GS \M has at most (2/3)|S | vertices. http://www.. and |M| ≤ k. there exists a subset M ⊆ S . Good luck. a graph G is k-separable. Show a polynomial approximation algorithm to the V-C problem which is a factor 2 approximation of the optimal solution. Manuscript. v} ∈ E.) Show that given a graph G which is k-separable. a subset V ⊆ V such that |V | ≤ K and for each edge {u. at least one of u and v belongs to V ? 1. you receive a profit p j . (b) [2 Points] Show that the decision problem is NP-C. Each task a j has a processing time t j . and furthermore each one of those connected components is also k-separable. 4.3600 approximation to VERTEX COVER is NP-Hard. Problem: MULTIPROCESSOR SCHEDULING Instance: A finite set A of ”tasks”. a2 . that is. Hint: Do a reduction from INDEPENDENT SET to VERTEX COVER. For a constant k. It was very recently shown (I. 2. and you wish to find a schedule that completes all the tasks and returns the greatest amount of profit. .

. say. a size s(u) ∈ Z + for each u ∈ U.2. Present a polynomial time algorithm that computes a subset T ⊆ RECT S. . U K such that the sum of the sizes of the items inside each Ui is B or less? 1.3. and M ≤ kopt . . The greedy approximation algorithm for MINIMUM SET COVER. . it outputs a partition of U into M bins.3. Prove the greedy algorithm is O(log n) factor optimal approximation. 3. S k in C such that S ⊆ ∪k S i ? i=1 1. Prove that the number of elements not covered after kopt iterations is at most n/2. .14 Bin Packing Problem: BIN PACKING Instance: Finite set U of items. . Assume that RECT S is a set of squares that can be arranged as to tile R completely. 10% of the area of R. In the optimization variant of BIN PACKING one has to find the minimum number of bins needed to contain all elements of U. Question: Is there a partition of U int disjoint sets U1 . and all the rectangles have their edges parallel of the edges of R? 5.15 Minimum Set Cover Problem: MINIMUM SET COVER Instance: Collection C of subsets of a finite set S and an integer k. so that this tiling of T covers. so that no pair of the rectangles intersect. an integer bin capacity Z B. Namely. 2. Prove that MINIMUM SET COVER problem is NP-C 2. 4. and a positive integer K. works by taking the largest set in X ∈ C. where kopt is the smallest number of sets of C needed to cover S . Describe a polynomial algorithm that computes the solution that uses the minimum number of bins to store all the elements. 4. . Question: Are there k sets S 1 . The algorithm repeat this until all the elements of S are removed. where kopt is the minimum number of bins of size B needed to store all the given elements of U. Present an algorithm that is a factor two approximation to optimal solution. Show that the following problem is NP-C. 24 . . Prove that the following problem is NP-C. Question: Is there a way of placing the rectangles of RECT S inside R. Show that the BIN PACKING problem is NP-C 2. remove all all the elements of X from S and also from each subset of C. 3. and a tiling of T . Problem: TILING Instance: Finite set RECT S of rectangles and a rectangle R in the plane. and n = |S |. Assume that B is bounded by an integer constant m. such that the total size of each bin is at most B.

outputs k disks. such that for every interval I ∈ I there is a point p ∈ X.17 MAX 3SAT Problem: MAX SAT Instance: Set U of variables. and an integer k and a radius r. a positive integer K. given P and a radius r. 2. where ropt is the minimum radius of such a cover of P. show a O(n log n) time algorithm that computes the smallest set of points X on the real line. so that the k disks cover P and are of radius r. Question: Find an assignment that maximized the number of clauses of C that are being satisfied. Prove that that the above algorithm is a factor two approximation to the optimal cover. Namely. a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C. 5. where ropt is the smallest radius. the radius of the disks output ≤ 2ropt .3. 6. In this problem. such that p ∈ I.3. and it continue in this fashion till it has k-points. 3. one should find the smallest number of disks of radius r that cover P. Describe an approximation algorithm to the r-DISK COVER problem. Question: Does S contain a hitting set for C of size K or less. a collection C of disjunctive clauses of literals where a literal is a variable or a negated variable in U. Question: Is there a cover of the points of P by k disks of radius (at most) r? 1. and k = O(kopt ). . where kopt is the minimal number of disks needed to cover P by disks of radius r. Given a set I of n intervals on the real line. so that we can find k-disks that cover the point-set. which are the resulting centers.16 k-Center Problem: k-CENTER Instance: A set P of n points in the plane. your algorithm would output k-disks that cover the points and their radius is ≤ (1+ε)ropt . The smallest k equal radius disks centered at those points are the required k disks. 2.Problem: HITTING SET Instance: A collection C of subsets of a set S . Describe an nO(k) time algorithm that solves this problem. 25 Consider the Problem MAX SAT. Namely. 4. that is. Show an implementation of this approximation algorithm in O(nk) time. There is a very simple and natural algorithm that achieves a 2-approximation for this cover: First it select an arbitrary point as a center (this point is going to be the center of one of the k covering disks). Prove that dual problem r-DISK-COVER problem is NP-Hard. given k and a set of points P in the plane. 2. given a point-set P and a radius r. Provide an ε-approximation algorithm for this problem. Then it computes the point that it furthest away from the current set of centers as the next center. Namely. 5.

3. prove that the problem of deciding whether a planar graph can be 3-colored is NP-C.3. 2. MIN CUT and MAX CUT (between s and t) 5. Let (U. which are just two versions of minimal representation of a graph). 5. and we randomly assign to the variables values 0 or 1. Prove that P ⊆ -NP. −2. 13}. 4. since −5 + 7 + (−2) = 0.21 PLANAR-3-COLOR Using 3COLORABLE. C) be an instance of MAX SAT such that each clause has ≥ 10 · log n distinct variables.3.20 Polynomially equivalent. −13. Namely. your algorithm should answer T for the set {−5. 2. SHORTEST PATH and LONGEST PATH 3. Show that for any instance of MAX SAT.3. and F for the set {−6. Prove that MAX SAT is NP-Hard.1. Hint: show that the gadget can be 3-colored. then every NP-C problem is not a member of -NP. EDGE COVER and VERTEX COVER 6. 4}. 2. there exists an assignment that satisfy all the clauses of C. 4.21. 7. MIN SPANNING TREE and MAX SPANNING TREE 2. −2. there exists an assignment that satisfies at least 7/8 of the clauses.3. TRAVELING SALESMAN PROBLEM and VACATION TOUR PROBLEM (the longest tour is sought). 2. does it contain three elements whose sum is zero? For example. Which of these pairs are polytime equivalent and which are not? Why? 2. where each clause has exactly three different literals.18 Complexity 1.19 3SUM Describe an algorithm that solves the following problem as quickly as possible: Given a set of n numbers. 26 . and then replace any crossings in a planar embedding with the gadget appropriately. −4. TRANSITIVE REDUCTION and MIN EQUIVALENT DIGRAPH (all of these seem dual or opposites. where M = |C|.3. 7. where n is the number of clauses. 2. Prove that there exists a satisfying assignment. Show that if NP -NP. then the expected number of satisfied clauses is (7/8)M. −17. Consider the following pairs of problems: 1. −4. Prove that if each clause has exactly three literals. except the last. 3. and the ‘gadget’ in figure 2.

Prove that if G is an undirected bipartite graph with an odd number of vertices. Hint: -NP is easy (what’s a certificate for showing that a number is composite?). 2. then G is nonhamiltonian. Give a polynomial time algorithm algorithm for finding a hamiltonian cycle in an undirected bipartite graph or establishing that it does not exist. Explain why the results in previous questions do not contradict the facts that both HAM-CYCLE and HAM-PATH are NP-C problems. Show that knowing this tree of primitive roots can be checked to be correct and used to show that n is prime. Show that the hamiltonian-path problem can be solved in polynomial time on directed acyclic graphs by giving an efficient algorithm for the problem.1: Gadget for PLANAR-3-COLOR. 2. Hint: show that you can replace any vertex with degree greater than 4 with a collection of gadgets connected in such a way that no degree is greater than four. prove that the problem of deciding whether a planar graph with no vertex of degree greater than four can be 3-colored is NP-C. and the ‘gadget’ in figure 2.Figure 2.24 Poly time subroutines can lead to exponential algorithms Show that an algorithm that makes at most a constant number of calls to polynomial-time subroutines runs in polynomial time. For NP.22 DEGREE-4-PLANAR-3-COLOR Using the previous result. 27 .22.3.3. is n prime?) is in NP ∩ -NP. consider a certificate involving primitive roots and recursively their primitive roots.23 Primality and Complexity Prove that PRIMALITY (Given n. Figure 2. and that this check takes poly time. 3.3. 2. 2.25 Polynomial time Hmiltonian path 1.3.3. but that a polynomial number of calls to polynomial-time subroutines may result in an exponential-time algorithm.2: Gadget for DEGREE-4-PLANAR-3-COLOR. 2.

4. 28 . Give an efficient probabilistic algorithm to decide this.2. 3. 1.26 GRAPH-ISOMORPHISM Consider the problem of deciding whether one graph is isomorphic to another. 2. or prove that neither case occurs. Either prove that this problem is NP-C. Give a dynamic programming algorithm to decide this.3. Give a brute force algorithm to decide this. give a poly time algorithm for it.

• We say a node v is downstream if. we have v ∈ B – that is. G can have many minimum cuts.2 Ad hoc networks [20 Points] Ad hoc networks are made up of low-powered wireless devices. Here’s one way to divide the nodes of G into three categories of this sort. [10 Points] Suppose you’re looking at a flow network G with source s and sink t. and some nodes are in the middle. • We say a node v is central if it is neither upstream nor downstream. have been proposed for situations like natural disasters in which the coordinators of a rescue effort might want to monitor conditions in a hard-toreach area.Exercises Sariel Har-Peled February 23. some nodes are clearly on the “sink side” of the main bottlenecks. The running time of your algorithm should be within a constant factor of the time required to compute a single maximum flow. 2006 Version: 1. and you want to be able to express something like the following intuitive notion: Some nodesare clearly on the “source side” of the main bottlenecks. we have v ∈ A – that is.1. 3.1. and at least one minimum s-t cut (A . B). • We say a node v is upstream if.Chapter 3 Exercises . so we have to be careful in how we try making this idea precise. B) for which v ∈ A. v lies on the sink side of every minimum cut. B ) for which v ∈ B . Give an algorithm that takes a flow network G and classifies each of its nodes as being upstream.Algorithms . The idea is that a large collection of these wireless devices could be dropped into such an area from an airplane and then configured into a functioning network. 29 . However.Network Flow 473G .1 3. the bad. v lies on the source side of every minimum cut. for all minimum s-t cuts (A. B).02 This chapter include problems that are realted to network flow. for all minimum s-t cuts (A. there is at least one minimum s-t cut (A. or central. downstream.1 Network Flow The good. and the middle. 3.

it becomes necessary to include provisions for dealing with the failure of a reasonable number of the nodes.Note that we’re talking about (a) relatively inexpensive devices that are (b) being dropped from an airplane into (c) dangerous territory. (b). for a pair of devices at distance δ. Design an algorithm that determines whether it is possible to choose a back-up set for each device (i. the signal strength f (δ) that they’ll be able to achieve on their wireless connection. The problem has demands. there’s a strict dichotomy between being “in range” or “out of range” is a simplified abstraction. Give an algorithm that determines whether it is possible to choose a back-up set for each device subject to this more detailed condition. each within d meters). We’ll call this a back-up set for device v. with positions represented by an (x. E). Suppose you’re given a set of n wireless devices. but no capacity limits on the edges. and numbers (capacities) (v. 2. and (c). w) ∈ E.. You are given a directed graph G = (V. so that if the back-up set for v consists of devices at distances d1 ≤ d2 ≤ · · · ≤ dk . Each device has a limited transmitting range – say it can communicate with other devices that lie within d meters of it. Again.. Moreover. stil requiring that no device should appear in the back-up set of more than b other devices. the algorithm should output the back-up sets themselves. they require that f (v.e. it should transmit a representation of its current state to some other device in the network. the given numbers are lower bounds on edge flow – that is. More formally. for some parameter b. does min-flow = maxcut?). then we should have f (d j ) ≥ p j for each j. no device appears in the back-up set of more than b other devices. w) for every edge (v. there is a graph G = (V. and there is no upper bound on flow values on edges. but it is not feasible. 3. 3. provided they can be found. and for the combination of reasons (a). More accurately. and so forth. w) for each edge (v.3 Minimum Flow [10 Points] Give a polynomial-time algorithm for the following minimization analogue of the Maximum-Flow Problem.1. we should include some redundancy: A device v should have a set of k other devices that it can potentially contact. and demands dv for each node v (satisfying 30 . The idea that. We define a flow f . and the value of a flow.e.1. E). k other devices. You are trying to solve a circulation problem. at least one other that can be reached with moderately high signal strength. Give a polynomial-time algorithm that finds a feasible flow of minimum possible values.) We might want to build this into our notion of back-up sets as follows: among the k devices in the back-up set of v. there should be at least one that can be reached with very high signal strength. However. w) ≥ (v. 1. Prove an analogue of the Max-Flow Min-Cut Theorem for this problem (i. for each pair of devices v and w. y) coordinate pair for each. since we don’t want it to try transmitting its state to a device that has already failed. 1. 2. we have values p1 ≥ p2 ≥ · · · ≥ pk . The algorithm should output the back-up sets themselves. requiring that all nodes except s and t satisfy flow conservation.4 Prove infeasibility. We’d like it to be the case that if one of the devices v detects that it is in danger of failing. with the further property that. as usual. More concretely. there’s a power decay function f (·) that specifies. each within d meters of it. provided they can be found. w) ∈ E. with a source s ∈ V and sink t ∈ V. (We’ll assume that f (δ) decreases with increasing δ.

7 by setting ce = +∞ for all edges e ∈ E. Player P0 names an actress x1 ∈ X. and so on. algorithmically speaking. Now the goal is to find a subset X ⊂ U maximizing x∈X v x such that there is an assignment of the customers in X to stations. x2 . and there is a set of k requests for service. (This is viewed as an advantage: If we need to reject a high-paying customer. isn’t it just breadth-first search?) and decide to invent a game with a little more punch. y1 .6 Follow the stars [20 Points] Some friends of yours have grown tired of the game “Six Degrees of Kevin Bacon” (after all. and there is an edge (x. v∈V 3. Using a max-flow computation. Let U be the set of customers. You quickly realize that the existence of such a set immediately implies that the flow cannot exist: The set U has a positive total demand. (Alternately. A player Pi (i = 0. We add x to the set X if and only if there is a way to assign X ∪ {x} to servers. the other the customers. Here’s how it works. 3. Give a polynomial-time algorithm to find a subset S ⊂ V of nodes such that there is no edge into S and for which v∈S dv is as large as possible subject to this condition. Each request can be served by a given set of stations. and so needs incoming flow. and we reject x otherwise. or provide a counterexample. and assume that customer x ∈ U is willing to pay v x ≥ 0 for being served. Assume that each station can serve at most one customer. so it would be very useful to know why the problem is not feasible as it stands now.1. we do not assign accepting customers to servers in a greedy fasion: we only fix the assignment after the set of accepted customers is fixed.) You want to fix up the graph to make the problem feasible. you see that there is a subset U of nodes such that there is no edge into U. . Consider the following greedy approach. Thus. When considering customer x the algorithm will either “promise” service to x or reject x in the following greedy fasion. and yet v∈U dv > 0. We process customers in order of decreasing value (breaking ties arbitrarily). The problem so far can be represented by a bipartite graph G: one side is the stations. and two players P0 and P1 . player P1 names an actor y1 who has appeared in a movie with x1 . they ask. y) between customer x and station y if customer x can be served from station y. On a closer look. it is enough to set ce to be an extremely large number for each edge – say. Does this greedy approach produce an optimal set of customers? Prove that it does.1. 31 . . or can get an assignment of a subset of customers to stations maximizing the number of served customers. and yet U has no edges into it.) However. at least we can tell him/her early. You start with a set X of n actresses and a set Y of n actors. y2 . that the stations are cell towers and the requests are cell phones. such that each actor/actress in the sequence has costarred with the actress/actor immediately preceding. P0 and P1 collectively generate a sequence x1 . larger than the total of all positive demands dv in the graph. In trying to evaluate how far the problem is from being solvable. . for example. and he/she cannot name a member of his/her set who hasn’t been named before. Note that this problem can be solved via the circulation algorithm from Section 7.5 Cellphones and services. and the problem is to decide if there is a flow f such that f (e) ≥ 0 and f in (v) − f out (v) = dv for all nodes v ∈ V. player P0 names an actress x2 who has appeared in a movie with y1 . 1) loses when it is Pi ’s turn to move.dv = 0). Here we consider a version of the problem with an addition complication: Each customer offers a different amount of money for the service. you wonder how big the demand of a set with no incoming edges can be. Say. we can decide whether or not all customers can be served. Consider an assignment problem where we have a set of n stations that can provide service. Let X be the set of customers that so far have been promised service. Note that rejected customers will not be considered later.

your friends hadn’t really gotten into the whole backward-edge thing when writing the code. with complete information on who has appeared in a movie with whom.7 Flooding [10 Points] Network flow issues come up in dealing with natural disasters and other crises. yeh. There are k hospitals in the region. it searches for ˜ s-t paths in a graph G f consisting only of edges of e for which f (e) < ce . However. x2 . We’ll call this the Forward-Edge-Only Algorithm. The flow { fe } is acyclic: There is no cycle in G on which all edges carry positive flow. In other words. and so their implementation builds a variant of the residual graph that only includes the forwards edges. defined by a flow value fe on each edge e. 3. depending on where they are right now). paramedics have identified a set of n injured people distributed across the region who need to be rushed to hospitals. and each of the n people needs to be brought to a hospital that is within a half-hour’s driving time of their current location (so different people will have different options for hospitals. y1 . with a positive integer capacity ce on each edge e. in a particular instance of this game.8 Capacitation.1. yeh.9 Fast Friends [20 Points] Your friends have written a very fast piece of maximum-flow code based on repeatedly finding augmenting paths as in the course lecture notes. 3. and they want to collectively work out whether they can choose a hospital for each of the injured people in such a way that the load on the hospitals is balanced: Each hospital receives at most n/k people. The bug turns out to be pretty easy to find.Suppose you are given a specific pair of such sets X and Y. Now suppose we pick a specific edge e∗ ∈ E and reduce its capacity by 1 unit. Show how to find a maximum flow in the resulting capacitated graph in time O(m + n). Consider the following scenario. Give a polynomial-time algorithm that takes the given information about the people’s locations and determines whether this is possible. one doesn’t want to overload any one of the hospitals by sending too many patients its way. in our setting.1. you realize that it’s not always finding a flow of maximum value.1. since major unexpected events often require the movement and evacuation of large numbers of people in a short amount of time. A strategy for Pi . (Note that we do not try ot prescribe how this algorithms chooses its forward-edge paths. and it terminates when there is no augmenting path consisting entirely of such edges. after you’ve looked at a bit of output from it. . and generates a legal next move for Pi (assuming it’s Pi ’s turn to move). and a designated sink t ∈ V. The paramedics are in touch by cell phone. that it never returns a flow whose value is less than a fixed fraction of optimal. 3. Give a polynomial-time algorithm that decides which of the two players can force a win. a designated source s ∈ V. E). provided that it terminates only when there are no forward-edge paths. At the same time. where m is the number of edges in G and n is the number of nodes. is an algorithm that takes a current sequence x1 . You are also given a maximum s-t flow in G. they claim. y2 . it may choose them in any fashion it wants. yeh Suppose you are given a directed graph G = (V. in fact. Do you believe this? The crux of their claim can be made precise in the following statement. 32 . . In addition to its blazing speed.) It’s hard to convince your friends they need to reimplement the code. . Due to large-scale flooding in a region.

but for which at least one entry in each row and each column is equal to 1. − Is it true that for every G and every k ≥ 0. we say that x −→ y if there exist k mutually edge-disjoint paths from x to y in G. 3.k G. Decide whether you think this statement is true or false.k [10 Points] Given a graph G = (V. E) be a directed graph. Let G = (V. 3. so that on every instance of the Maximum-Flow Problem. Give a polynomial-time algorithm to find an s-t maximum flow in such a node-capacitated network. E) be a directed graph. sink t ∈ V. the Forward-Edge-Only Algorithm is guaranteed to find a flow of value at least 1/b times the maximum-flow value (regardless of how it chooses its forward-edge paths). Define an s-t cut for node-capacitated networks. [8 Points] Give a polynomial-time algorithm that determines whether a matrix M with 0-1 entries is rearrangeable. 3. Let mi j denote the entry in row i and column j.13 Transitivity G.k G.e. A diagonal entry is one of the form mii for some i. with source s ∈ V. and there is no limit on how much flow is allowed to pass through a node. and a natural number k.k .1. we assume edges have capacities. 1.k G.“There is an absolute constant b > 1 (independent of the particular input flow network). the relation −→ is transitive? That is. 2. Give a polynomial-time algorithm to decide whether G has a unique minimum s-t cut (i. we can define a relation −→ on pairs of vertices of G − as follows. y ∈ V.1..12 Unique Cut [10 Points] Let G = (V.10 Even More Capacitation [10 Points] In a standard s − t Maximum-Flow Problem. and nonnegative edge capacities {ce }. We say that a flow is feasible if it satisfies the usual flow-conservation constraints and the node-capacity constraints: f in (v) ≤ cv for all nodes. then we have x −→ z? Give a proof or a counterexample.1. and show that the analogue of the Max-Flow Min-Cut Theorem holds true. we consider the variant of the MaximumFlow and Minimum-Cut problems with node capacities. In this problem. an s-t of capacity strictly less than that of all other s-t cuts). is it always the case − that if x −→ y and y −→ z. [2 Points] Give an example of a matrix M that is not rearrangeable. If x.1. 3. and give a proof of either the statement or its negation. − − − 33 G. sink t ∈ V.11 Matrices [10 Points] Let M be an n × n matrix with each entry equal to either 0 or 1.k G. the flow through a node v is defined as f in (v). E). Given a flow f in this graph. and nonnegative node capacities {cv ≥ 0} for each v ∈ V. with source s ∈ V.

000 grown-up women 13.000 24.000 2.000 total 26.000 7. E) can be determined by running a maximum-flow algorithm on at most |V| flow networks. v) on each edge (u. Country A B C Total grown-up men 11. For example. 3.000 4.145 27. the edge connectivity of a tree is 1.019 2.000 total 26.000 children 1.045 0.000 7. For example. 34 .15 Edge Connectivity [20 Points] The edge connectivity of an undirected graph is the minimum number k of edges that must be removed to disconnect the graph.1. and you want to round each fractional number α to either α or α .000 55. Let C = max(u.16 Maximum Flow By Scaling [20 Points] Let G = (V.000 10.000 4.000 10. The Census Rounding Problem is to round all data to integers without changing any row or column sum. [5 Points] Consider the Census Rounding Problem as defined above. sink t. where row and column sums are integers. E) be a flow network with source s. The statistics are about populations of different regions in the world and are recorded in multiples of one million.936 4. [10 Points] Prove that the rounding we are looking for in (a) and (b) always exists. and the edge connectivity of a cyclic chain of vertices is 2. v). 1.1.000 55.000 27.3. [5 Points] Consider first the special case when all data are between 0 and 1.000 3.000 We will assume here for simplicity that our data is such that all row and column sums are integers. Use a flow computation to check if the desired rounding is possible. They collect statistics and publish the collected data in a book. Use a flow computation to check if the desired rounding is possible. So you have a matrix of fractional numbers between 0 and 1.983 10. 3.998 9. Country A B C Total grown-up men 11. 2.872 3.919 24.14 Census Rounding [20 Points] You are consulting for an environmental statistics firm. each having O(V) vertices and O(E) edges.000 grown-up women 12.000 22. Each fractional number can be rounded either up or down. Show how the edge connectivity of an undirected graph G = (V. Examples of such statistics would look like the following table.000 1. v) ∈ E.083 2.1. and your problem is to round each fraction that is between 0 and 1 to either 0 or 1 without changing the row or column sums. and an integer capacity c(u.v)∈E c(u.000 children 1. 3. [2 Points] Argue that a minimum cut of G has capacity at most C|E|.000 22. a good rounding for our table data would be as follows.000 0.

1. [5 Points] For a given number K. where |L| = |R|. v) 2 initialize flow f to 0 3 K ← 2 lg C 4 while K ≥ 1 do { 5 while (there exists an augmenting path p of capacity at least K) do { 6 augment flow f along p } 7 K ← K/2 } 8 return f 3. Prove Hall’s theorem: there exists a perfect matching in G if and only if |A| ≤ |N(A)| for every subset A ⊆ L.17 Perfect Matching [20 Points] 1.v)∈E c(u. 3. 6. The following modification of F-F-M can be used to compute a maximum flow in G. is d-regular if every vertex v ∈ V has degree exactly d. For any X ⊆ V. [4 Points] Show that the capacity of a minimum cut of the residual graph G f is at most 2K|E| each time line 4 is executed. where V = L ∪ R. [10 Points] A perfect matching is a matching in which every vertex is matched. y) ∈ E for some x ∈ X . 35 . Let G = (V. Every d-regular bipartite graph has |L| = |R|. if such a path exists. define the neighborhood of X as N(X) = y ∈ V (x. [2 Points] Conclude that M-F-B-S can be implemented so that it runs in O(E 2 lg C) time. show that an augmenting path of capacity at least K can be found in O(E) time.2. t) 1 C ← max(u. 5. 2. M-F-B-S(G. s. [4 Points] Argue that the inner while loop of lines 5-6 is executed O(E) times for each value of K. E) be an undirected bipartite graph with vertex partition V = L ∪ R. the set of vertices adjacent to some member of X. [3 Points] Argue that M-F-B-S returns a maximum flow. 4. that is. Prove that every d-regular bipartite graph has a matching of cardinality |L| by arguing that a minimum cut of the corresponding flow network has capacity |L|. E). [10 Points] We say that a bipartite graph G = (V.

E) can always be found by a sequence of at most |E| augmenting paths. unfortunately. define an α approximate cut in a multigraph G as any cut whose cardinality is within a multiplicative factor α of the cardinality of the min-cut in G. Determine the probability that a single iteration of the randomized algorithm for cuts will produce as output some α-approximate cut in G.22 Go to school! Professor Adam has two children who. 3. Using the analysis of the randomized min-cut algorithm.e. [10 Points] Show that a maximum flow in a network G = (V.1.19 Minimum Cut Festival [20 Points] 1.1. consider how both δ(s. 4. Prove that the flows in a network form a convex set. [Hint: For any edge (u.18 Number of augmneting paths 1.1. v). t) change between times at which (u. For any α ≥ 1.] 2. Given a multigraph G(V. show that an edge can be selected uniform at random from E in time O(n).v). “cover”) all the 1’s in the matrix. but in fact each one refuses to walk on any block that the other child has stepped on that day. 3.1. dislike each other. u) ∈ E. 2. v) = α · f (u. We also say that a set of lines in the matrix is a cover of H if they include (i. but beyond that he is not sure if it is going to be 36 . show that if f1 and f2 are flows. E). v) ∈ E if and only (v. show that the number of distinct min-cuts in a multigraph G cannot exceed n(n − 1)/2. then so is α f1 + (1 − α) f2 for all α in the range 0 ≤ α ≤ 1. and let α be a real number. denoted by α f . 3. that is. Show that the Edmonds-Karp algorithm terminates after at most |V||E|/4 iterations. We say that a set of 1’s in the matrix H is independent if no two of them appear in the same line. The children have no problem with their paths crossing at a corner. Formulate and prove a similar result of the number of α -approximate cuts in a multigraph G.] 3. E) has symmetric edges.v) is critical.. given access to a source of random bits. is a function from V × V to IR defined by (α f )(u.21 Scalar Flow Product [10 Points] Let f be a flow in a network. u) and δ(v.1.20 Independence Matrix [10 Points] Consider a 0 − 1 matrix H with n1 rows and n2 columns. show that the maximum number of independent 1’s equals the minimum number of lines in the cover. (u.3. The scalar flow product. Using the max-flow min-cut theorem on an appropriately defined network. [Hint: Determine the paths after finding the maximum flow. We refer to a row or a column of the matrix H as a line. 3. The problem is so severe that not only they refuse to walk to school together. That is. Fortunately both the professor’s house and the school are on corners. [10 Points] Suppose that a flow network G = (V. where n is the number of vertices in G.

. Pk } be a maximum set of vertex-disjoint shortest augmenting paths with respect to M 4 M ← M ⊕ (P1 ∪ P2 ∪ .. where V = L ∪ R and all edges have exactly one endpoint in L.) In this problem. . Pk are vertexdisjoint augmenting paths with respect to M. 2. Show how to formulate the problem of determining if both his children can go to the same school as a maximum-flow problem. then the symmetric difference M ⊕ P is a matching and |M ⊕ P| = |M| + 1. E).. Pk be a maximum set of vertex-disjoint augmenting paths of length l with respect to M. ∪ Pk ).1. 3... for finding a maximum √ matching in a bipartite graph.. and its edges belong alternatively to M and E − M. Let l be the length of a shortest augmenting path with respect to a matching M. P2 . . . we describe a faster algorithm. the number of iterations in the repeat loop) and to describe an implementation of line 3. and let P1 .23 The Hopcroft-Karp Bipartite Matching Algorithm [20 Points] In this problem. show that every vertex in the graph G = (V. and suppose that P is a shortest augmenting path with respect to M . Prove that if |M| ≤ |M ∗ |. the elements that are in exactly one of the two sets.. (This definition of an augmenting path is related to. Given an undirected. an augmenting path in a flow network. due to Hopcroft and Karp. Conclude that G is a disjoint union of simple paths or cycles.. The general structure of our algorithm is the following: H-K(G) 1 M←∅ 2 repeat 3 let P ← {P1 . The algorithm runs in O( V E) time. P2 . then M ⊕ M ∗ contains at least |M ∗ | − |M| vertex-disjoint augmenting paths with respect to M... let M be a matching in G. the symmetric difference A ⊕ B is defined as (A − B) ∪ (B − A). 37 . A shortest augmenting path with respect to a matching M is an augmenting path with a minimum number of edges. 1.possible to send both of his children to the same school. ∪ Pk ) is a matching with cardinality |M| + k.. ends at an unmatched vertex in R.. We say that a simple path P in G is an augmenting path with respect to M if it starts at an unmatched vertex in L. Argue that edges in each such simple path or cycle belong alternatively to M or M ∗ . that is. P2 .. M ⊕ M ∗ ) has degree at most 2. [2 Points] Show that if P is vertex-disjoint from P1 . but different from.. . Given two sets A and B. Pk . 3. . then P has more than l edges. ∪ Pk ) 5 until P = ∅ 6 return M The remainder of this problem asks you to analyze the number of iterations in the algorithm (that is. The professor has a map of his town. . Let M = M ⊕ (P1 ∪ P2 ∪ . [4 Points] Show that if M is a matching and P is an augmenting path with respect to M. P2 . bipartite graph G = (V. we treat a path as a sequence of edges. [4 Points] Given two matchings M and M ∗ in G. Show that if P1 . rather than as a sequence of vertices. then the symmetric difference M ⊕ (P1 ∪ P2 ∪ ...

. Show that A = (P1 ∪ P2 ∪ . Conclude that P has more than l edges. 5. [2 Points] Prove that if a shortest augmenting path for M has length l. Pk . Conclude that the total running time of √ H-K is O( V E). Let A be the set of edges (M ⊕ M ) ⊕ P.. ∪ Pk ) ⊕ P and that |A| ≥ (k + 1)l. 38 . [Hint: By √ how much can M grow after iteration number V?] 7. [2 Points] Now suppose P is not vertex-disjoint from P1 . Pk for a given matching M.. √ 6.4. P2 .. P2 . [4 Points] Give an algorithm that runs in O(E) time to find a maximum set of vertex-disjoint shortest augmenting paths P1 .. [2 Points] Show that the number of repeat loop iterations in the algorithm is at most 2 V. the size of the maximum matching is at most |M| + |V|/l.... ..

19. 23 2SAT. 25 MINIMUM SET COVER. 21. 19 EXACT-COVER-BY-3-SETS. 19 39 . 25 Hamiltonian Path. 25 BIN PACKING. 17. 18. 20 Partition. 21 Minimum Test Collection. 19. 18 PRIMALITY. 22. 20 3COLORABLE. 17 Not-3SAT. 22. 18. 17 Subset Sum. 18 SUBSET SUM. 17 Subset Sum. 22. 19 TILING. 21 Subgraph Isomorphism. 19. 22 LARGEST COMMON SUBGRAPH. 27 reduction. 26 3SAT. 17 Subgraph Isomorphism. 24 HITTING SET. 25 Not-3SAT.Index Problem k-CENTER. 19 MAX SAT. 21 KNAPSACK. 23 Max Degree Spanning Tree. 21. 24 MULTIPROCESSOR SCHEDULING. 18 MAX SAT. 24 VERTEX COVER. 20 PARTITION. 21 SUBGRAPH ISOMORPHISM. 22.

Sign up to vote on this title
UsefulNot useful