Professional Documents
Culture Documents
43
Polynomial time algorithms:
) (
k
n I
Tractable algorithms
For small we can compute the
result fast
k
44
) (
k
n I P !
for all
k
The class
P
All tractable problems
Polynomial time
45
P
CYK-algorithm
} {
n n
b a
-
} {ww
46
Exponential time algorithms:
) 2 (
n
I
Intractable algorithms
Some problem instances
may take centuries to solve
47
Example: the Traveling Salesperson Problem
problem} TSP in the paths shortest { ! L
) 2 ( ) ! (
n
DTIME n DTIME L <
Exponential time
Intractable problem
48
Example: The satisfiability Problem
Boolean expressions in
Conjunctive Normal Form:
k
t t t t .
3 2 1
p i
x x x x t v v v v ! .
3 2 1
Variables
Question: is expression satisfiable?
49
) ( ) (
3 1 2 1
x x x x v v
Satisfiable:
1 , 1 , 0
3 2 1
! ! ! x x x
1 ) ( ) (
3 1 2 1
! x x x x
Example
50
2 1 2 1
) ( x x x x
Not satisfiable
Example
51
e} satisfiabl is expression : { w w L !
) 2 (
n
I L
For variables:
n
Algorithm:
search exhaustively all the possible
binary values of the variables
exponential
52
Non-Determinism
Language class: ) (n NTIME
A Non-Deterministic Turing Machine
accepts each string of length
in time
) (n NTIME
1
L
2
L
3
L
) (n O
n
53
Example: } {ww L !
Non-Deterministic Algorithm
to accept a string : ww
Use a two-tape Turing machine
Guess the middle of the string
and copy on the second tape
Compare the two tapes
w
54
|) (| w O
Time needed:
|) (| w O
Total time: |) (| w O
} {ww L !
Use a two-tape Turing machine
Guess the middle of the string
and copy on the second tape
Compare the two tapes
w
55
) (n I
} {ww L !
56
In a similar way we define the class
)) ( ( n T NTIME
) (n T
For any time function:
Examples: ),... ( ), (
3 2
n I n I
57
Non-Deterministic Polynomial time algorithms:
) (
k
n I L
58
) (
k
n I P !
for all
k
The class NP
Non-Deterministic Polynomial time
59
Example:
The satisfiability problem
Non-Deterministic algorithm:
Guess an assignment of the variables
e} satisfiabl is expression : { w w L !
Check if this is a satisfying assignment
60
Time for variables: n
) (n O
e} satis iabl is expression : { w w L !
Total time:
Guess an assignment of the variables
Check if this is a satisfying assignment ) (n O
) (n O
61
e} satisfiabl is expression : { w w L !
NP L
The satisfiability problem is an -Problem NP
62
Observation:
NP P _
Deterministic
Polynomial
Non-Deterministic
Polynomial
63
Open Problem: ? NP P !
WE DO NOT KNOW THE ANSWER
64
Example: Does the Satisfiability problem
have a polynomial time
deterministic algorithm?
Open Problem: ? NP P !
WE DO NOT KNOW THE ANSWER
65
NP-Completeness
A problem is NP-complete if:
It is in NP
Every NP problem is reduced to it
(in polynomial time)
66
Observation:
If we can solve an NP-complete problem
in Deterministic Polynomial Time (P time)
then we know:
NP P !
67
Observation:
If prove that
we cannot solve an NP-complete problem
in Deterministic Polynomial Time (P time)
then we know:
NP P =
68
Cooks Theorem:
The satisfiability problem is NP-complete
69
Cooks Theorem:
The satisfiability problem is NP-complete
Proof:
Convert a Non-Deterministic Turing Machine
to a Boolean expression
in conjunctive normal form
70
Other NP-Complete Problems:
The Traveling Salesperson Problem
Vertex cover
Hamiltonian Path
All the above are reduced
to the satisfiability problem
71
Observations:
It is unlikely that NP-complete
problems are in P
The NP-complete problems have
exponential time algorithms
Approximations of these problems
are in P