Professional Documents
Culture Documents
13-1
The Class NP
Beyond P
We have seen that the class P provides a useful model of easy
computation
This includes 2-Satisfiability and
2-Colourability
But what about 3-Satisfiability and
3-Colourability
No polynomial time algorithms for these problems are known
On the other hand
13-2
Certificates
Every yes-instance of those problems has a short and easily checkable
certificate
Satisfiability a satisfying assignment
k-Colourability a k-colouring
Hamiltonian Circuit a Hamiltonian circuit
Linear Programming a solution to the system of
inequalities
In all cases one can easily prove a positive answer
13-3
Verifiers
Definition
Definition
AAdecider
decidermachine
machine VV isiscalled
calledaa verifier
verifier for
foraalanguage
language LL ifif
LLw
w VV accepts
accepts w;c
w;c for
forsome
somestring
string c
c
13-4
The Class NP
Definition
Definition
The
Theclass
classofoflanguages
languagesthat
thathave
havepolynomial
polynomialtime
timeverifiers
verifiersisis
called
called NP
NP
13-5
13-6
SubsetSum
Instance: A sequence of positive integers S {a1 , , an } and a
target integer t.
Question: Is there a subset T S such that
ai t
iT
Path
Instance: A graph G and two its vertices u and v.
Question: Is there a path connecting u and v?
13-7
Problems not in NP
No Hamiltonian Circuit
Instance: A graph G.
Question: Is it true that G has no Hamiltonian circuit?
13-8
Problems not in NP
Checkers
Instance: A positive integer n.
Question: Is there a winning strategy for whites in a checker game
on n n board?
13-9
Non-deterministic Machines
We can get an alternative definition of the class NP by considering
non-deterministic machines
Recall that if NT is a non-deterministic Turing Machine, then NT(x)
denotes the tree of configurations which can be entered with input
x, and NT accepts x if there is some accepting path in NT(x)
Definition
Definition
The
The time
timecomplexity
complexity ofofaa non-deterministic
non-deterministic Turing
Turing
Machine
Machine NT
NT isisthe
thefunction
functionNTime NT such
suchthat
that NTime NT ( x )
isisthe
thenumber
numberofofsteps
stepsininthe
theshortest
shortestaccepting
acceptingpath
pathofof NT(x)
NT(x)
ififthere
thereisisone,
one, otherwise
otherwiseititisisthe
thenumber
numberofofsteps
stepsininthe
theshortest
shortest
rejecting
rejectingpath
path
(If not all paths of NT(x) halt, then NTime NT ( x ) is undefined)
13-10
Definition
Definition
The
The nondeterministic
nondeterministictime
timecomplexity
complexityclass
class NTIME[f]
NTIME[f] isis
defined
definedtotobe
bethe
theclass
classofofall
alllanguages
languageswith
with nondeterministic
nondeterministic
time
timecomplexity
complexityinin O(f)
O(f)
13-11
An Alternative Definition of NP
Definition
Definition
NP NTIME[ n k ]
k 0
This was the original form of the definition of NP, and was first formulated
by Karp in 1972
It explains the name NP Nondeterministic Polynomial-time
13-12
Equivalence
Theorem
Theorem
The
Thetwo
twodefinitions
definitionsofof NP
NP are
areequivalent
equivalent
Proof:
If L NTIME[n k ] , then there is a nondeterministic machine
NT such that x L if and only if there is an accepting computation
path in NT(x). Furthermore, the length of these paths is in O (| x |k )
Using (some encoding of) these computation paths as the certificates,
we can construct a polynomial time verifier for L which simply checks
that each step of the computation path is valid
13-13
13-14
guessing a certificate
checking certificate
13-15
P and NP
All
Languages
Decidable
Languages
NP
P NP?
The
Thequestion
questionofofwhether
whetherorornot
not PPNP
NP isisone
oneofofthe
thebiggest
biggestopen
open
problems
problemsinincomputer
computerscience
science
13-16
13-17
NP-Completeness
Definition
Definition
AAlanguage
language LL isissaid
saidtotobe
be NP-complete
NP-completeifif LLNP
NP and,
and,for
for
any
any AANP,
NP, AALL
13-18
Proving NP-completeness
To show that L is NP-complete we must show that every
language in NP can be reduced to L in polynomial time
This would appear to be hard!
However, once we have one NP-complete language L0
we can show any other language L is NP-complete just by
showing L0 L
Hence the most difficult part is finding the first one
13-19
Theorem
Theorem (Cook
(CookLevin)
Levin)
Satisfiability
Satisfiabilityisis NP-complete
NP-complete
13-20