cse 326: data structures: graphs

22
1 CSE 326: Data Structures: Graphs Lecture 24: Friday, March 7 th , 2003

Upload: teagan-gaines

Post on 31-Dec-2015

21 views

Category:

Documents


2 download

DESCRIPTION

CSE 326: Data Structures: Graphs. Lecture 24: Friday, March 7 th , 2003. Today. Finish NP complete problems Course evaluation forms. NP-Complete Problems. Recall: A Hamiltonean path = a paths that goes through each node exactly once How to find one ? Try out all paths. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE 326: Data Structures:  Graphs

1

CSE 326: Data Structures: Graphs

Lecture 24:Friday, March 7th, 2003

Page 2: CSE 326: Data Structures:  Graphs

2

Today

• Finish NP complete problems

• Course evaluation forms

Page 3: CSE 326: Data Structures:  Graphs

3

NP-Complete Problems

Recall:• A Hamiltonean path = a paths that goes through each

node exactly once

• How to find one ? Try out all paths.• Exponential time, and nobody knows better

• Why don’t we prove that there is no better algorithm ?• Because we don’t know how to prove it

Page 4: CSE 326: Data Structures:  Graphs

4

P and NPRecall:• A problem is in P (or PTIME) if we can solve it in time

O(nk), for some k > 0

• A problem is in NP if we can check a candidate solution in P

• Hamiltonean cycle (HC) is in NP• In fact, P NP• But what about NP ⊈ P or NP P ? Nobody knows.

Page 5: CSE 326: Data Structures:  Graphs

5

Another NP Problem

• SAT: Given a formula in Boolean logic, e.g.

determine if there is an assignment of values to the variables that makes the formula true (=1).

• Why is it in NP?

a b a c b c

Page 6: CSE 326: Data Structures:  Graphs

6

SAT is NP-Complete• Cook (1971) showed the following:

• Including Hamiltonean Cycle (HC)• In some sense, SAT is the hardest problem in NP• We say that “SAT is NP-Hard”• A problem that is NP-Hard and in NP is called NP-

complete

TheoremSuppose that we can solve the SAT problem in polynomial time.Then there is a way to solve ANY NP problem in polynomial time !!!

TheoremSuppose that we can solve the SAT problem in polynomial time.Then there is a way to solve ANY NP problem in polynomial time !!!

Page 7: CSE 326: Data Structures:  Graphs

7

SAT is NP-Complete• Proof of Cook’s theorem:• Suppose we can solve SAT in time O(m7), where m

is the size of the formula

• Let some other problem in NP: we can check a candidate solution in, say, time O(n5), where n is the size of the problem’s input

Page 8: CSE 326: Data Structures:  Graphs

8

SAT is NP-Complete: Proof

• To solve that other problem, do the following• We have a program A that checks some candidate

solution in time O(n5)• Construct a HUGE boolean formula that

represents the execution of A: its variables are the candidate solution (which we don’t know) plus all memory bits

• Then check if this formula is satisfiable (i.e. there exists some candidate solution)

Page 9: CSE 326: Data Structures:  Graphs

9

SAT is NP-Complete: Proof

Time = 0

Memory(at most n5 memory words (why ?))

Programcounter Input

Candidatesolution (unknown)

Time = 1

Time = n5

Boolean expressionsize = n5 n5

Boolean expressionsize = n5 n5

Answer (0 or 1)

HUGE boolean formula of size O(n5 n5 n5) check satisfiability in time O((n5 n5 n5)7)

Page 10: CSE 326: Data Structures:  Graphs

10

The Graph of NP-Completeness• What is special about SAT ?

• Nothing ! There are hundreds of NP-complete problems:

• Directed Hamiltonean Path (DHP)

• Vertex Cover

• Clique

• etc, etc, ...

Page 11: CSE 326: Data Structures:  Graphs

11

Directed Hamiltonean Path is NP-Complete

• Proof: by reducing SAT to DHP:

• Then use transitivity to argue than we can solve any NP problem in polynomial time

• I’ll show you how to prove the lemma...

Theorem Directed Hamiltonean Path (DHP) is NP CompleteTheorem Directed Hamiltonean Path (DHP) is NP Complete

Lemma If we can solve DHP in polynomial time, thenwe can solve SAT in polynomial time

Lemma If we can solve DHP in polynomial time, thenwe can solve SAT in polynomial time

Page 12: CSE 326: Data Structures:  Graphs

12

Directed Hamiltonean Path is NP-Complete

• Suppose you are given a boolean formula in conjunctive normal form:

• Construct a directed graph G s.t. it admits a Hamiltonean cycle iff the formula is satisfiable

a b a c b c

Page 13: CSE 326: Data Structures:  Graphs

13

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

Step 1: construct this subgraph

Page 14: CSE 326: Data Structures:  Graphs

14

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

Step 2: now replicate it once for each boolean variable

c 1 c 2 c 3

c 1 c 2 c 3

a

b

c

Page 15: CSE 326: Data Structures:  Graphs

15

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

Step 3: now add a new node for each clause c1, c2, ...

c 1 c 2 c 3

c 1 c 2 c 3

a

b

c

c1

c2

c3

Page 16: CSE 326: Data Structures:  Graphs

16

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

Step 4: now connect the variable graphs to the clause nodes in clever wayE.g. for c2:

c 1 c 2 c 3

c 1 c 2 c 3

a

b

c

c1

c2

c3

Right-left fora

Left-right for c

Page 17: CSE 326: Data Structures:  Graphs

17

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

Step 5: finally, the formula is satisfiable iff there exists a Hamiltonean path !E.g a=1, b=0, c=1

c 1 c 2 c 3

c 1 c 2 c 3

a

b

c

c1

(true becauseof a)

c2

(true becauseof c)

c3

(true becauseof c)

Page 18: CSE 326: Data Structures:  Graphs

18

a b a c b c c 1 c 2 c 3

c 1 c 2 c 3

E.g a=1, b=0, c=1

c 1 c 2 c 3

c 1 c 2 c 3

a

b

c

c1

(true becauseof a)

c2

(true becauseof c)

c3

(true becauseof c)

Page 19: CSE 326: Data Structures:  Graphs

19

A Great Book You Should Own!

• Computers and Intractability: A Guide to the Theory of NP-Completeness, by Michael S. Garey and David S. Johnson

Page 20: CSE 326: Data Structures:  Graphs

20

Your Chance to Win a Turing Award: P = NP?

• Nobody knows whether NP P– Proving or disproving this will bring you

instant fame!• It is generally believed that P NP, i.e.

there are problems in NP that are not in P– But no one has been able to show even one

such problem!– Practically all of modern complexity theory

is premised on the assumption that P NP

• A very large number of useful problems are in NP

Alan Turing(1912-1954)

Page 21: CSE 326: Data Structures:  Graphs

21

P, NP, and Exponential Time Problems

• All currently known algorithms for NP-complete problems run in exponential worst case time– Finding a polynomial time

algorithm for any NPC problem would mean:

• Diagram depicts relationship between P, NP, and EXPTIME (class of problems that provably require exponential time to solve)

It is believed that P NP EXPTIME

EXPTIME

NP

P

NPC

Page 22: CSE 326: Data Structures:  Graphs

22

Coping with NP-Completeness

1. Settle for algorithms that are fast on average: Worst case still takes exponential time, but doesn’t occur very often. But some NP-Complete problems are also average-time NP-Complete!

2. Settle for fast algorithms that give near-optimal solutions: But finding even approximate solutions to some NP-Complete problems is NP-Complete!

3. Just get the exponent as low as possible! Much work on exponential algorithms for Boolean satisfiability: in practice can often solve problems with 1,000+ variablesBut even 2n/100 will eventual hit the exponential curve!