## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

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

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

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

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

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

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

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

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

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

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

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

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

. . . . . . . . .3. . . . .8 Capacitation. . . . . . . . . . . . . . . . Polynomially equivalent. . .1. . . . . . . . . . . . . . . .18 2. . . . . . . . . .5 Cellphones and services. . . . . . . . . . . . . . . .21 Scalar Flow Product . . . . . . 3. . . . . . . . . yeh . . . . . . . . . .18 Number of augmneting paths . . . . . . . 3. . 3. . . . . . . . . . . . . . . . . . . .9 Fast Friends . 4 . . . .2 Ad hoc networks . .22 2. . .7 Flooding . . 3. . .1. . . . . . .19 2. . . . .23 The Hopcroft-Karp Bipartite Matching Algorithm . . . . . . . . . . . . . . . . . . .22 Go to school! . . . . . .1. . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . .2. . . . . . . . . . . . . . . . . . .3.1. . . . . . . . . . . . . . . . . 3.1. . . . . . .3. . . . . . DEGREE-4-PLANAR-3-COLOR .1. . . . . . . . . . . . . . . .1 Network Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Minimum Flow . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . .1. . . . . . . . .1. . . . . . . . . . . . 3. . . . . . .19 Minimum Cut Festival . . . . . . 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 . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . . . . and the middle. . . . . . . . . 3. . . . . . . . . . . . . . . 3. . . . . . . . . . . . . . . . . . . . . . . . .3. .1. . . . . . . . . . . . . . . . . . . . . . . . . . . the bad. . . . . .1. . Poly time subroutines can lead to exponential algorithms Polynomial time Hmiltonian path . . . . . . . . . . . . . .3. . . . . . . . . . . yeh. . . . . . . .24 2. . . . . . . . . . . . . . . . 3. .20 Independence Matrix .6 Follow the stars . . . . . . . . Primality and Complexity . . . . 3. . . . . . . .1. . . . . . . . . . . . . . . . . yeh. . . . . . . . . . . . . . . . . . . . 3.15 Edge Connectivity . . . . . . . .12 Unique Cut . . . . . . . . . . .1. . .1. . . . . . . . 3SUM . .20 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Matrices . . . .4 Prove infeasibility. . 3. . . . 3. . .3. . . . . . 3. . . . . PLANAR-3-COLOR . . . . . . . . . . . . . . . . . . . . . . . . . . .10 Even More Capacitation .26 3 Complexity . . .16 Maximum Flow By Scaling . . .1. . . . . . . . . . . .13 Transitivity . . 3. . . 3. . .1 The good. . . . . . . . . . . . . . . . . .3. . . . . . . . . . . 3. . . . . .23 2. . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. GRAPH-ISOMORPHISM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Census Rounding . . . . . . . . 3. . . . . . . . . . . . . . . . . . . .1. . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Network Flow 3. . . . . . . .3. . . . . . . . . . . .21 2. . . . . . 3. . . . . . . . . . . . . .1. . . . . . . . . . .17 Perfect Matching . . . . . . . . . . . . . . . . .25 2. . . . . . .1. . 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. .

Their main purpose is to check whether you are read to take the 473 algorithms class. such that no two vertices that are connected by an edge have the same color.0 This chapter include problems that are prequisite.Prerequisite 473G .Chapter 1 Exercises . that visits every vertex exactly once.) A Hamiltonian path is a sequence of directed edges. where each edge points from the winner to the loser. 2.Algorithms . joined end to end. (a) [5 Points] Prove or disprove that if in a graph G the maximum degree is k.Exercises Sariel Har-Peled February 23.1 Graph Problems 1. then the vertices of the graph can be colored using k + 1 colors. 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 . [20 Points] A tournament is a directed graph with exactly one edge between every pair of vertices. If you do not have the prerequisites it is your responsibility to ﬁll in the missing gaps in your education. A . Prove that every tournament contains at least one Hamiltonian path. 1. (Think of the nodes as players in a round-robin tournament. 2 ¢ ¡ 3 1 6 5 A six-vertex tournament containing the Hamiltonian path 6 → 4 → 5 → 2 → 3 → 1. 2006 Version: 1.

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

State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). 7 . 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. 6. 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.Prove that any such chessboard can be tiled without gaps or overlaps by L-shapes consisting of 3 squares each. √ (a) [2 Points] A(n) = A n/3 + log n + n (b) [2 Points] B(n) = min 3 + B(k) + B(n − k) . Assume reasonable but nontrivial base cases if none are supplied. T 2 and T 3 be three trees deﬁned over the set of vertices {v1 . .2 Recurrences 1. . please don’t turn in proofs). but you should do them anyway just for practice. vn }. whose nodes are labeled by letters of the alphabet. please don’t turn in proofs). C [10 Points] (a) [5 Points] Let T 1 . You do not need to turn in proofs (in fact. . Professor George O’Jungle has a favorite 26-node binary tree. 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 . You do not need to turn in proofs (in fact. R [20 Points] Solve the following recurrences. R II [20 Points] Solve the following recurrences. . (b) [5 Points] Describe an eﬃcient algorithm for computing this coloring. T 2 and T 3 ). and give the inorder sequence of nodes. Assume reasonable but nontrivial base cases if none are supplied. More exact solutions are better. What is the running time of your algorithm? 7. More exact solutions are better. but you should do them anyway just for practice. State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). 1.

] (i) I(n) = (n − 1)(I(n − 1) + I(n − 2)).(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) . 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. [10 Points] Evaluate the following summations. but you should do them anyway just for practice. simplify your answers as much as possible. You do not need to turn in proofs (in fact. where F(1) = 1 and F(2) = 2. State tight asymptotic bounds for each function in the form Θ( f (n)) for some recognizable function f (n). where F(0) = F(1) = 1 4. R III [20 Points] Solve the following recurrences. Signiﬁcant partial credit will be given for answers in the form Θ( f (n)) for some recognizable function f (n). [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. please don’t turn in proofs). (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) . Assume reasonable but nontrivial base cases if none are supplied.

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

indicating ties if there are any. You do not need to turn in proofs (in fact. limn→∞ 0). (a) Prove that 2 lg n + lg n = Θ(n2 ).5 − (n − 1)4.] 2. the functions n2 . n. the functions n2 . For example. n . n4. For example. O . 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)).5 cos n + 2 lg∗ 22 2n n lg(lg∗ n) 2lg n n3/(2 lg n) nlg lg n n2. 3.do them anyway just for practice. 10 = Θ 22 lg lg n .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. n5.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. Let g(n) = n i=1 fi (n).5 − (n − 1)5. such that for every i. n3 could be sorted either as n 2 2 n n 2 ≡ n2 n3 . (b) If f1 (n) = O(g1 (n)) and f2 (n) = O(g2 (n)). please don’t turn in proofs). n . [10 Points] √ (a) Let fi (n) be a sequence of functions. fi (n) = o( n) (namely. 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.5 cos n + 2 lg∗ 22 n n lg(lg n) 2lg ∗ n2. n. S . write f (n) g(n) to mean f (n) = o(g(n)) and f (n) ≡ g(n) to mean f (n) = Θ(g(n)). . lg n lg lg n (b) Prove or disprove: 2 (c) Prove or disprove: 22 =Θ2 lg n . S II [20 Points] Sort the following 25 functions from asymptotically smallest to asymptotically largest. fi (n) √ n = Prove or disprove: g(n) = o(n3/2 ). n3 could be sorted either as n n2 ≡ n n3 or as 2 2 n 2 n n3 . but you should do them anyway just for practice. [Hint: When considering two functions f (·) and g(·) it is sometime useful to 2 ≡ n consider the functions ln f (·) and ln g(·).

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

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

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

upon their arrival at Hogwarts School of Witchcraft and Wizardry. the students tried to group together by house. b) 4. b) if a is odd and b is even return WE(a. Right? 14 . and the Hat tells the student which house they will join. As a result. Describe an algorithmx that rearranges the items into four clusters in O(n) time using only O(1) extra space. a mod b) WeirdEuclid(a. Fortunately. T . you know what the phrase ‘describe an algorithm’ means.SlowEuclid(a. but there was too little room in the hallway for more than one student to move at a time. After everyone learned what house they were in. Ravenclaw. a) else if b = 0 return a else return SE(b. Every year. where each item has one of four possible values. a) else return WE(a − b. Huﬄepuﬀ. new students are sorted into one of four houses (Gryﬃndor. so it knew how to group the students as quickly as possible. the Sorting Hat took CS Course many years ago. This year. 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. b) : if b = 0 return a else return FE(b. possibly with a pointer to some additional data. the Sorting had to take place in the basement hallways. b) : if b > a return SE(b. b/2) if a is even and b is odd return WE(a/2. b) : if b = 0 return a if a = 0 return b if a is even and b is even return 2∗WE(a/2. where there was so little room to move that the students had to stand in a long line. you are given an array of n items. or Slytherin) by the Hogwarts Sorting Hat. a failed experiment by Fred and George Weasley ﬁlled almost all of Hogwarts with sticky brown goo. What method did the Sorting Hat use? (a) More formally. The student puts the Hat on their head. mere moments before the annual Sorting. b/2) if b > a return WE(b − a. a − b) FastEuclid(a.

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

Prove the following identities for all positive integers n and m. [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. and then the rubber band is stretched an inch longer. k n−k (b) Give a non-inductive combinatorial proof of the same identity. Miscellaneous An ant is walking along a rubber band. The initial length of the rubber band is n inches. so after t seconds. 3. then Fn is an integer multiple of Fm . the ant walks one inch to the right. (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. (a) Fn is even if and only if n is divisible by 3. The rubber band stretches uniformly.8 1. t=0 t=1 t=2 Every second. the ant walks an inch. 1. and Fn = Fn−1 + Fn−2 for all n ≥ 2. (a) Prove the following identity by induction: 2n = n n k=0 n n . so stretching the rubber band also pulls the ant to the right.(d) [5 Points] Provide a bound. There is a correct one-sentence proof. give an answer of the form f (n) + Θ(1) for some explicit function f (n). S . by showing that the two sides of the equation count exactly the same thing in two diﬀerent ways. 2. and then you make the rubber band one inch longer by pulling on the right end. F1 = 1. (a) How far has the ant moved after t seconds. Once every second. 16 . on the number of steps in the game till it terminates in the general case. Recall the standard recursive deﬁnition of the Fibonacci numbers: F0 = 0. as a function of n and t? Set up a recurrence and (for full credit) give an exact closed-form solution. the rubber band is n + t inches long. starting at the left end. as tight as possible.

Question: Does G contain a subgraph isomorphic to H. v} ∈ E2 if and only if { f (u). 2. there is some test c ∈ C for which ai . that is.Chapter 2 Exercises . Question: Is there a subcollection C ⊆ C with |C | ≤ J such that. f (v)} ∈ E? Show how to use this black box.) The faun.” a collection C of subsets of A. ﬁnding and outputting the smallest possible set C ). you are given G and H. I fear Greeks even when they bring gifts.1 2.Algorithms . 1. and there exists a one-to-one function f : V2 → V satisfying {u.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.e. [10 Points] The second box was a black box for solving S I.. representing binary “tests.”.Exercises Sariel Har-Peled February 23. 17 . |e| = |E2 |. E1 ) and H = (V2 . 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 ﬁnite set A of “possible diagnoses. for every pair ai . Problem: S I Instance: Two graphs. timeo Danaos et dona ferentes”. a j ∩ c = 1 (that is. came to visit you on labor day. how to solve in polynomial time the optimization version of this problem (i.02 2. 2006 Version: 1.. G = (V1 . a test c that “distinguishes” between ai and a j )? Show how to use this black box.1. to compute the subgraph isomorphism (i.” and a positive integer J ≤ |C|.NP Completeness 473G . and left you with two black boxes. E2 ). which means literally “Whatever it is.e. a subset V ⊆ V1 and a subset E ⊆ E1 such that |V| = |V2 |. [10 Points] The ﬁrst black box. the brother of the P satyr. a j of possible diagnoses from A.

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

set of positive integers.3 2. and M. 2. provide an algorithm that solves it in polynomial time in n. where M = max s∈S s. a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C.4 EXACT-COVER-BY-4-SETS The EXACT-COVER-BY-3-SETS problem is deﬁnes as the following: given a ﬁnite set X with |X| = 3q and a collection C of 3-element subsets of X. 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. one can try to solve it by backtracking.3.2 2SAT Given an instance of 2SAT (this is a problem similar to 3SAT where every clause has at most two variables). Why this does not imply that P = NP? 2.3. [5 Points] Problem: HITTING SET Instance: A collection C of subsets of a set S . 2.1 Solving special subcases of NP-C problems in polynomial time Subset Sum Problem: S S Instance: S . show that EXACT-COVER-BY-4-SETS is also NP-C. 19 .an integer number Question: Is there a subset X ⊆ S such that x=t? x∈X Given an instance of S S. that is. so that no pair of the rectangles intersect. that is.Problem: TILING Instance: Finite set RECT S of rectangles and a rectangle R in the plane.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. and all the rectangles have their edges parallel of the edges of R? 4.2.2. does C contain an exact cover for X. Question: Does S contain a hitting set for C of size K or less. 2. t: . Question: Is there a way of placing the rectangles of RECT S inside R. a positive integer K.

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

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 ﬁnite set A and a “size” s(a) ∈ Z + for each a ∈ A. that is. Question: Are there k sets S 1 . . E) and integer k Question: Does G contains a spanning tree T where every node in T is of degree at most k? 2. we have |π(i) − π( j)| ≤ 20.) Problem: M D S T4.. S k in C such that S ⊆ ∪k S i ? i=1 Problem: HITTING SET 2. every vertex have a unique number).7 NP-Completeness Collection [20 Points] Prove that the following problems are NP-Complete. . 21 .e. Instance: A collection C of subsets of a set S . E) Question: Does G contains a Hamiltonian path? (Namely a path that visits all vertices of G. 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. Instance: Collection C of subsets of a ﬁnite set S and an integer k. an integer B. Problem: H P 3. such that for any edge i j ∈ E. .3.9 Partition We already know the following problem is NP-C: Problem: SUBSET SUM Instance: A ﬁnite set A and a “size” s(a) ∈ Z + for each a ∈ A. a subset S ⊆ S with |S | ≤ K and such that S contains at least one element from each subset in C. E) be an undirected graph over n vertices.3.8 Independence [10 Points] Let G = (V. 2. Assume that you are given a numbering π : V → {1. Question: Does S contain a hitting set for C of size K or less. a positive integer K.3.2. . Instance: Graph G = (V. Instance: Graph G = (V. or provide a polynomial time algorithm. Either prove that it is NP-Hard to ﬁnd the largest independent set in G. . n} (i. . . Problem: MINIMUM SET COVER 1. .

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

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

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

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

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

2.22. Hint: -NP is easy (what’s a certiﬁcate for showing that a number is composite?). 2. 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. then G is nonhamiltonian. For NP.3. 2.3. Give a polynomial time algorithm algorithm for ﬁnding a hamiltonian cycle in an undirected bipartite graph or establishing that it does not exist. Prove that if G is an undirected bipartite graph with an odd number of vertices. Explain why the results in previous questions do not contradict the facts that both HAM-CYCLE and HAM-PATH are NP-C problems.3.2: Gadget for DEGREE-4-PLANAR-3-COLOR. 27 .3.3. consider a certiﬁcate involving primitive roots and recursively their primitive roots. 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. is n prime?) is in NP ∩ -NP.Figure 2.25 Polynomial time Hmiltonian path 1. and the ‘gadget’ in ﬁgure 2. but that a polynomial number of calls to polynomial-time subroutines may result in an exponential-time algorithm. Figure 2. 2.22 DEGREE-4-PLANAR-3-COLOR Using the previous result. 3.1: Gadget for PLANAR-3-COLOR. Show that the hamiltonian-path problem can be solved in polynomial time on directed acyclic graphs by giving an eﬃcient algorithm for the problem. Show that knowing this tree of primitive roots can be checked to be correct and used to show that n is prime.23 Primality and Complexity Prove that PRIMALITY (Given n.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. and that this check takes poly time.

28 .26 GRAPH-ISOMORPHISM Consider the problem of deciding whether one graph is isomorphic to another.2. Give a dynamic programming algorithm to decide this. give a poly time algorithm for it. 2. 1. Either prove that this problem is NP-C. 3. Give an eﬃcient probabilistic algorithm to decide this. or prove that neither case occurs.3. 4. Give a brute force algorithm to decide this.

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

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

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

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

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

The Census Rounding Problem is to round all data to integers without changing any row or column sum.1. and the edge connectivity of a cyclic chain of vertices is 2.000 grown-up women 12.3. [2 Points] Argue that a minimum cut of G has capacity at most C|E|.000 7. They collect statistics and publish the collected data in a book. 2.000 22. Use a ﬂow computation to check if the desired rounding is possible. 34 .000 10. Examples of such statistics would look like the following table.000 We will assume here for simplicity that our data is such that all row and column sums are integers.000 total 26.000 24. a good rounding for our table data would be as follows. each having O(V) vertices and O(E) edges.000 4.145 27.16 Maximum Flow By Scaling [20 Points] Let G = (V. So you have a matrix of fractional numbers between 0 and 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.083 2.919 24. [5 Points] Consider ﬁrst the special case when all data are between 0 and 1. The statistics are about populations of diﬀerent regions in the world and are recorded in multiples of one million. 1. v) ∈ E. Let C = max(u. v) on each edge (u. Country A B C Total grown-up men 11. the edge connectivity of a tree is 1.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. and an integer capacity c(u.045 0.019 2.000 children 1. [10 Points] Prove that the rounding we are looking for in (a) and (b) always exists. Country A B C Total grown-up men 11. E) be a ﬂow network with source s.000 grown-up women 13. Show how the edge connectivity of an undirected graph G = (V.000 total 26. E) can be determined by running a maximum-ﬂow algorithm on at most |V| ﬂow networks.000 1.983 10. sink t.936 4.000 10.1.000 27. where row and column sums are integers. For example.872 3. [5 Points] Consider the Census Rounding Problem as deﬁned above. 3.000 7.v)∈E c(u. Each fractional number can be rounded either up or down. For example.998 9.000 55.1.000 4. v).000 55. Use a ﬂow computation to check if the desired rounding is possible. 3.14 Census Rounding [20 Points] You are consulting for an environmental statistics ﬁrm.000 2.000 children 1.000 0. 3.000 22.000 3. and you want to round each fractional number α to either α or α .

[3 Points] Argue that M-F-B-S returns a maximum ﬂow. 2. deﬁne the neighborhood of X as N(X) = y ∈ V (x. show that an augmenting path of capacity at least K can be found in O(E) time.2. where |L| = |R|. [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.1. [4 Points] Argue that the inner while loop of lines 5-6 is executed O(E) times for each value of K. 4. Every d-regular bipartite graph has |L| = |R|. where V = L ∪ R. E) be an undirected bipartite graph with vertex partition V = L ∪ R. For any X ⊆ V. the set of vertices adjacent to some member of X. E). Prove that every d-regular bipartite graph has a matching of cardinality |L| by arguing that a minimum cut of the corresponding ﬂow network has capacity |L|. [10 Points] We say that a bipartite graph G = (V.v)∈E c(u. 6. 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) 2 initialize ﬂow 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 ﬂow f along p } 7 K ← K/2 } 8 return f 3. that is. is d-regular if every vertex v ∈ V has degree exactly d. 5. [5 Points] For a given number K. t) 1 C ← max(u. s. y) ∈ E for some x ∈ X . 35 . [10 Points] A perfect matching is a matching in which every vertex is matched. Let G = (V. 3. [2 Points] Conclude that M-F-B-S can be implemented so that it runs in O(E 2 lg C) time. if such a path exists. The following modiﬁcation of F-F-M can be used to compute a maximum ﬂow in G. M-F-B-S(G.

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

.. [4 Points] Given two matchings M and M ∗ in G.. we treat a path as a sequence of edges. Argue that edges in each such simple path or cycle belong alternatively to M or M ∗ . Pk . let M be a matching in G.) In this problem. [4 Points] Show that if M is a matching and P is an augmenting path with respect to M. and its edges belong alternatively to M and E − M. but diﬀerent from.. Prove that if |M| ≤ |M ∗ |. P2 .. and let P1 . . then the symmetric diﬀerence M ⊕ (P1 ∪ P2 ∪ . E). where V = L ∪ R and all edges have exactly one endpoint in L. P2 . 2. (This deﬁnition of an augmenting path is related to. Given two sets A and B. the elements that are in exactly one of the two sets..1. . bipartite graph G = (V. 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.. ends at an unmatched vertex in R. The algorithm runs in O( V E) time. for ﬁnding a maximum √ matching in a bipartite graph.. M ⊕ M ∗ ) has degree at most 2. Let l be the length of a shortest augmenting path with respect to a matching M... . ∪ Pk ). Pk be a maximum set of vertex-disjoint augmenting paths of length l with respect to M. ∪ Pk ) is a matching with cardinality |M| + k. then M ⊕ M ∗ contains at least |M ∗ | − |M| vertex-disjoint augmenting paths with respect to M.possible to send both of his children to the same school. P2 . A shortest augmenting path with respect to a matching M is an augmenting path with a minimum number of edges. Let M = M ⊕ (P1 ∪ P2 ∪ . then the symmetric diﬀerence M ⊕ P is a matching and |M ⊕ P| = |M| + 1. . The general structure of our algorithm is the following: H-K(G) 1 M←∅ 2 repeat 3 let P ← {P1 . 1... [2 Points] Show that if P is vertex-disjoint from P1 . Conclude that G is a disjoint union of simple paths or cycles.. 3.. that is. rather than as a sequence of vertices. show that every vertex in the graph G = (V. Show how to formulate the problem of determining if both his children can go to the same school as a maximum-ﬂow problem. due to Hopcroft and Karp. 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. we describe a faster algorithm. an augmenting path in a ﬂow network. the symmetric diﬀerence A ⊕ B is deﬁned as (A − B) ∪ (B − A).. 3. Pk are vertexdisjoint augmenting paths with respect to M. Show that if P1 . Pk } be a maximum set of vertex-disjoint shortest augmenting paths with respect to M 4 M ← M ⊕ (P1 ∪ P2 ∪ .. and suppose that P is a shortest augmenting path with respect to M . the number of iterations in the repeat loop) and to describe an implementation of line 3.. .23 The Hopcroft-Karp Bipartite Matching Algorithm [20 Points] In this problem. P2 . Given an undirected. 37 . The professor has a map of his town.

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

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

- Kevin Chen and Erik Winfree- Error Correction in DNA Computing
- Binary Tree Sort is More Robust than Quick Sort in Average Case
- Open Shop Scheduling Problem
- Written Assignment1 Sample Solution
- Un Weighted Sc
- ieee-it-07.pdf
- 471-475
- Software Design
- k-select
- Brinza-Zelikovsky
- Update MCA Batch 2012 Syllabus--21!07!2014
- LimitsOnComputationLimits Nature 0814
- 02-dynprog
- Lecture 03
- 102 Uncertainity Principle
- 2E3Tutorial8solution
- COMP211slides_2
- cts cquestp
- On-Line Versus Off-Line Algorithms
- 002_dcProblems
- [IJET-V2I2P3]
- Com Bi National Genetic and Heuristic Algorithm for Bin Packing
- 03 Simplex Implementations
- Game Objects
- COMP2230_2008_4_1pp
- cs301 (1)
- வணக்கம் என் நண்பர்களே
- MELJUN_CORTES_JEDI Slides Data Structures Chapter04 Binary Trees
- Software Engineering Solved Mcqs
- Introduction to Decision Trees

Read Free for 30 Days

Cancel anytime.

Close Dialog## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

Loading