Hamiltonian Path I
For some problems it is difficult to find an algorithm in P
We first discuss an example of finding a Hamiltonian Path
Definition: for a given directed graph find a path going through all nodes once
Fig 7.17
Hamiltonian Path II
s t
HAMPATH = {hG , s, ti | G : directed, a Hamiltonian path from s to t}
A brute-force way: checking all possible paths But the number is exponential
Polynomial verification
Hamiltonian Path III
This is an example where verification is easier than determination
Compositeness I
We discuss another example where verification is easier than determination
An integer is composite if
x = pq, p > 1, q > 1 Given x , difficult to find p, q
Given x , p, q easily verify x = pq or not
Not polynomial verifiable I
Some problems are difficult so even a polynomial verifier cannot be easily obtained
HAMPATH: given hG , s, ti no Hamiltonian path from s to t
Verification may still be difficult
Given s and t it seems we still need to check all paths
Verifier I
Definition: an algorithm V is a verifier of a language A if
A = {w | V accepts hw , ci for some strings c}
Example: compositeness. V accepts hw , ci = hx, pi, where p is a divisor Example: Hamiltonian path. V accepts
hw , ci = hhG , s, ti, a path from s to ti
Verifier II
Definition: a polynomial verifier if it takes polynomial time of |w |
A: polynomially verifiable if ∃ a polynomial verifier Note that we measure time on |w | without
considering |c|
For a polynomial verifier, |c| should be in polynomial of |w |
Otherwise, reading |c| already non-polynomial
NP I
NP is a class of languages
Definition: a language ∈ NP if it has a polynomial verifier
We will prove that this definition is equivalent to that the language is decided by nondeterministic polynomial TM
This is where the name comes from Some use this as the definition
Note that for nondeterministic TM the running time
NP II
Definition:
NTIME(t(n))
={L | L decided by O(t(n)) nondeterministic TM}
NP = ∪kNTIME(nk)
NTM for HAMPATH I
A list p1· · · pm is nondeterministically chosen For each list:
1 Check repetitions
2 Check s = p1; t = pm
3 Check that for i = 1 . . . m − 1, (pi, pi +1) is an edge of G
Cost on each list is polynomial:
repetitions: O(m2) s = p , t = p : O(m)