Sunteți pe pagina 1din 3

CSE 3315 - Theoretical Concepts Homework 6: P and NP

CSE 3315 - Theoretical Concepts


Homework 6- Solution - Fall 2000 Due Date: Dec. 6 2000, 5:30 pm

This algorithm makes iterations (one for each in ). In each iteration it removes one symbol from the rst number string and makes a copy of the second number string. This requires moving the read head to the beginning of the input string and then moving it across once. The complexity of , making the total complexity of the algorithm since . each iteration is thus b) Binary subtraction can be solved in a way analogous to binary addition. Using a three-tape Turing machine rst copies the second number to tape and adds s to the shorter of the numbers to make them the same length. Then, starting with the least signicant bit, subtraction is performed bitwise with the carry bit represented in the state of the Turing machine. Assuming state represents the presence of no carry bit and represents the state in which there is a carry bit, subtraction is performed as follows:
 # " " &)# ( $ %# ' " & $ %#    !          

For each bit this subtraction requires a constant number of time steps. The initial copying of the second number requires steps. Therefore, the overall algorithm has complexity and is thus polynomial.
       

c 2000 Manfred Huber

"

"

"

"

"

"

"

&)# (

&)# (

4 &# $

" 1)# (

" 0# 2

"

"

2 #

2 #

2 #

'

'

'

'

'

'

'

'

'

'

'

" &

"

"

' 03# (

'52%# 

" 0%# $

"

"

"

$ %#

$ #

1.

a) Unary multiplication can be performed by means of successive addition. The following two-tape Turing machine does this in polynomial time: 1. Check if the rst number string (initially ) is empty. a) If it is empty the multiplication is nished and the Turing machine halts. 2. Erase the rst from the rst number string. 3. Append a copy of the second number string ( ) to the string on tape . 4. Go to step 1.

Page 1

CSE 3315 - Theoretical Concepts Homework 6: P and NP

c) The transition table of an indirected graph contains a list of all vertices and edges of the graph. To nd out if the graph is connected it is sufcient to check if all nodes are reachable from a given start node (since the graph is undirected this implies that there is a path from every node to every other node). To determine this, a two-tape Turing machine can be used to execute the following algorithm. 1. Copy the rst vertex from the transition table on tape to tape . 2. For all edges that are connected to the the selected vertex, check if the vertex at the other end of the edge is already on tape . If it is not, add it to the list on tape . 3. Go to the next vertex in the list on tape and repeat until no new vertices are added to the list on tape (this list now contains all vertices that can be reached from the rst vertex). 4. Check if the list on tape contains all vertices of the graph. Finding all vertices that are directly connected to a given vertex and adding them to the list on the second tape takes time steps. Checking if all vertices are in the list takes steps. Since there are at most vertices, the overall complexity of the algorithm is and thus polynomial. . A sentence of d) Sentences in disjunctive normal form are of the form length has fewer than conjunctive terms, each of which contains fewer than propositions. To show that a given sentence is satisable it is sufcient to show that one of the conjunctive terms to be not satisable it has to contain is satisable. For a conjunctive terms of the form a contradiction (i.e. a literal and its negation ). To test satisability we can thus use the following algorithm: 1. Go to the rst conjunctive term. 2. Check if the conjunctive term contains a pair of literals of the form and . a) If it does not, the sentence is satisable. b) Otherwise, go to the next conjunctive term and repeat step 2. If there are no more conjunctive terms, the sentence is not satisable. To check for a contradictory pair of propositions in a conjunctive term requires to check the whole term once for each proposition. This takes time . This procedure has to be performed at times. The overall complexity is thus . most
    2          9 GE 9    777 S 777 C777 C777 S 777 C H 9 E C A 9 QQPTRQQWVQQPQQQDUTRQQP)IGFDB@ H 9 bGE 777 C Y 9 C A 9 RQQa`X)B@ H I9            2              7 8

c 2000 Manfred Huber

Page 2

CSE 3315 - Theoretical Concepts Homework 6: P and NP


c 6

b) For this problem, the algorithm rst nondeterministically picks two integers and , both of which is an inverse, so would be ). The length of each of these have to be smaller than (if numbers is thus less than . To verify that these are the right numbers the algorithm multiplies and . Then it multiplies and and adds to the result. In a last step it compares the results of both calculations. If they are the same, then is the inverse modulo of . Each multiplication takes time steps (see time steps and the overall complexity of verication 1.a or example in class). Addition takes is therefore Since the nondeterministic generation of a solution and the verication are both polynomial time on a nondeterministic Turing machine, the overall algorithm is nondeterministic polynomial time. c) A cycle can be written as a sequence of vertices that starts and ends with the same vertex and that does not include any other vertex more than once. To generate a cycle the algorithm thus nondeterministically generates a sequence of vertices with a maximum length of . To verify that this is a correct solution to the problem the algorithm then checks if the number of vertices in the cycle is exactly half the number of vertices in the graph. This requires to go over all vertices in the transition table and can be performed in steps. Then it has to be veried that all edges in the cycle (i.e. an edge between every pair of consecutive vertices in the sequence) exist in the transition table of the graph. This again requires checking every edge in the cycle (at most ) against all the transition table, and thus requires time steps. This makes the verication algorithm Since the nondeterministic generation of a solution and the verication are both polynomial time on a nondeterministic Turing machine, the overall algorithm is nondeterministic polynomial time.
                        s s       9 9 h w yx9     h t vu9          9

c 2000 Manfred Huber

Page 3

          

   

 r    

e fd

2.

a) To show that a problem is in the algorithm rst nondeterministically picks a solution (in polynomial time) and then veries the solution (in polynomial time). For this problem a solution (or more precisely the string that lets us verify the existence of a solution) is a set of different integers, each of which is no larger than (every number that is the product of more than integers is also the product of exactly integers). To pick one of these numbers and to pick numbers is therefore . requires time To verify that the integers are a correct factorization of the input, the algorithm multiplies the ve numbers and then compares the result to the input. Multiplication of 2 integers of size and has complexity (for both unary and binary representations - see 1.a or the example in class). To multiply 5 integers the algorithm multiplies the rst two, multiplies the result with the third integer, . The length of the result is less than and so on. The complexity of the rst multiplication is . The second multiplication therefore has complexity . All ve multiplications have . Comparing the result with the input is , and the overall verication thus complexity can therefore be done in time steps. Since the nondeterministic generation of a solution and the verication are both polynomial time on a nondeterministic Turing machine, the overall algorithm is nondeterministic polynomial time.
   r    h ' qpi@     g g    

S-ar putea să vă placă și