Professional Documents
Culture Documents
1
Consider a decidable (recursive) language L
which is decided by a Turing Machine M
For any string w the computation of M
terminates (in an accept of reject state)
in a finite amount of transitions
Accept
or Reject
Time = #transitions followed
2
TM (n )
1 2 3 4 k
TIME (T (n ))
L1 L3
L2
{a n : n 0 }
TIME (n ) 2
{a n b n : n 0 }
5
Example: The membership problem
for context free languages
L { G ,w : w is generated by grammar G }
Polynomial time
6
Theorem: TIME (n k 1
) TIME (n )
k
k 1
DTIME (n )
k
DTIME (n )
7
Polynomial time algorithms: TIME (n ) k
8
The class P
P TIME (n ) k
for all k 0
k 0
•Polynomial time
{ww}
10
nk
Exponential time algorithms: TIME (2 )
11
Example: the Hamiltonian Path Problem
s t
YES!
13
A solution: search exhaustively all paths
nk
L TIME (n ! ) TIME (2 )
Exponential time
Intractable problem
14
The clique problem
15
The clique problem
16
Example: The Satisfiability Problem
Boolean expressions in
Conjunctive Normal Form:
t1 t2 t3 tk
ti x1 x2 x3 x p
Variables
Satisfiable: x1 0, x2 1, x3 1
( x1 x2 ) ( x1 x3 ) 1
18
Example: ( x1 x2 ) x1 x2
Not satisfiable
19
L {w : expression w is satisfiable}
nk
L TIME (2 )
exponential
Algorithm:
search exhaustively all the possible
binary values of the variables
20
Non-Determinism
Language class: NTIME (n)
NTIME (n)
L1 L3
L2
Non-Deterministic Algorithm
to accept a string ww :
O (| w |)
•Compare the two tapes
Total time: O (| w |)
23
NTIME (n)
L {ww}
24
In a similar way we define the class
NTIME (T (n))
2 3
Examples: NTIME (n ), NTIME (n ),...
25
Non-Deterministic Polynomial time algorithms:
k
L NTIME ( n )
26
The class NP
k
NP NTIME (n ) for all k
27
Example: The satisfiability problem
L {w : expression w is satisfiable}
Non-Deterministic algorithm:
•Guess an assignment of the variables
28
L {w : expression w is satisfiable}
L NP
30
Observation:
P NP
Deterministic Non-Deterministic
Polynomial Polynomial
31
Open Problem: P NP ?
32
Open Problem: P NP ?