• No results found

Theory of Computation

N/A
N/A
Protected

Academic year: 2020

Share "Theory of Computation"

Copied!
28
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

The Class NP

Polynomial Time verifiers Examples of Problems in NP

(3)

Let us start by looking at the following simple (and very important) non-deterministic TM. The transition function of this machine is given by

δ(q0, 1) = {(q0, 0, R), (q0, 1, R)}

δ(q0, ) = {(qa, , R)}.

Let us call this TM G (which stands for guessing). What will happen if we run this TM on input 0n.

(4)

Since, it is a non-deterministic TM the computation is given by a computation tree. Let us look at the computation tree.

Here n = 3.

(5)

As, you can see each leaf configuration had a string of 0/1 written on the tape. This machine seems to be going through all possible 0/1 at the same time. As, if it was guessing a 0/1 string of length n.

By using G as a subroutine we can make guesses. This is the power of non-determinism.

(6)

Let us now look at an example of a problem that is in NP. Define

COMPOSITE = {hni|n = pq for some ingeters p, q > 1} To show that this problem in NP we have to show a non-deterministic machine that accepts all composite numbers given in binary.

Here is the TM

1 On input hni let k be the number of bits in n.

2 Use G to guess a k-bit number p.

3 Use G to guess a k-bit number q.

4 If pq = n and p, q > 1 then accept. Else reject.

(7)

Suppose we give this machine 15 in binary. When we run G it will branch off and each branch will guess a 4 bit number. One of those branches will guess 3. So p = 3. Similarly, when we run G again it will branch off and each branch will guess a number and one of them will be 5. This particular branch will accept. Thus by definition 15 will be accepted.

(8)

Suppose we give this machine 13 in binary. When we run G it will branch off and each branch will guess a 4 bit number. So every branch will have a p. Similarly, when we run G again it will branch off and each branch will guess a number and every branch will have a q. No branch will accept. Because, the condition

13 = pq and p, q > 1

cannot be satisfied for any p, q. Thus 13 will be rejected.

(9)

A moments thought shows that

every composite will be accepted by some branch. and

every prime will be accepted by all branches.

Thus this NTM accepts COMPOSITES. It is easy to see that the length of any branch is polynomial in the number of bits in hni. Thus this is a non-deterministic polynomial time algorithm that accepts composites.

(10)

Let us look at another problem in NP. Let

HAMPATH = {hG , s, ti : G has a hamiltonian path}

We will show that this problem is in NP. Let us recall that given a digraph G . A hamiltonian path in G is a path that visits each vertex exactly once.

(11)

Here is a graph with a hamiltonian path from s to t. Show picture of a graph.

(12)

This graph does not have a hamiltonian path from s to t.

(13)

Here is a NTM that accepts HAMPATH:

1 On input hG , s, ti. Let n be the number of vertices in G .

2 Guess v1, . . . , vn a sequence of n vertices of G using the guessing

machine.

3 Check if all vertices are distinct. 4 Check if v1 = s.

5 Check if vn= t.

6 for i = 1, . . . , n − 1 check if (vi, vi +1) is an edge in G . 7 If all conditions are satisfied accept else reject.

(14)

A moments thought shows that

If G has a hamiltonian path from s to t then at least one branch will accept.

and

If G does not have a hamiltonian path from from s to t no branch will accept.

Thus this NTM accepts HAMPATH. It is easy to see that the length of any branch is polynomial n. Thus this is a non-deterministic polynomial time algorithm that accepts HAMPATH.

(15)

Let A be a language. A verifier for a language A is an algorithm (Turing machine) V such that

A = {w |V accepts hw , ci for some string c}. Thus a verifier V

1 Takes two inputs hw , ci.

2 c is called the certificate or proof.

3 It accepts an hw , ci if c is a correct proof of the fact that w ∈ A.

We measure the time running time of a verifies only in terms of |w |. We say that V is a polynomial time verifier if it runs in time polynomial in |w |. If A has a polynomial time verifier then we say that it is polynomial time

(16)

Composites is polynomial time verifiable. Here is a verification algorithm.

1 On input < n, (p, q) > 2 Check if p ≤ n else reject. 3 Check if q ≤ n else reject. 4 Check if p, q > 1 else reject. 5 Check if p × q = n else reject.

6 accept.

Note that if someone has found a factorization of a number n then it is easy for them to convince anyone that the number is composite. Thus the factorization of n is a easily verifiable proof that the number is composite.

(17)

HAMPATH is polynomial time verifiable. Here is a verification algorithm.

1 On input

< G , s, t, (v0, . . . , vn) >

2 Check if v0 = s. 3 Check if vn= t.

4 Check if all vi’s are distinct and each vertex of G appears in the list. 5 for i = 1 to n − 1 check if (vi, vi +1) are connected with an edge of G .

(18)

NP is the class of languages that have polynomial time verifiers. NP is the class of languages that are decided by polynomial time non-deterministic Turing machies.

We want to show that these two definitions are equivalent.

(19)

For now let us define:

NP1 is the class of languages that have polynomial time verifiers.

NP2 is the class of languages that are decided by polynomial time

non-deterministic Turing machines.

(20)

Let L be a language in NP1 and V be a (polynomial time) verifier for L.

Consider the following non-deterministic TM. Let us say V runs in time dnk.

1 On input w of length n.

2 Guess a certificate c of length atmost dnk

3 Run V on hw , ci

4 if V accepts accept else reject.

This is a non-deterministic TM. It runs in time O(nk). Now, if w ∈ L then there at least one certificate c such that V accepts hw , ci. Thus if w ∈ L at least one branch of M will accept w .

(21)

If w 6∈ L then no branch of M will accept w . This shows that L is in NP2.

(22)

Now, we will show that if L is in NP2 then L is in NP1. Let L be in NP1

then there is non-deterministic TM M that accepts L. M runs in time dnk. Let w ∈ L. What is the way to prove that w ∈ L. We can try to prove that M accepts w . But how?

(23)

Note that a NTM can make a choice at every step. There will be at most b possibilities for each choice. Suppose we take a string of the form

1311 · · ·

This string tells us to make choice number 1 in the first step. Choice number 3 in the second step and so on...

Now, let us consider the following verifier for L.

1 One input hw , ci 2 Check if |c| ≤ dnk .

3 Simulate M on w by making the choices dictated by c.

(24)

Now, we can remove the subscripts that we had put on these classes since we have shown they are the same.

NP is the class of languages that have polynomial time verifiers. NP is the class of languages that are decided by polynomial time non-deterministic Turing machines.

(25)

Let us define

CLIQUE = {hG , ki|G has a clique of size k}.

Here G is an undirected graph. Let us recall the definition of a clique. A clique S is a set of vertices which are all connected to each other. Here is a picture of a clique.

(26)

Here is a graph with a clique of size 4 in it. We have bolded out the clique vertices.

(27)

Is CLIQUE in NP?

You should think of making a verifier. What would be a good proof that a graph has a clique of size k?

(28)

The vertices of the clique themselves are the best possible proof.

References

Related documents

For employees performing Class I asbestos jobs involving more than 25 linear feet or 10 square feet of asbestos-containing or presumed asbestos-containing thermal insulation

• If the passport issued to you in the last FIVE years has been lost, stolen, damaged, destroyed or is inaccessible, you must include with this application form a

boundary symbol #, is the center top cell of a window. center cell of window is a non-state symbol and not adjacent to a state symbol. Case 2.. CLAIM:

The thesis aims are 1) to understand what affects to our travel behaviour and transport mode choices, 2) to understand the travel related symbolic, affective and social user

All bidders agree to provide all such additional information if, and when requested, at their own expense, provided no bidder in supplying any such information shall be allowed, in

Increase investment in producer cooperatives to ensure growth in rural incomes through entrepreneurship knowledge and skills to achieve income and food secure

Diane Fish requested the trial court impute full-time income to Jeffrey

Then by induction there is an NFA accepting the language denoted by S that has a single start state with no incoming edges and a single final state with no outgoing edges (see