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

David Evans cs.virginia/~evans

  • Upload
    tariq

  • View
    53

  • Download
    5

Embed Size (px)

DESCRIPTION

Lecture 15: Intractable Problems (Smiley Puzzles and Curing Cancer). David Evans http://www.cs.virginia.edu/~evans. CS200: Computer Science University of Virginia Computer Science. Menu. P and NP NP Problems NP-complete Problems. Complexity Class P. - PowerPoint PPT Presentation

Citation preview

Page 1: David Evans cs.virginia/~evans

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

CS200: Computer ScienceUniversity of VirginiaComputer Science

Lecture 15: Intractable Problems(Smiley Puzzles and Curing Cancer)

Page 2: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 2

Menu

• P and NP

• NP Problems

• NP-complete Problems

Page 3: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 3

Complexity Class P

Class P: problems that can be solved in polynomial time

O(nk) for some constant k.

Easy problems like sorting, making a photomosaic using duplicate tiles, understanding the universe.

Page 4: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 4

Complexity Class NP

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

If we could try all possible solutions at once, we could identify the solution in polynomial time.

We’ll see a few examples today.

Page 5: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 5

0

2000

4000

6000

8000

10000

12000

2

10

18

26

34

42

50

58

66

74

82

90

98

n log2 n(quicksort)

n2 (bubblesort)

Growth Rates

Page 6: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 6

Why O(2n) work is “intractable”

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

today2022

time since “Big Bang”

log-log scale

Page 7: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 7

Moore’s Law Doesn’t Help

• If the fastest procedure to solve a problem is O(2n) or worse, Moore’s Law doesn’t help much.

• Every doubling in computing power increases the problem size by 1.

Page 8: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 8

Smileys Problem

Input: 16 square tiles

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

Page 9: David Evans cs.virginia/~evans
Page 10: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 10

NP Problems

• Best way we know to solve it is to try all possible permutations until we find one that is right

• Easy to check if an answer is right – Just look at all the edges if they match

• We know the simleys problem is: O(n!) and (n) but no one knows if it is (n!) or (n)

Page 11: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 11

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 the 5x5 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 12: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 12

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 13: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 13

3SAT Smiley• Step 1: Transform

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

Step 3: Invert transform (back into 3SAT problem

Page 14: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 14

The Real 3SAT Problem(also identical to Smileys Puzzle)

Page 15: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 15

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 16: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 16

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 17: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 17

PropositionExample

Sentence ::= Clause

Clause ::= Clause1 Clause2 (or)

Clause ::= Clause1 Clause2 (and)

Clause ::= Clause (not)

Clause ::= ( Clause )

Clause ::= Name

a (b c) b c

Page 18: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 18

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 19: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 19

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 20: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 20

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 21: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 21

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 22: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 22

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 23: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 23

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 24: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 24

NP Complete• 3SAT and Smiley Puzzle are examples of

NP-complete Problems• A problem is NP-complete if it is as hard as

the hardest problem in NP• All NP problems can be mapped to any of

the NP-complete problems in polynomial time

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

Page 25: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 25

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 26: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 26

Traveling Salesman 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 travelled

Page 27: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 27

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 28: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 28

Minesweeper Consistency Problem

– Input: a position in the game Minesweeper

– Output: either a assignment of bombs to variables, or “no”.

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

Page 29: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 29

Photomosaic Problem– Input: a set of tiles, a master image, a

color difference function, and a minimum total difference

– Output: either a tiling with total color difference less than the minimum or “no”.

• If given a tiling, easy to check if the total color difference is less than the minimum.

Page 30: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 30

Drug Discovery Problem– Input: a set of proteins, a desired 3D

shape

– Output: a sequence of proteins that produces the shape

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

Note: solving the minesweeper problem may be worth $1M, but if you can solve this one its worth $1Trillion+. (US Drug sales = $200B/year)

Page 31: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 31

Factoring Problem– Input: an n-digit number

– Output: a set of factors whose product is the input number

• Given the factors, easy to multiply to check if they are correct

• Not proven to be NP-Complete (but probably is)

• See “Sneakers” for what solving this one is worth… (PS7 will consider this)

Page 32: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 32

NP-Complete Problems• These problems sound really different…but they are

really the same!• A P solution to any NP-Complete problem makes all

of them in P (worth ~$1Trillion)– Solving the minesweeper constraint problem is actually as

good as solving drug discovery!

• A proof that any one of them has no polynomial time solution means none of them have polynomial time solutions (worth ~$1M)

• Most computer scientists think they are intractable…but no one knows for sure!

Page 33: David Evans cs.virginia/~evans

11 February 2002 CS 200 Spring 2002 33

Charge• Later in the course:

– There are some problems even harder than NP complete problems!

– There are problems we can prove are not solvable, no matter how much time you have. (Gödel – your spring break reading)

• PS4 Due Friday (Lab Hours Thu 7-9pm)

• Friday– Either review for exam or reduction example