Farley Lai, 00764474

Theory of Computation, Homework 5 7.6 i.) union Without loss of generality, let  M 1  and  M 2  be  the  TMs that decide two languages   L1  and  L2  in P. Then we construct a TM  M  that decides the union of  L1  and  L2  in polynomial time. M = ”on input  w 1. Run  M 1  on  w . Accept if it accepts. 2. Run  M 2  on  w . Accept if it accepts. 3. Otherwise, reject.” Since stage1 and stage2 both run in polynomial time, TM  M  can decide the union of  L1  and  L2 in polynomial time. Hence,  P  is closed under union. ii.) concatenation Without loss of generality, let  M 1  and  M 2  be  the  TMs that decide two languages   L1  and  L2  in P. Then we construct a TM  M  that decides the concatenation of  L1  and  L2  in polynomial time. M = ”on input  w 1. For each possible split of  w = w1 w2 a. Run  M 1  on  w1  and run  M 2  on  w2 . Accept if  both accept. 2. Otherwise, reject.” Assume the  jwj = n . There are  O(n)  possible splits of  w  at most. Besides, the sum of the time complexities of  M 1  and  M 2  is also polynomial. Thus, step1 run in polynomial time and TM  M can decide the concatenation of  L1  and  L2  in polynomial time. Hence,  P  is closed under concatenation. iii.) complement Without loss of generality, let  M  be  the  TM that decides a language   L  in P. Then we construct a TM  M 0  that decides the complement of  L  in polynomial time. M 0 = ”on input  w 1. Run  M  on  w 2. Accept if it rejects. Otherwise, reject if it accepts.” Since step1 run in polynomial time, TM  M 0  can decide the complement of  L  in polynomial time. Hence,  P  is closed under complement.

7.7 i.) union Without loss of generality, let  N 1  and  N 2  be  the  NTMs that decide two languages   L1  and  L2 in NP. Then we construct an NTM  N  that decides the union of  L1  and  L2  in polynomial time. N = ”on input  w 1. Run  N 1  on  w  nondeterministically. Accept if it accepts. 2. Run  N 2  on  w  nondeterministically. Accept if it accepts. 3. Otherwise, reject.” Since stage1 and stage2 both run in polynomial time nondeterministically, NTM  N  can decide the union of  L1  and  L2  in polynomial time. Hence,  N P  is closed under union. ii.) concatenation Without loss of generality, let  N 1  and  N 2  be  the  NTMs that decide two languages   L1  and  L2 in NP. Then we construct an NTM  N  that decides the concatenation of  L1  and  L2  in polynomial time. N = ”on input  w 1. For each possible split of  w = w1 w2 a. Run  N 1  on  w1  nondeterministically and run  N 2  on  w2  nondeterministically. Accept if  both accept. 2. Otherwise, reject.” Assume the  jwj = n . There are  O(n)  possible splits of  w  at most. Besides, the sum of the time complexities of  N 1  and  N 2  is also polynomial. Thus, step1 run in polynomial time and NTM  N can decide the concatenation of  L1  and  L2  in polynomial time. Hence,  N P  is closed under concatenation. 7.12 Since  ab  is exponential in the length of  b , we need to break down  ab  and apply the modulo operation several times so that the resulting size never goes exponential. First,  we treat  b  in its binary representation. There are at most  log2 b  bits. So log log Q2b b 2 i Q2b bi2 i ab mod p = ( a i ) mod p = ( (a mod p)) mod p i

i

In the worst case, we assume  bi = 1  for all  i . However,

abi+12 mod p = (abi2 )2 mod p = (abi2 mod p)2 mod p:  That is, each term can be computed by squaring the remainder of the previous term  mod p . Hence, for each modulo operation, the computation is  O(p 2 )  which is in polynomial time. Additionally, for each multiplication of neighboring terms, we also apply the modulo operation in  O(p 2 ):  Since there are at most  log2 b terms,  ab Ñ c (mod p)  is  O(2log2 b p 2 ):  Therefore,  M ODEXP 2 P : i+1

i

i

7.16 1.) In the proof of theorem 7.56, the SUBSET­SUM problem instance constructed contains numbers of large magnitude presented in decimal notation. However, compared with binary/decimal encoding, unary encoding will grow the input size exponentially. Therefore, the reduction to generate the corresponding input for UNARY­SSUM will require a number of steps that is exponential in the size of the input, taking more than polynomial time. The proof fails. 2.) SUBSET À SUM  is in  P because the following polynomial time algorithm based on dynamic programming solve the problem. Input:  (S; t) , where  S = f x1 ; x2 ; :::; xkg Variables: Integers  i; j; l[0::k][0::t] , all are initialized to 0 l[0][0]← 1 ; f or i = 1 to k do f or j = 0 to t À xi do if l[i À 1 ][j] = 1 then l[i][j + xi] ← 1; od od if l[k][t] = 1 then accept else reject; 7.17 Assume that  P = N P :  Let  B 2 P  but  B = = ¶  and  B = = ÆÃ  such that there exist a string waccept 2 B  and a string  wreject 2 = B . To show  B  in  P = N P  is NP­complete, let  A  be an arbitrary language in  P = N P . Therefore,  A  can be decided by a polynomial time decider  M A . Next, we show a polynomial time reduction  M  from  A  to  B  as follows. M = ”On input  w : 1. Run  M A  on  w . 2. If  M A  accepts then output  waccept . If  M A  rejected then output  wreject .” Obviously, there exists a polynomial time reduction from  A  to  B . Hence  B  is NP­complete.

7.20 a.) SP AT H  is in P because the following TM  M  can decide it in polynomial time. M = “On input  ⟨G; a; b; k⟩  where  G  is a graph with  n  nodes, two which are  a  and  b: 1. Mark node  a  0 2. For each  i  from 0 to  n : a. If an edge  (s; t)  is found connecting  s  marked  i  to an unmarked node  i , mark node  t  with  i + 1 . 3. If  b  is marked with a value of at most  b , accept. Otherwise, reject.” b.) LP AT H 2 N P  because a path from  a  to  b  can be guessed by an NTM nondeterministically and checked if its length is at least  k  in polynomial time. Next, we show  U HAMP AT H Ôp LP AT H  by constructing a TM  F  that computes the reduction  f . F = “On input  ⟨G; a; b⟩  of  U HAMP AT H , where  G  is a graph with two nodes  a  and  b: 1. Let  k  be the number of nodes of G. 2. Output  ⟨G; a; b; k⟩  as an instance of  LP AT H ” If  ⟨G; a; b⟩ 2 U HAMP AT H  , then  G  has a Hamiltonian path of length  k  from  a  to  b . That is, ⟨G; a; b; k⟩ 2 LP AT H  . On the other hand, if  ⟨G; a; b; k⟩ 2 LP AT H , then  G  must contain a simple path of length  k  from  a  to  b . However, since  G  has only  k  nodes, the path must be Hamiltonian. There,  ⟨G; a; b⟩ 2 U HAMP AT H:  Hence,  U HAMP AT H Ôp LP AT H: According to the above,  LP AT H  is NP­Complete.

7.21 i.)  DOUBLE À SAT 2 N P On input of a Boolean formula, an NTM could guess two different Boolean assignments nondeterministically and accept if both of the assignments satisfy the formula. Hence, DOUBLE À SAT  is in  N P : ii.)  DOUBLE À SAT  is NP­hard SAT  can be reduced to  DOUBLE À SAT  by constructing a TM  F  that computes the reduction f  as follows. F = ”On input of a Boolean formula  (¶)  with variables  x1 ; x2 ; :::; xk 1. Let  ¶0 = ¶ ^ (x _ x)  by introducing a new variable  x 2. Output  (¶0)  with variables  x1 ; x2 ; :::; xk; x ” If  ¶ 2 SAT , its satisfying assignment plus  x = true  or  x = true  can serve as the two satisfying assignments of  ¶0:  On the other hand, if  ¶0 2 DOUBLE À SAT  is satisfiable,  ¶  can be satisfied by the assignment where the new variables  x  and  x  are removed. Therefore, DOUBLE À SAT  is NP­hard. According to i. and ii.,  DOUBLE À SAT  is NP­Complete. 7.24 a.) In a clause of an  = = assignment, there is one literal set true or two literals set true. Thus, the negation of a the clause will still induce a clause with one literal set true or two literals set true. Since a negated clause is also a clause of an  = = assignment, the negation of an  = = assignment is too an  = = assignment. b.) Let  ¶  be a 3cnf­formula of an instance of  3 SAT  and  ¶0  be a 3cnf­formula of an instance of = = SAT :  The reduction of replacing a clause  ci (y1 _ y2 _ y3 )  of  ¶  with two clauses (y1 _ y2 _ zi) ^ (zi_ y3 _ b)  of  ¶0  can be computed in polynomial time for sure. Next, we show  ¶ is satisfiable iff  ¶0  has the corresponding  = = assignment. If  ¶  is satisfiable, either  y1 = ture  and  y2 = ture , or only  y3 = true . In the former case, set  zi false. In the latter case, set  zi  true. In any case,  b  is set false. On the other hand, if  ¶0  has an = = assignment,  y1 ; y2  and  y3  cannot all be set false since this may cause one of the clauses in the  = = assignment to be false. Thus, the corresponding clause  (y1 _ y2 _ y3 )  must be true. A satisfying assignment of  ¶  is then derived. c.) Obviously,  = = SAT  is in NP because an NTM can guess an  = = assignment and check if it satisfies the formula nondeterministically in polynomial time. According to the reduction in b, = = SAT  is concluded to be NP­Complete.

7.28 i.)  SET À SP LIT T ING 2 N P On input of  (S; C) , where  S  is a finite set and  C = fC 1 ; C 2 ; :::; C kg  is a collection of subsets of  S , for some  k > 0 , an NTM could guess a coloring of the elements nondeterministically and accept if no  C i  has all its elements colored with the same color. Hence,  SET À SP LIT T ING is in  N P : ii.)  SET À SP LIT T ING  is NP­hard 3 SAT  can be reduced to  SET À SP LIT T ING  by constructing a TM  F  that computes the reduction  f  as follows. F = ”On input of a 3CNF Boolean formula  (¶)  with  l  clauses and variables x1 ; x1 ; x2 ; x2 ; :::; xk; xk 1. Set  S = f x1 ; x1 ; x2 ; x2 ; :::; xk; xk; zg 2. For each clause  ci  in  ¶ , add a subset  C i  of  S  including  z  and the literals in  ci  as the elements. 3. add a subset  C xi  for each pair of  xi and xi ” Clearly,  C = f C 1; C 2; :::; C l; C x1; C x2; :::; C xk; g: If  ¶ 2 SAT , its satisfying assignment can serve as a coloring of  (S; C)  by coloring all the true literals red and all the false literals as well as  z  blue such that each subset  C i  has at least one blue element  z  and one red literal which has a true assignment. For subset  C xi , the pair of literals  xi and xi  must be colored exactly red for one and blue for the other. Obviously, (S; C) 2 SET À SP LIT T ING: On the other hand, if  (S; C) 2 SET À SP LIT T ING  has a coloring,  ¶  can be satisfied by the assignment where red literals are set true while blue literals are set false. Therefore, SET À SP LIT T ING  is NP­hard. According to i. and ii.,  SET À SP LIT T ING  is NP­Complete.