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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3. 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. 2. and that this check takes poly time. Prove that if G is an undirected bipartite graph with an odd number of vertices. 27 . Show that knowing this tree of primitive roots can be checked to be correct and used to show that n is prime. 2. 2. Hint: -NP is easy (what’s a certiﬁcate for showing that a number is composite?).25 Polynomial time Hmiltonian path 1. 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. 2. and the ‘gadget’ in ﬁgure 2.3.23 Primality and Complexity Prove that PRIMALITY (Given n. 3. consider a certiﬁcate involving primitive roots and recursively their primitive roots. but that a polynomial number of calls to polynomial-time subroutines may result in an exponential-time algorithm.3.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.Figure 2.3.22 DEGREE-4-PLANAR-3-COLOR Using the previous result. 2.22. Figure 2. is n prime?) is in NP ∩ -NP. Give a polynomial time algorithm algorithm for ﬁnding a hamiltonian cycle in an undirected bipartite graph or establishing that it does not exist.1: Gadget for PLANAR-3-COLOR. 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. then G is nonhamiltonian. 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.

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

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

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

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

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

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

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

where |L| = |R|. Every d-regular bipartite graph has |L| = |R|. [10 Points] We say that a bipartite graph G = (V. [3 Points] Argue that M-F-B-S returns a maximum ﬂow. The following modiﬁcation of F-F-M can be used to compute a maximum ﬂow in G. E) be an undirected bipartite graph with vertex partition V = L ∪ R. 5. 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. 35 . [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. [4 Points] Argue that the inner while loop of lines 5-6 is executed O(E) times for each value of K. s. 2. 4. Let G = (V. M-F-B-S(G. E). the set of vertices adjacent to some member of X. is d-regular if every vertex v ∈ V has degree exactly d. that is. 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|. Prove Hall’s theorem: there exists a perfect matching in G if and only if |A| ≤ |N(A)| for every subset A ⊆ L. t) 1 C ← max(u.1.17 Perfect Matching [20 Points] 1. 3. [2 Points] Conclude that M-F-B-S can be implemented so that it runs in O(E 2 lg C) time. where V = L ∪ R. y) ∈ E for some x ∈ X . if such a path exists. 6. [5 Points] For a given number K. For any X ⊆ V.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.v)∈E c(u. [10 Points] A perfect matching is a matching in which every vertex is matched.

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

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

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

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

- Recur
- CS Algorithms Cheatsheet
- MELJUN CORTES Automata Theory 21
- multiproject waffers
- Ec6301 - Object Oriented Programming and Data Structure
- 6201 Scheduling 2
- Data Structure Lec16 Handout
- Algorithms 1
- Computational Geometry and Computer Graphics in c++.pdf
- Computer Science-Lecture 8-More Math Issues
- npcomplete
- Ds Assignment
- Disinformation
- 02-asymp
- game theory
- 15-btrees
- documentation
- Paper_Routing in Cognitive Radio Network_Challenges and Solution
- Populating a TreeView Control from a List -Deborah's Developer MindScape.pdf
- 10-Gcd
- Slides
- Types of Binary Tree
- A Two-Layer Hierarchical Permission Based Mutual Exclusion Algorithm
- Data Structure
- A Survey on the Traveling Salesman Problem
- i2ml2e-chap9-v1-0
- BPlus Tree
- Lecture 06 Ch6.Trees(1)
- Chen 2017
- Chess Vis 14

Sign up to vote on this title

UsefulNot usefulClose Dialog## Are you sure?

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

Close Dialog## This title now requires a credit

Use one of your book credits to continue reading from where you left off, or restart the preview.

Loading