the class np lecture 20 section 7.3 mon, nov 27, 2006

24
The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

Upload: clarissa-nash

Post on 18-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The Class NP

Lecture 20Section 7.3

Mon, Nov 27, 2006

Page 2: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

Nondeterministic Algorithms

• When we solve a problem nondeterministically, we do not just magically write down the solution.

• We must be able to• Generate the solution in polynomial

time, and• Verify the solution in polynomial time.

Page 3: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The COMPOSITES Problem

• The COMPOSITES Problem: Given an integer m, determine whether it is composite.

• The integer m is composite if there exist integers a and b, both greater than 1, such that m = ab.

Page 4: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The COMPOSITES Problem

• How do we generate a solution in polynomial time?

• Let n be the length of the integer, in bits.

• To choose a divisor a, we choose n bits to create the binary representation of a.

Page 5: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The COMPOSITES Problem

• Then do the same for b.• That can be done in polynomial

time.• How do we verify that m = ab?• We just multiply a times b and

compare to m.• That too can be done in polynomial

time.

Page 6: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

Verifiers

• A verifier for a language A is an algorithm V such that

A = {w | V accepts w, c for some string c}.

• c is a string containing additional information needed for verification.

• c is called a certificate.

Page 7: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

Verifiers

• The language of the COMPOSITES problem is

{m | m is composite}.• The verifier is a Turing machine

that accepts m, a, b whenever m = ab.

Page 8: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The Class NP

• A potential solution to a problem is verifiable in polynomial time if the verifier V is a polynomial-time Turing machine.

Page 9: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The Class NP

• The class NP is the class of all languages whose members can be generated in polynomial time and that have polynomial-time verifiers.

Page 10: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The Class NP

• Let NTIME(t(n)) be the set of all languages that are decidable nondeterministically in time O(t(n)).

• Then

0

)(NTIMENPk

kn

Page 11: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The choose() Function

• We will assume that we have available the following three functions.• accept()• reject()• choose()

Page 12: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The choose() Function

• The function accept() outputs “accept.”

• The function reject() outputs “reject.”

• The function choose() takes a set S as its parameter.

Page 13: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The choose() Function

• The size of S must be polynomial in n.

• If there is a choice of values from S that will eventually lead to calling accept() and a choice that leads to calling reject(), then choose() will choose a value that leads to accept().

Page 14: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The choose() Function

• If there is no such choice, i.e., every choice leads to accept() or every choice leads to reject(), then choose() will choose a random value from the set S.

Page 15: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The COMPOSITES Problem

COMPOSITE(m){ a = 0; b = 0;// Generate values for a and b for (i = 1; i <= n; i++) { a = 2*a + choose({0, 1}); b = 2*b + choose({0, 1}); }// Verify the choice if (m == a*b) accept(); else reject();}

Page 16: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

• This is programming as it was meant to be.

Page 17: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

Examples of NP Problems

• Some NP problems• CLIQUE• VERTEX-COVER• SUBSET-SUM• SAT• 3SAT

Page 18: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The CLIQUE Problem

• Given a graph G, a clique of G is a complete subgraph of G.

• The CLIQUE Problem: Given a graph G and an integer k, does G contain a clique of size k?

• Let n be the number of vertices in G.

Page 19: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

A CLIQUE AlgorithmCLIQUE(G, k){// Generate a clique C = {}; for (i = 1; i <= n; i++) if (choose({true, false}) Add vertex i to C;// Verify the clique if (size of C != k) reject(); for (i = 1; i <= k; i++) for (j = 1; j <= k; j++) if (i != j && (C[i], C[j]) E) { reject(); exit(); } accept(); }

Page 20: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The VERTEX-COVER Problem

• Given a graph G, a vertex cover of G is a set of edges S of G such that every vertex of G is incident to an edge in S.

• The VERTEX-COVER Problem: Given a graph G and an integer k, does G have a vertex cover of size k?

Page 21: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

A VERTEX-COVER Algorithm

VERTEX_COVER, k){// Generate a vertex cover C = {}; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) if (choose({true, false}) Add edge(i, j) to C;// Verify the vertex cover if (size of C != k) reject(); for (i = 1; i <= n; i++) for (j = 1; j <= k; j++) { if (vertex i is incident to C[j]) continue; } accept(); }

Page 22: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The SUBSET-SUM Problem

• The SUBSET-SUM Problem: Given a set S = {a1, a2, …, an} of integers and an integer k, does there is a subset {b1, b2, …, bm} of S such that

b1 + b2 + … + bm = k?

Page 23: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The SAT Problem

• The SAT Problem: Given a Boolean expression f(x1, x2, …, xn) in n Boolean variables x1, x2, …, xn, do there exist truth values for x1, x2, …, xn for which f(x1, x2, …, xn) will be true?

• That is, is f satisfiable?

Page 24: The Class NP Lecture 20 Section 7.3 Mon, Nov 27, 2006

The 3SAT Problem

• The 3SAT Problem: This is the same as SAT except that the Boolean expression is in conjunctive normal form with exactly 3 variables in each clause.