Transcript Slides

Lecture 23:
Intractable Problems
(Smiley Puzzles and
Curing Cancer)
CS200: Computer Science
University of Virginia
Computer Science
David Evans
http://www.cs.virginia.edu/evans
Menu
• Review: P and NP
• NP Problems
• NP-Complete Problems
21 March 2003
CS 200 Spring 2003
2
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.
21 March 2003
CS 200 Spring 2003
3
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.
21 March 2003
CS 200 Spring 2003
4
Why O(2n) work is “intractable”
1E+30
1E+28
time
since
“Big
Bang”
n!
1E+26
2n
1E+24
1E+22
1E+20
1E+18
1E+16
1E+14
1E+12
1E+10
2022
today
1E+08
1E+06
n2
n log n
10000
100
1
2
21 March 2003
4
8
16
CS 200 Spring 2003
32
64
128
log-log scale
5
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”.
21 March 2003
CS 200 Spring 2003
6
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!
21 March 2003
CS 200 Spring 2003
8
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 NP
We can easily try n! different answers
We can quickly check if a guess is
correct (check all n tiles)
21 March 2003
CS 200 Spring 2003
9
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.
21 March 2003
CS 200 Spring 2003
10
This makes a huge difference!
1E+30
1E+28
time
since
“Big
Bang”
n!
1E+26
2n
1E+24
1E+22
1E+20
Solving the 5x5 smileys problem
either takes a few seconds, or more
time than the universe has been in
existence. But, no one knows
2032
which for sure!
today
1E+18
1E+16
1E+14
1E+12
1E+10
1E+08
1E+06
n2
n log n
10000
100
1
2
21 March 2003
4
8
16
CS 200 Spring 2003
32
64
128
log-log scale
11
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
21 March 2003
CS 200 Spring 2003
12
3SAT  Smiley




21 March 2003
CS 200 Spring 2003
Step 1: Transform
into smileys
Step 2: Solve (using
our fast smiley
puzzle solving
procedure)
Step 3: Invert
transform (back into
3SAT problem
13
The Real 3SAT Problem
(also can be quickly transformed
into the Smileys Puzzle)
21 March 2003
CS 200 Spring 2003
14
Propositional Grammar
Sentence ::= 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
21 March 2003
CS 200 Spring 2003
15
Propositional Grammar
Clause ::= Clause
Not Rule: Evaluates to the opposite value
of clause (true  false)
Clause ::= ( Clause )
Group Rule: Evaluates to value of clause.
Clause ::= Name
Name Rule: Evaluates to value associated
with Name.
21 March 2003
CS 200 Spring 2003
16
Proposition
Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
(or)
(and)
(not)
a  (b  c)  b  c
21 March 2003
CS 200 Spring 2003
17
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)
21 March 2003
CS 200 Spring 2003
18
SAT Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
(or)
(and)
(not)
SAT (a  (b  c)  b  c)
 { a: true, b: false, c: true }
 { a: true, b: true, c: false }
SAT (a  a)
 no way
21 March 2003
CS 200 Spring 2003
19
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)
21 March 2003
CS 200 Spring 2003
20
3SAT / SAT
Is 3SAT easier or harder than SAT?
It is definitely not harder than
SAT, since all 3SAT problems
are also SAT problems. Some
SAT problems are not 3SAT
problems.
21 March 2003
CS 200 Spring 2003
21
3SAT Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
(or)
(and)
(not)
3SAT ( (a  b   c)
 (a   b  d)
 (a  b   d)
 (b   c  d ) )
 { a: true, b: false, c: false, d: false}
21 March 2003
CS 200 Spring 2003
22
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!
21 March 2003
CS 200 Spring 2003
23
NP Complete
• Cook and Levin proved that 3SAT was NPComplete (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!
21 March 2003
CS 200 Spring 2003
24
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)
21 March 2003
CS 200 Spring 2003
25
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 traveled
21 March 2003
CS 200 Spring 2003
26
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.
21 March 2003
CS 200 Spring 2003
27
Phylogeny
Problem
– Input: a set of n species
and their genomes
– Output: a tree that
connects all the species
in a way that requires the
less than k total
mutations or “impossible”
if there is no such tree.
21 March 2003
CS 200 Spring 2003
28
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.
21 March 2003
CS 200 Spring 2003
29
Perfect 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”.
Note: not a perfect photomosaic!
If given a tiling, easy to check if the total
color difference is less than the minimum.
21 March 2003
CS 200 Spring 2003
30
Drug Discovery Problem
– Input: a set of proteins,
a desired 3D shape
– Output: a sequence of
proteins that produces
the shape (or
impossible)
Caffeine
If given a sequence, easy (not really) to
check if sequence has the right shape.
Note: US Drug sales = $200B/year
21 March 2003
CS 200 Spring 2003
31
Is it ever useful to be
confident that a problem is
hard?
21 March 2003
CS 200 Spring 2003
32
Factoring Problem
•
•
•
•
– Input: an n-digit number
– Output: two prime factors whose product is
the input number
Easy to multiply to check factors are correct
Not proven to be NP-Complete (but probably
is)
Most used public key cryptosystem (RSA)
depends on this being hard
See “Sneakers” for what solving this means
21 March 2003
CS 200 Spring 2003
33
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!
21 March 2003
CS 200 Spring 2003
34
Speculations
• Must study math for 15 years before understanding
an open problem
– Was ~10 until Andrew Wiles proved Fermat’s Last
Theorem
• Must study physics for ~6 years before
understanding an open problem
• Must study computer science for ~6 weeks before
understanding the most important open problem
– Unless you’re a 6-year old at Cracker Barrel
• But, every 5 year-old understands the most
important open problems in biology!
21 March 2003
CS 200 Spring 2003
35
Charge
• Problem Set 6: Due Monday
• Minesweeper is NP complete (optional)
• We still aren’t sure if the Cracker Barrel
Puzzle is NP-Complete
– Chris Frost and Mike Peck are working on it
(except Chris is off in Beverly Hills, see Daily
Progress article)
– Will present about their proof at a later lecture
21 March 2003
CS 200 Spring 2003
36