david evans cs200: computer science university of virginia computer science class 38: intractable...

33
David Evans http://www.cs.virginia.edu/ evans CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles and Curing Cancer)

Upload: rhiannon-bolmer

Post on 01-Apr-2015

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

David Evanshttp://www.cs.virginia.edu/evans

CS200: Computer ScienceUniversity of VirginiaComputer Science

Class 38:Intractable Problems(Smiley Puzzles and Curing Cancer)

Page 2: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 2

Complexity and Computability• We’ve learned how to measure the

complexity of any procedure ()– Average score on question 6 (8.9/10), 7

(8.6/10) and 8 (8.1/10)

• We’ve learned how to show some problems are undecidable– Harder (average on question 4 = 7.7)

• Today: reasoning about the complexity of some problems

Page 3: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 3

Complexity ClassesClass P: problems that can be solved in polynomial time by a deterministic TM.

O (nk) for some constant k.

Easy problems like simulating the universe are all in P.

Class NP: problems that can be solved in polynomial time by a nondeterministic TM

Hard problems like the pegboard puzzle sorting are in NP (as well as all problems in P).

Page 4: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 4

Problem Classes

PNP

Decidable

Undecidable

Sorting: (n log n)

Simulating Universe: O(n3)

Cracker Barrel: O(2n) and (n)

Fill tape with 2n *s: (2n)

Halting Problem: ()

Page 5: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 5

P = NP?• Is there a polynomial-time solution to the

“hardest” problems in NP?

• No one knows the answer!

• The most famous unsolved problem in computer science and math

• Listed first on Millennium Prize Problems– win $1M if you can solve it – (also an automatic A+ in this course)

Page 6: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 6

If P NP:

PNP

Decidable

Undecidable

Sorting: (n log n)

Simulating Universe: O(n3)

Cracker Barrel: O(2n) and (n)

Fill tape with 2n *s: (2n)

Halting Problem: ()

Page 7: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 7

If P = NP:

PNP

Decidable

Undecidable

Sorting: (n log n)

Simulating Universe: O(n3)

Cracker Barrel: O(2n) and (n)

Fill tape with 2n *s: (2n)

Halting Problem: ()

Page 8: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 8

Smileys Problem

Input: n square tiles

Output: Arrangement of the tiles in a square, where the colors and shapes match up, or “no, its impossible”.

Page 9: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

Thanks to Peggy Reed for making the Smiley Puzzles!

Page 10: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 10

How much work is the Smiley’s Problem?

• Upper bound: (O)O (n!)

Try all possible permutations

• Lower bound: () (n)

Must at least look at every tile

• Tight bound: ()

No one knows!

Page 11: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 11

NP Problems

• Can be solved by just trying all possible answers until we find one that is right

• Easy to quickly check if an answer is right – Checking an answer is in P

• The smileys problem is in NPWe can easily try n! different answers

We can quickly check if a guess is correct (check all n tiles)

Page 12: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 12

Is the Smiley’s Problem in P?

No one knows!

We can’t find a O(nk) solution.

We can’t prove one doesn’t exist.

Page 13: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 13

This makes a huge difference!

1

100

10000

1E+06

1E+08

1E+10

1E+12

1E+14

1E+16

1E+18

1E+20

1E+22

1E+24

1E+26

1E+28

1E+30

2 4 8 16 32 64 128

n! 2n

n2

n log n

today

2032

time since “Big Bang”

log-log scale

Solving a large smileys problem either takes a few seconds, or more time than the universe has been in existence. But, no one knows which for sure!

Page 14: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 14

Who cares about Smiley puzzles?If we had a fast (polynomial time) procedure to solve the smiley puzzle, we would also have a fast procedure to solve the 3/stone/apple/tower puzzle:

3

Page 15: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 15

3SAT Smiley

Step 1: Transform into smileys

Step 2: Solve (using our fast smiley puzzle solving procedure)

Step 3: Invert transform (back into 3SAT problem

Page 16: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 16

The Real 3SAT Problem(also can be quickly transformed

into the Smileys Puzzle)

Page 17: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 17

Propositional GrammarSentence ::= Clause

Sentence Rule: Evaluates to value of Clause

Clause ::= Clause1 Clause2

Or Rule: Evaluates to true if either clause is true

Clause ::= Clause1 Clause2

And Rule: Evaluates to true iff both clauses are true

Page 18: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 18

Propositional GrammarClause ::= Clause

Not Rule: Evaluates to the opposite value of clause (true false)

Clause ::= ( Clause )Group Rule: Evaluates to value of clause.

Clause ::= NameName Rule: Evaluates to value associated with Name.

Page 19: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 19

PropositionExample

Sentence ::= Clause

Clause ::= Clause1 Clause2 (or)

Clause ::= Clause1 Clause2 (and)

Clause ::= Clause (not)

Clause ::= ( Clause )

Clause ::= Name

a (b c) b c

Page 20: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 20

The Satisfiability Problem (SAT)

• Input: a sentence in propositional grammar

• Output: Either a mapping from names to values that satisfies the input sentence or no way (meaning there is no possible assignment that satisfies the input sentence)

Page 21: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 21

SAT Example

SAT (a (b c) b c) { a: true, b: false, c: true } { a: true, b: true, c: false }

SAT (a a) no way

Sentence ::= Clause

Clause ::= Clause1 Clause2 (or)

Clause ::= Clause1 Clause2 (and)

Clause ::= Clause (not)

Clause ::= ( Clause )

Clause ::= Name

Page 22: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 22

The 3SAT Problem• Input: a sentence in propositional

grammar, where each clause is a disjunction of 3 names which may be negated.

• Output: Either a mapping from names to values that satisfies the input sentence or no way (meaning there is no possible assignment that satisfies the input sentence)

Page 23: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 23

3SAT / SAT

Is 3SAT easier or harder than SAT?

It is definitely not harder than SAT, since all 3SAT problemsare also SAT problems. Some SAT problems are not 3SAT problems.

Page 24: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 24

3SAT Example

3SAT ( (a b c) (a b d)

(a b d) (b c d ) ) { a: true, b: false, c: false, d: false}

Sentence ::= Clause

Clause ::= Clause1 Clause2 (or)

Clause ::= Clause1 Clause2 (and)

Clause ::= Clause (not)

Clause ::= ( Clause )

Clause ::= Name

Page 25: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 25

3SAT Smiley• Like 3/stone/apple/tower puzzle, we

can convert every 3SAT problem into a Smiley Puzzle problem!

• Transformation is more complicated, but still polynomial time.

• So, if we have a fast (P) solution to Smiley Puzzle, we have a fast solution to 3SAT also!

Page 26: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 26

NP Complete• Cook and Levin proved that 3SAT was NP-

Complete (1971)• A problem is NP-complete if it is as hard as

the hardest problem in NP• If 3SAT can be transformed into a different

problem in polynomial time, than that problem must also be NP-complete.

• Either all NP-complete problems are tractable (in P) or none of them are!

Page 27: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 27

NP-Complete Problems• Easy way to solve by trying all possible guesses• If given the “yes” answer, quick (in P) way to check

if it is right– Solution to puzzle (see if it looks right)– Assignments of values to names (evaluate logical

proposition in linear time)

• If given the “no” answer, no quick way to check if it is right– No solution (can’t tell there isn’t one)– No way (can’t tell there isn’t one)

Page 28: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 28

Traveling Salesperson Problem– Input: a graph of cities and roads with

distance connecting them and a minimum total distant

– Output: either a path that visits each with a cost less than the minimum, or “no”.

• If given a path, easy to check if it visits every city with less than minimum distance traveled

Page 29: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 29

Graph Coloring Problem– Input: a graph of nodes with edges

connecting them and a minimum number of colors

– Output: either a coloring of the nodes such that no connected nodes have the same color, or “no”.

If given a coloring, easy to check if it no connected nodes have the same color, and the number of colors used.

Page 30: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 30

Pegboard Problem- Input: a configuration of n pegs on a cracker barrel style pegboard

- Output: if there is a sequence of jumps that leaves a single peg, output that sequence of jumps. Otherwise, output false.If given the sequence of jumps, easy (O(n)) to check it is correct. If not, hard to know if there is a solution. Proof that variant of this

problem is NP-Complete isattached to today’s notes.

Page 31: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 31

Minesweeper Consistency Problem– Input: a position of n

squares in the game

Minesweeper– Output: either a

assignment of bombs to

squares, or “no”.

• If given a bomb assignment, easy to check if it is consistent.

Page 32: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 32

Drug Discovery Problem– Input: a set of proteins, a

desired 3D shape– Output: a sequence of

proteins that produces the shape (or impossible)

Note: US Drug sales = $200B/year

If given a sequence, easy (not really) to check if sequence has the right shape.

Caffeine

Page 33: David Evans  CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles

21 April 2004 CS 200 Spring 2004 33

Is it ever useful to be confident that a problem is

hard?