Sei sulla pagina 1di 2

ECS 120: Theory of Computation UC Davis Phillip Rogaway

Handout 9S March 14, 2002

Problem Set 10 Solutions


Problem 1. Let INFINITE = { M : M is a TM and L(M ) is innite}. Let REGULAR = { M : M is a TM
and L(M ) is context free}. Show that INFINITE m REGULAR.

Given M we must create, by way of a Turing-computable function f , a TM encoding M is nite i L(M ) is context free. Machine M works as follows: 1 M on input x: 2 If x = an bn cn , for some n, then accept 3 By dovetailing, for every (y, t) where w x (in lexicographic order) and t N do 4 Run M on y for t steps. 5 If M accepts y within this amount of time, then accept

where L(M )

If L(M ) is innite then lines 35 are guaranteed to accept, regardless of x, and so L(M ) = {0, 1} , which is innite. IF L(M ) is nite then it has some last string z , according to the lexicographic ordering. Lines 35 will not accept any string exceeding z . So L(M ) will be a nite set unioned together with {an bn cn : n C }, for some constant C . This language is not context free. Problem 2. Suppose you are given a polynomial time algorithm which, on input of a Boolean formula , decides if is satisable. Describe an ecient procedure which nds a satisfying assignment for . Let the variable of be x1 , . . . , xn . We build a satisfying assignment t for as follows: T F , where T and F are new variables. for i 1 to n do Let be with every occurrence of xi replaced by the variable T . Ask the decision procedure if is satisable If it is, replace by and dene t(xi ) = true Otherwise, replace by with every occurrence of xi replaced by F , and let t(xi ) = false return t as a satisfying truth assignment We make exactly n calls to our polynomial-time decision procedure, and each call is on a formula whose size is almost the same as the size of , so this is an ecient way to nd a satisfying assignment to . Problem 3. p. 272, problem 7.19. First, it is easy to see that DOUBLE-SAT NP. On input of a Boolean formula , a verier could guess two Boolean assignments, t1 and t2 , and then verify that these assignments are dierent from one another and that each satises . In other words, the certicate consists of distinct satisfying assignments t1 and t2 . To show that DOUBLE-SAT is NP-hard, we show that SAT P DOUBLE-SAT. The function f which maps an instance of SAT to an instance of DOUBLE-SAT works as follows: = (x1 x2 ), where the x1 and x2 are new variables (they dont occur in ). This reduction is certainly polynomial time. Now if is unsatisable, certainly is, too, since we have only conjuncted an additional term. But if has some satisfying assignments t, than has at least three (and therefore at least two) satisfying assignments, (corresponding to the three dierent ways of extending t to the new variables x1 and x2 .

ECS 120 Handout 9S: Problem Set 10 Solutions

Problem 4. Page 274, Problem 7.26. Each card can be described by a pair of lists of numbers, ((L1 , . . . , Ll ), (R1 , . . . , Rr )) where a hole is drilled at each left-position Li and right-position Rj . For example, the card in the picture on Page 240 could be described by ((1, 2, 3, 4, 5), (1, 5, 6)). It could also be described by ((1, 5, 6), (1, 2, 3, 4, 5)). Given a collection of such descriptions, a nondeterministic TM needs only to guess how to order each ordered pair (i.e., how to orient each card) so as to make sure that no number x occurs in every left column, and no number x occurs in every right column. Certainly this check is in polynomial time, so PUZZLE NP. Now we show 3SAT P PUZZLE. (We could also, and rather more easily, have done this using =SAT.) Let = C1 C2 Cm be a 3CNF formula over variables {x1 , . . . , xn }. We will map to n + 1 cardsone card ci per variable xi , plus one special card, c . Each card will have m rows of potential holes, each hole being either a left-hole or a right-hole. That is, theres one row for every clause. Card ci contains holes except at the following locations. For each 1 j m, if xi appears in clause Cj , ll in (ie., put no hole) at the left column of row j . Similarly, if xi appears in clause Cj , ll in (ie., put no hole) at the right column of row j . The special card c has every possible left-hole drilled out, and has every possible right-hole lled in. Claim 1: The mapping f from to f () = (c1 , . . . , cn , c ) is polynomial time. This is obvious. Claim 2: If is satisable, then f () = (c1 , . . . , cn , c ) = f () PUZZLE. Let t be a satisfying truth assignment for . For each variable xi , if t(xi ) = 1 then orient card ci with the left column on the left; else, orient card ci with the left column on the right. Always orient the special card with the left column on the left (ie., the lled-in column on the left). Then every right hole is covered up by virtue of c , while every left hole is covered because the left hole corresponding to clause Cj is covered up by a card ci , where xi or xi is in Ci and t assigns this literal to be true. Claim 3: If f () = (c1 , . . . , cn , c ) PUZZLE, then is satisable. If the special card, c , has its left column on the right, then ip over the entire stack of cards so that the lled-in column of c will now be on the right. We can now read a satisfying truth assignment right o the the orientation of the remaining cards. Namely, if card ci is oriented with its left-column on the left, set t(xi ) = 1; else set t(xi ) = 0. To check that this assignment works to satisfy , note that every clause Cj corresponds to some row j , and the left-hand hole of row j is covered up by some card ci , and ci has xi has now been assigned the correct truth value so as to make Cj evaluate to true.

Potrebbero piacerti anche