42
1 NP-Completeness Zeph Grunschlag

1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

Embed Size (px)

Citation preview

Page 1: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

1

NP-Completeness

Zeph Grunschlag

Page 2: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

2

Announcement

HW9 Due Now HW Amnesty I’ll drop your lowest hw score.

Page 3: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

3

AgendaNP-complete problems Proof that Punch-Card Puzzle is NP-

complete

P vs. NP question Known and unknown hierarchies

Next Time: Foundational proof that 3SAT is NP-complete (Cook-Levin Theorem)

Page 4: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

4

NP-Complete Problems“Magic Bullets”

We have already encountered some “NP-complete” problems. The first one was the punch-card puzzle. Solving the puzzle in general in polynomial time would land you a $1,000,000 as well as yield a fast solution to thousands of other problems in NP.

But solving any other NP-complete problem would bear the same fruits, as all NP-complete problems are polynomially equivalent to each other: if P and Q are NP-complete, then P is poly-time reducible to Q and vice versa.

Page 5: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

5

NP-Complete ProblemsHere is a list of some NP-complete problems:1. SAT2. CSAT3. 3SAT4. Punch-Card Puzzle5. Clique6. Discrete Linear Algebra7. Traveling Salesperson8. Hamiltonian PathSee many more at “An Annoted List…” or

from Garey and Johnson’s book.1

Page 6: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

6

NP-CompleteDefinition

We already know what it means for a problem to be in NP. NP-complete problems are problems which are in NP but are also NP-hard:

DEF: A language L is NP-hard if every problem L’ in NP is poly-time mapping reducible to L. If in addition, L is in NP, L is said to be NP-complete.

Page 7: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

7

NP-Hard ProblemsANTM

Intuitively, a problem is NP-hard if it is at least as hard as any problem in NP. But we already have an archetypal hardest problem: the undecidable problem ATM. Thus ATM ought to be NP-hard. It is possible to show this using for example, the NP-hardness of SAT.

However, to demonstrate directly from definition a problem that’s NP-hard, easier to use ANTM.

Q: Is ANTM Turing equivalent to ATM?

Page 8: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

8

NP-Hard ProblemsANTM

A: ANTM and ATM are Turing equivalent

1) A solution to ANTM would automatically give a solution to ATM since all TM are automatically NTM’s.

2) Since NTM’s can be determinized algorithmically, given any description of <NTM,input> can convert (and even in polynomial time!) to a description of equivalent <TM,input> which accepts iff original description accepts.

Page 9: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

9

NP-Hard ProblemsANTM

Proof that ANTM is NP-hard:

Given any language L’ * in NP, there is a NTM M’ which decides L’. Define the following mapping reduction f :

Given x *, f (x) = < M’ , x >f can be achieved by an I/O TM which runs in

polynomial time, simply by pre-appending x by the description of M’ on the tape. Furthermore, f (x) is in ANTM exactly when x is in L’. So f is a poly-time mapping reduction.�

Q: Is ANTM NP-complete?

Page 10: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

10

NP-Hard ProblemsANTM

A: No! Since all NP-complete are in NP ANTM would be in NP. This is impossible as problems in NP are decidable by exhaustive (exponential) search.

Page 11: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

11

Showing NP-Completeness

Standard technique for showing that a problem is NP-complete.

1) Show directly that problem is in NP.2) Show that a previously known NP-

complete problem is poly-time reducible to the problem of interest.

Typically, for step (2) an NP-complete SAT variant is used.

Page 12: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

12

Punch-Card Puzzleis NP-Complete

Let’s show that the Punch-Card Puzzle is NP-complete. We’ve already done step 1 in the previous lecture. Let’s reduce CSAT to the puzzle in poly-time:

Proof that CSAT reduces to Puzzle: This is a case that the Puzzle CSAT reduction is almost exactly the reverse of CSAT Puzzle.

Page 13: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

13

Reducing CSAT to Punch-Card Puzzle

1st IDEA: Concentrate only on left column.1) Each variable gives a card.2) Each clause gives a row.

When xi appears in clause j, the i th card will have no hole in the left column of row j.

When xi appears in clause j, the i th card will have no hole in the right column of row j.

Therefore, i th card fills in exactly those left rows that correspond to satisfied clauses, while i th card flipped fills in left rows that correspond to negation satisfying clauses.

Page 14: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

14

Reducing CSAT to Punch-Card Puzzle

EG: Consider conjunction of 4 clauses:x y z x

There should be 3 cards because there are 3 variables and 4 rows, because there are 4 clauses.

Page 15: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

15

Reducing CSAT to Punch-Card Puzzle

EG: Consider conjunction of 4 clauses:x y z x

There should be 3 cards because there are 3 variables and 4 rows, because there are 4 clauses.

Page 16: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

16

Reducing CSAT to Punch-Card Puzzle

EG: Consider conjunction of 4 clauses:x y z x

Variable x

Page 17: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

17

Reducing CSAT to Punch-Card Puzzle

EG: Consider conjunction of 4 clauses:x y z x

Variable x Variable y

Page 18: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

18

Reducing CSAT to Punch-Card Puzzle

EG: Consider conjunction of 4 clauses:x y z x

Variable x Variable y Variable z

Q: Any problems?

Page 19: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

19

Reducing CSAT to Punch-Card Puzzle

A: One column can be satisfied but not both!

Q: Any suggested fixes?

Page 20: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

20

Reducing CSAT to Punch-Card Puzzle

A: (2nd Idea) Just add the card whose right column is completely filled in, and left column completely open:

Claim: This actually works in general!In fact…

Page 21: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

21

Reducing CSAT to Punch-Card Puzzle

LEMMA: Suppose a boolean expression is transformed into a card puzzle according to 1st idea. Then if is unsatisfiable, not even 1 column can be filled.

Proof of lemma: If 1 column can be filled, we can assume it’s the left column by flipping all cards if it wasn’t. By construction, each card will fill in a row exactly when its variable has the corresponding truth value. Thus filling in the left column, means that is satisfiable. We’ve shown that if even 1 column is fillable, then is satisfiable, which is equivalent to lemma.//

Page 22: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

22

Reducing CSAT to Punch-Card Puzzle

Proof that 2nd idea works: CASE I. If is satisfiable then the left column is

fillable and adding the last card ensures that puzzle is solvable.

CASE II. If is unsatisfiable then by lemma, neither column is fillable. Adding the last card only allows the filling in of 1 of the two columns, so the puzzle remains unsolvable.

Thus we have satisfiable iff the constructed puzzle is solvable which proves the reduction of CSAT to the Punch-Card Puzzle.

Page 23: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

23

Reducing CSAT to Punch-Card Puzzle

Let’s see how this works on a more interesting example than x y z x.

Convert (x y y)(x z w )(y z w )

Page 24: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

24

Reducing CSAT to Punch-Card Puzzle

Convert (x y y)(x z w )(y z w )

There are 4 variables so 4 starting cards. There are 3 clauses so 3 rows.

Page 25: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

25

Reducing CSAT to Punch-Card Puzzle

Convert (x y y)(x z w )(y z w )

x

Page 26: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

26

Reducing CSAT to Punch-Card Puzzle

Convert (x y y)(x z w )(y z w )

x y

Page 27: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

27

Reducing CSAT to Punch-Card Puzzle

Convert (x y y)(x z w )(y z w )

x y z

Page 28: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

28

Reducing CSAT to Punch-Card Puzzle

Convert (x y y)(x z w )(y z w )

x y z w

Q: Is expression satisfiable?

Page 29: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

29

Reducing CSAT to Punch-Card Puzzle(x y y)(x z w )(y z w )

A: Yes. Set y = z = true, x,w = anything.

With cards this means that can fill left column by just using 2nd and 3rd cards:

Page 30: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

30

Reducing CSAT to Punch-Card Puzzle(x y y)(x z w )(y z w )

A: Yes. Set y = z = true, x,w = anything.

With cards this means that can fill left column by just using 2nd and 3rd cards:

Add 2nd card:

Page 31: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

31

Reducing CSAT to Punch-Card Puzzle(x y y)(x z w )(y z w )

A: Yes. Set y = z = true, x,w = anything.

With cards this means that can fill left column by just using 2nd and 3rd cards:

Add 3rd card:

Page 32: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

32

Reducing CSAT to Punch-Card Puzzle

(x y y)(x z w )(y z w )Notice that we don’t need the card with filled right column. This is because could use sequence: 1, 2, 3, flip 4.

Page 33: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

33

Reducing CSAT to Punch-Card Puzzle

(x y y)(x z w )(y z w )Notice that we don’t need the card with filled right column. This is because could use sequence: 1,

2, 3, flip 4.

Page 34: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

34

Reducing CSAT to Punch-Card Puzzle

(x y y)(x z w )(y z w )Notice that we don’t need the card with filled right column. This is because could use

sequence: 1, 2, 3, flip 4.

Page 35: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

35

Reducing CSAT to Punch-Card Puzzle

(x y y)(x z w )(y z w )Notice that we don’t need the card with filled right column. This is because could use sequence: 1,

2, 3, flip 4.

Page 36: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

36

Reducing CSAT to Punch-Card Puzzle

(x y y)(x z w )(y z w )Notice that we don’t need the card with

filled right column. This is because could use sequence: 1, 2, 3, flip 4.

Q: What does this say about boolean

expression?

Page 37: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

37

Reducing CSAT to Punch-Card Puzzle(x y y)(x z w )(y z w )

A: x = y = z = true, w = false and x = y = z = false, w = true

(antipode)are both solutions of boolean expression!

Page 38: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

38

P vs. NP Problem

The most important open problem in theoretical CS is determining whether P is strictly smaller than NP. Intuitively, there seems to be no way to simulate exponentially many branches of an NTM computation in polynomial time. However, could have argued the same for NFA’s and argument would have been false!

Page 39: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

39

Known hierarchy

Let’s sum up what we actually know:1. All regular languages can be recognized in

linear time2. Context free languages can be recognized

in cubic time on a RAM (in fact, can prove that complexity of CFG’s is equal to complexity of matrix multiplication, so can do it in sub-cubic time)

3. There are decidable languages not solvable in polynomial time (EQREX )

Page 40: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

40

Known hierarchyGet the following RAM hierarchy

diagram: RECDECP

TIME(n)

CFLTIME(n3)

REG

EQREX

Page 41: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

41

Conjectured HierarchyInside of DEC we conjecture:

DEC

NP P co-NPNPcomplete

PRIMESAT

Page 42: 1 NP-Completeness Zeph Grunschlag. 2 Announcement HW9 Due Now HW Amnesty I’ll drop your lowest hw score

42

Blackboard Exercises1. Show that the following is NP-complete:

Telling if two boolean expressions are logically non-equivalent (have different output for some input).

2. Show that unless P = NP, there is no efficient algorithm for minimizing boolean expressions. (Therefore no efficient way to minimize circuits in general –result of great consequence in digital logic).

3. 3COLOR NP-hardness example