04 Non Deterministic Time
04 Non Deterministic Time
LIPADE
Algorithmic Complexity
Non-Deterministic Time
2023
Outline
1
Polynomial Hierarchy
Deterministic Non-Deterministic
(q0 , x0 ) (q0 , x0 )
δ δ
δ δ
(q1 , x1 ) ... (qk , xk )
(q1 , x1 ) δ
δ δ δ
...
... ...
...
δ δ
δ δ
δ
(qm , xm ) (qn , xn )
(qn , xn ) (qo , xo ) (qp , xp )
Solving an Equation...
Does f (n) = 0 have a solution, with n ∈ [0, 1, . . . , 109 ]?
Solving an Equation...
Does f (n) = 0 have a solution, with n ∈ [0, 1, . . . , 109 ]?
Solving an Equation...
Does f (n) = 0 have a solution, with n ∈ [0, 1, . . . , 109 ]?
Solving an Equation...
Does f (n) = 0 have a solution, with n ∈ [0, 1, . . . , 109 ]?
Solving an Equation...
Does f (n) = 0 have a solution, with n ∈ [0, 1, . . . , 109 ]?
Proposition
I ∀f : N 7→ N, then DTIME(f (n)) ⊆ NTIME(f (n))
I ∀f (n) ≥ n, NTIME(f (n)) is closed for finite union and finite
intersection
I if L1 , . . . , Lm ∈ NTIME(f (n)), then L1 ∪ · · · ∪ Lm ∈ NTIME(f (n))
I if L1 , . . . , Lm ∈ NTIME(f (n)), then L1 ∩ · · · ∩ Lm ∈ NTIME(f (n))
Proposition
I ∀f : N 7→ N, then DTIME(f (n)) ⊆ NTIME(f (n))
I ∀f (n) ≥ n, NTIME(f (n)) is closed for finite union and finite
intersection
I if L1 , . . . , Lm ∈ NTIME(f (n)), then L1 ∪ · · · ∪ Lm ∈ NTIME(f (n))
I if L1 , . . . , Lm ∈ NTIME(f (n)), then L1 ∩ · · · ∩ Lm ∈ NTIME(f (n))
Definition
I The complexity class NP is the set of languages decided in
polynomial time by a NDTM, i.e
[
NP = NTIME(nk )
k ∈N
Definition
I The complexity class NP is the set of languages decided in
polynomial time by a NDTM, i.e
[
NP = NTIME(nk )
k ∈N
Definition
I The complexity class NP is the set of languages decided in
polynomial time by a NDTM, i.e
[
NP = NTIME(nk )
k ∈N
Clique
I Input: G a graph, k ∈ N
I Problem: Does G contain a clique with size k ?
Subset Sum
I Input: {a1 , . . . , an } ⊂ N, k ∈ N
I Problem: Is there a subset S ⊆ {a1 , . . . , an } s.t. x∈S x = k ?
P
Polynomial Hierarchy
Definition
Given a complexity class C, its complement COC is defined by
CO C = {P̄ | P ∈ C}
Definition
Given a complexity class C, its complement COC is defined by
CO C = {P̄ | P ∈ C}
No Clique
I Input: G a graph, k ∈ N
I Problem: Does G contain no clique with size k ?
No Clique
I Input: G a graph, k ∈ N
I Problem: Does G contain no clique with size k ?
Theorem
P ⊆ NP and P ⊆ CONP
but NP = CONP or NP 6= CONP is still an open question
Theorem
P ⊆ NP and P ⊆ CONP
but NP = CONP or NP 6= CONP is still an open question
Definition
Given C1 , C2 two complexity classes, CC
1 is the set of all problems
2
Definition
Given C1 , C2 two complexity classes, CC
1 is the set of all problems
2
Definition
Given C1 , C2 two complexity classes, CC
1 is the set of all problems
2
Example
A problem belongs to PNP if it can be solved by a DTM with
polynomially many calls to a NP oracle (i.e. a polynomial NDTM)
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP
NP
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP
P ∆P2
NP
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP ΠP2
P ∆P2
NP ΣP2
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP ΠP2
P ∆P2 ∆P3
NP ΣP2
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP ΠP2 ΠP3
NP ΣP2 ΣP3
Definition
The polynomial hierarchy is the set of complexity classes defined
recursively by
P
I ∆P0 = ΣP0 = ΠP0 = P I ΣPk +1 = NPΣk
P P
I ∆Pk +1 = PΣk I ΠPk +1 = CONPΣk
CO NP ΠP2 ΠP3
NP ΣP2 ΣP3
I C1 → C2 means that C1 ⊆ C2
I PH = i∈N ΣPi
S
C-hardness
A problem P is C-hard iff for each P 0 ∈ C, P 0 ≤Pf P
C-completeness
A problem P is C-complete iff it is C-hard and P ∈ C
C-completeness
A problem P is C-complete iff it is C-hard and P ∈ C
A lot of interesting AI problems are complete for NP, CONP, ΣP2 or ΠP2
Polynomial Hierarchy
General knowledge: SAT is the first problem which has been proved
NP-complete.
General knowledge: SAT is the first problem which has been proved
NP-complete.
The power of propositional logic to express a lot of « real » problems
(solving games, planning,. . . ) has led to the development of quite
efficient methods to solve NP-complete problems. But even these
methods do not allow to solve ALL instances of NP-complete
problems.
CNF-SAT
Any formula can be transformed in an equivalent CNF formula
I The transformation can be done in polynomial time
CNF-SAT
Any formula can be transformed in an equivalent CNF formula
I The transformation can be done in polynomial time
I Solving CNF-SAT is NP-complete
CNF-SAT
Any formula can be transformed in an equivalent CNF formula
I The transformation can be done in polynomial time
I Solving CNF-SAT is NP-complete
DNF-SAT
Any formula can be transformed in an equivalent DNF formula
I Solving DNF-SAT is polynomial
CNF-SAT
Any formula can be transformed in an equivalent CNF formula
I The transformation can be done in polynomial time
I Solving CNF-SAT is NP-complete
DNF-SAT
Any formula can be transformed in an equivalent DNF formula
I Solving DNF-SAT is polynomial
I The transformation cannot be done in polynomial time :(
Complexity of 2SAT
Determining if a 2CNF formula is satisfiable is in P
Complexity of Horn-SAT
Determining if a Horn formula is satisfiable is in P
Definition
Given a universe U and S ⊆ 2U , a set packing of U is a subset C ⊆ S
s.t. all elements in C are pairwise disjoints
Definition
Given a list of objects x1 , . . . , xn , each of them associated with a value
v1 , . . . , vn and a weight w1 , . . . , wn , a knapsack with a maximal weight
W , and an integer V , is it possible to fill the bag with some of the
objects, such that the sum of the weights is lesser than W and the
sum of the values is greater than V ?
Theorem
Solving the Knapsack Problem is NP-complete
Definition
A graph is a pair G = hN, Ei where elements of N are called nodes
and E ⊆ N × N is the set of edges between the nodes. A kernel of G
is a subset K ⊆ N s.t. ∀ni , nj ∈ K , (ni , nj ) ∈
/ E and ∀nj ∈ N \ K ,
∃ni ∈ K s.t. (ni , nj ) ∈ E
Definition
An implicant of a formula φ is a conjunction of literals c = x1 ∧ · · · ∧ xn
s.t. c ` φ.
Polynomial Hierarchy
Algorithm 1 SAT
Input: φ
Let ω be some interpretation
for c a clause in φ do
sat_clause = false
for l a literal in c do
if ω(l) = 1 then
sat_clause = true
end if
end for
if not sat_clause then
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate: Intuition
37
Algorithm 2 SAT
Input: φ
I Non-deterministic guess
Let ω be some interpretation
for c a clause in φ do
sat_clause = false
for l a literal in c do
if ω(l) = 1 then
sat_clause = true
end if
end for
if not sat_clause then
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate: Intuition
37
Algorithm 3 SAT
Input: φ
I Non-deterministic guess
Let ω be some interpretation
for c a clause in φ do I Each execution of the
sat_clause = false algorithm tests a different
for l a literal in c do value of ω
if ω(l) = 1 then
sat_clause = true
end if
end for
if not sat_clause then
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate: Intuition
37
Algorithm 4 SAT
Input: φ
I Non-deterministic guess
Let ω be some interpretation
for c a clause in φ do I Each execution of the
sat_clause = false algorithm tests a different
for l a literal in c do value of ω
if ω(l) = 1 then I If there is one execution that
sat_clause = true returns True, then φ is a
end if positive instance
end for
if not sat_clause then
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate: Intuition
37
Algorithm 5 SAT
Input: φ
I Non-deterministic guess
Let ω be some interpretation
for c a clause in φ do I Each execution of the
sat_clause = false algorithm tests a different
for l a literal in c do value of ω
if ω(l) = 1 then I If there is one execution that
sat_clause = true returns True, then φ is a
end if positive instance
end for I In this case, ω is called a
if not sat_clause then certificate for φ
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate
38
Definition
A certificate (also called a witness) is a word that certifies the answer
to a computation, or certifies the membership of some word in a
language.
Example
I P = “Given a polynomial P, has P at least one root?”. The
instance P(x) = x 2 can be verified with the certificate x = 0:
P(0) = 0.
x = 0 is a certificate that P is a positive instance of P
Definition
A certificate (also called a witness) is a word that certifies the answer
to a computation, or certifies the membership of some word in a
language.
Example
I P = “Given a polynomial P, has P at least one root?”. The
instance P(x) = x 2 can be verified with the certificate x = 0:
P(0) = 0.
x = 0 is a certificate that P is a positive instance of P
I P’= “Given a polynomial P, is P(x) positive for all x?” The
instance P 0 (x) = x 2 − 2 can be verified with the certificate
x = −1: P 0 (−1) = (−1)2 − 2 = 1 − 2 = −1 < 0.
x = −1 is a certificate that P 0 is a negative instance of P’
Proposition
Let P be a problem. Given an instance x of P and a certificate c, if
the problem
P 0 : « Is c a proof that x is a positive instance of P? »
is in P, then P ∈ NP
Proposition
Let P be a problem. Given an instance x of P and c a certificate, if
the problem
Proposition
Let P be a problem. Given an instance x of P and a certificate c, if
the problem
P 0 : « Is c a proof that x is a positive instance of P? »
is in P, then P ∈ NP
Proposition
Let P be a problem. Given an instance x of P and c a certificate, if
the problem
Algorithm 6 SAT
Input: φ
Let ω be some interpretation
for c a clause in φ do
sat_clause = false
for l a literal in c do
if ω(l) = 1 then
sat_clause = true
end if
end for
if not sat_clause then
return False
end if
end for
return True
J.-G. Mailly | Non-Deterministic Time
Certificate Verification
40
Algorithm 8 SAT
Algorithm 9 Verify Interpretation
Input: φ
Input: φ, ω
Let ω be some interpretation
for c a clause in φ do
for c a clause in φ do
sat_clause = false
sat_clause = false
for l a literal in c do
for l a literal in c do
if ω(l) = 1 then
if ω(l) = 1 then
sat_clause = true
sat_clause = true
end if
end if
end for
end for
if not sat_clause then
if not sat_clause then
return False
return False
end if
end if
end for
end for
return True
return True
J.-G. Mailly | Non-Deterministic Time
Certificate Verification
40
Algorithm 10 SAT
Algorithm 11 Verify Interpretation
Input: φ
Input: φ, ω
Let ω be some interpretation
for c a clause in φ do
for c a clause in φ do
sat_clause = false
sat_clause = false
for l a literal in c do
for l a literal in c do
if ω(l) = 1 then
if ω(l) = 1 then
sat_clause = true
sat_clause = true
end if
end if
end for
end for
if not sat_clause then
if not sat_clause then
return False
return False
end if
end if
end for
end for
return True
return True
J.-G. Mailly | Non-Deterministic Time
General C-Membership with a Certificate
41
Proposition
Let P be a problem. Given an instance x of P and a certificate c, if
the problem
P 0 : « Is c a proof that x is a positive instance of P? »
Proposition
Let P be a problem. Given an instance x of P and a certificate c, if
the problem
P 0 : « Is c a proof that x is a positive instance of P? »
Proposition
Let P be a problem. Given an instance x of P and a certificate c, if
the problem
P 0 : « Is c a proof that x is a negative instance of P? »
is in ΣPi−1 , then P ∈ ΠPi