Transcript Slides

Class 14:
Intractable
Problems
CS150: Computer Science
University of Virginia
Computer Science
David Evans
http://www.cs.virginia.edu/evans
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”.
CS150 Fall 2005: Lecture 14: Intractable Problems
2
Thanks to Peggy Reed for
making the Smiley Puzzles!
Problems and Procedures
• To know a O (f) bound for a problem, we
need to find a (f) procedure that solves it
– The sorting problem is O (n log n) since we
know a procedure that solves it in (n log n)
• To know a Ω(f ) bound for a problem,
we need to prove that there is no
procedure faster than (f) that solves it
– We proved sorting is Ω(n log n) by reasoning
about the number of decisions needed
CS150 Fall 2005: Lecture 14: Intractable Problems
4
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!
CS150 Fall 2005: Lecture 14: Intractable Problems
5
Complexity Class P
“Tractable”
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,
simulating the universe are all in P.
CS150 Fall 2005: Lecture 14: Intractable Problems
6
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.
Alternately: If we had a magic guess-correctly
procedure that makes every decision correctly,
we could devise a procedure that solves the
problem in polynomial time.
Note: this definition is not precise enough to be satisfying yet! We will
need to understand better what a “step” means when we measure work
to define this properly.
CS150 Fall 2005: Lecture 14: Intractable Problems
7
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)
CS150 Fall 2005: Lecture 14: Intractable Problems
8
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.
CS150 Fall 2005: Lecture 14: Intractable Problems
9
Orders of Growth
1200
1000
simulating
universe
logn
n
nlogn
n^2
800
600
smileys puzzle
400
n^3
2n < n!
2^n
200
insertsort
quicksort
0
1
2
3
4
CS150 Fall 2005: Lecture 14: Intractable Problems
5
6
7
8
9
10
10
Orders of Growth
70000
smileys
puzzle
60000
logn
n
nlogn
n^2
n^3
2^n
40000
simulating universe
50000
30000
20000
10000
0
1
2
3
4
5
6
7
CS150 Fall 2005: Lecture 14: Intractable Problems
8
9
10 11 12 13 14 15 16
11
insertsort
quicksort
Orders of Growth
1200000
1000000
logn
n
nlogn
n^2
Smileys
puzzle
800000
“intractable”
600000
400000
n^3
2^n
“tractable”
200000
0
1
2
3
4
5
6
7
8
9 10 11 12 13 14 15 16 17 18 19 20
simulating universe
I do nothing that a man of unlimited funds, superb physical
endurance, and maximum scientific knowledge could not do.
– Batman (may be able to solve intractable problems, but
computer scientists can only solve tractable ones for large n)
CS150 Fall 2005: Lecture 14: Intractable Problems
12
Quiz Break
CS150 Fall 2005: Lecture 14: Intractable Problems
13
Intractable Problems
log-log scale
1E+30
time
since
“Big
Bang”
1E+28
n!
1E+26
2n
1E+24
1E+22
1E+20
1E+18
1E+16
P
1E+14
1E+12
1E+10
2022
today
1E+08
1E+06
n2
n log n
10000
100
1
2
4
8
CS150 Fall 2005: Lecture 14: Intractable Problems
16
32
64
14
128
Moore’s Law Doesn’t Help
• If the fastest procedure to solve a
problem is (2n) or worse, Moore’s
Law doesn’t help much.
• Every doubling in computing power
increases the problem size by 1.
CS150 Fall 2005: Lecture 14: Intractable Problems
15
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)
CS150 Fall 2005: Lecture 14: Intractable Problems
16
This makes a huge difference!
1E+30
time
since
“Big
Bang”
1E+28
n!
1E+26
2n
1E+24
1E+22
1E+20
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!
1E+18
1E+16
1E+14
1E+12
2032
today
1E+10
1E+08
1E+06
n2
n log n
10000
100
1
2
4
8
CS150 Fall 2005: Lecture 14: Intractable Problems
16
32
64
128
log-log scale
17
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
CS150 Fall 2005: Lecture 14: Intractable Problems
18
3SAT  Smiley




CS150 Fall 2005: Lecture 14: Intractable Problems
Step 1: Transform
into smileys
Step 2: Solve (using
our fast smiley
puzzle solving
procedure)
Step 3: Invert
transform (back into
3SAT problem
19
The Real 3SAT Problem
(also can be quickly transformed
into the Smileys Puzzle)
CS150 Fall 2005: Lecture 14: Intractable Problems
20
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
CS150 Fall 2005: Lecture 14: Intractable Problems
21
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.
CS150 Fall 2005: Lecture 14: Intractable Problems
22
Proposition
Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
a  (b  c)  b  c
CS150 Fall 2005: Lecture 14: Intractable Problems
23
(or)
(and)
(not)
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)
CS150 Fall 2005: Lecture 14: Intractable Problems
24
SAT Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
SAT (a  (b  c)  b  c)
 { a: true, b: false, c: true }
 { a: true, b: true, c: false }
SAT (a  a)
 no way
CS150 Fall 2005: Lecture 14: Intractable Problems
25
(or)
(and)
(not)
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)
CS150 Fall 2005: Lecture 14: Intractable Problems
26
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.
CS150 Fall 2005: Lecture 14: Intractable Problems
27
3SAT Example
Sentence ::= Clause
Clause ::= Clause1  Clause2
Clause ::= Clause1  Clause2
Clause ::= Clause
Clause ::= ( Clause )
Clause ::= Name
3SAT ( (a  b   c)
 (a   b  d)
 (a  b   d)
 (b   c  d ) )
 { a: true, b: false, c: false, d:
false}
CS150 Fall 2005: Lecture 14: Intractable Problems
28
(or)
(and)
(not)
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!
CS150 Fall 2005: Lecture 14: Intractable Problems
29
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!
CS150 Fall 2005: Lecture 14: Intractable Problems
30
Charge
• PS4 is due Monday
• More on P vs. NP next class
CS150 Fall 2005: Lecture 14: Intractable Problems
31