Hard Problems

Hard Problems
Familiar Problems
Sorting: nlog(n)
Shortest Path: |E|log(|V|)
All pairs shortest path: |V|^3
Topological Sort: |E|+|V|
M inimum Spanning Tree: |E|log(|V|)
Dictionary Operations: log(n)
...
Familiar Problems
All of these are
Question: Are all problems solvable in
polynomial time?
Computability
An simpler question:
Are all problems solvable?
Equivalently:
Can a computer compute the value of
f(x) for any f and x?
Computability
An simpler question:
Are all problems solvable?
Equivalently:
Can a computer compute the value of
f(x) for any f and x?
Answer: N o!
The H alting Problem
G iven a computer program F, write a
program H , where,
This is impossible!
The H alting Problem
Proof (by contradiction):
Suppose h(f, x) is computable.
First, enumerate every computer program:
The H alting Problem
Proof, continued:
N ow define a function,
Since we listed all computable function,
for some k,
The H alting Problem
Proof, continued:
What happens when we call g on its own
number?
A Contradiction!
Two Problems
H a m i l ton i a n Ci rcu i t
G iven a graph G :
Find a path that that goes through each
vertex exactly once, and returns:
Two Problems
Eu l eri a n Ci rcu i t
G iven a graph G :
Find a path that that goes through each
edge exactly once, and returns:
Two Complexity Classes
P = The set of all problems solvable in
polynomial time.
N P = The set of all problems verifiable in
polynomial time.
N ote that P is a subset of N P.
Two Complexity Classes
Eulerian Cycle in in N P.
H amiltonian Cycle also is in N P.
Eulerian Cycle in in P.
I s H amiltonian Cycle in P?
Two Complexity Classes
Eulerian Cycle in in N P.
H amiltonian Cycle also is in N P.
Eulerian Cycle in in P.
I s H amiltonian Cycle in P?
N o on e kn ows!
?
P = NP
I s there any problem in N P that' s not in P?
N ot currently known!
H uge practical consequences:
circuit board layout,
protein folding,
flight schedules,
etc.
(Also, a $1 million prize. )
P ! = NP
Suppose we want to show P! =N P.
Find any problem in N P that' s definately
not in P.
Similary to comparison sort taking at least
nlog(n) comparisons.
Find a problem in N P that takes at least,
P = NP
Suppose we want to show P=N P.
Find the hardest problem in N P, and show
that it' s in P.
Ok, so what' s the hardest problem in N P?
Two M ore Complexity
Classes
N P-H ard =
problems at least as hard as anything in N P.
N P-Complete =
problems in both N P-H ard and N P
We just need to show one problem in
N P-Complete is also in P!
N P-Complete
H amiltonian Cycle in N P-Complete.
Thousands of others are too:
Longest Path
Boolean Satisfiability
Traveling Salesman
Set Covering
G raph Coloring
...
Traveling Salesman
G iven set of n cities, and distances
between the cities, find the shortest cycle
visiting each city exactly once.
This is just H amiltonian Cycle, but with
edge weights.
Longest Path
Problem:
G iven a graph, find the longest path
between any two vertices.
Longest Path is N P-Complete.
But Shortest Path is in P!
1 5-Puzzle
Find the fewest number of moves needed to
solve the k-Puzzle.
Pretty good solutions using Best First
Search with a M anhattan Distance heuristic.
M inesweeper
I s a certain assignment of flags constistant
with the adjacent numbers.
Easy in practice, but not easy in general.
SAT
G iven a set of Boolean variable, s can we
assign true/false values to them to make
an arbitrary formula true?
For example, give the formula:
Can we assign values to the x' s to make
this true?
3SAT
Let' s make things easier:
Every formula takes the same form:
Formula:
and number of clauses seperated by OR
Clause:
three terms seperated by AN D
Term:
either
or
3SAT is N P-Complete, 2SAT is P.
Proving N P-Completeness
Show a reduction from some known N PComplete problem.
"I f we can solve H amiltonian Cycle we can
solve 3SAT. "
Practical Concerns
M oral of the story:
Don' t waste time trying to write a clever
program to solve a N P-complete problem.
Look for a good approximation or heuristic.