Complexity
Complexity
Complexity
231
8.1 Introduction
• Polynomial complexity.
• NP-complete problems.
232
8.2 Measuring complexity
• O notation.
233
8.3 Polynomial problems
• Graph example.
• Reasonable encodings:
– no padding,
– polynomial decoding,
– unary representation of numbers not allowed.
234
Complexity and Turing machines
TM (n) ≤ p(n)
for all n ≥ 0.
235
8.4 Polynomial transformations
236
The Travelling Salesman (TS)
• Set C of n Cities.
• Distances d(ci, cj ).
• A constant b.
237
Hamiltonian Circuit (HC)
• Graph G = (V, E)
• Is there a closed circuit in the graph that contains each vertex exactly
once.
s s s s
@ @
@ @
@s
@ @
@
@ @
@ @
s @s
@ s @s
@
238
Definition of polynomial transformations
Definition :
Consider languages L1 ∈ Σ∗1 and L2 ∈ Σ∗2. A polynomial transformation
from L1 to L2 (notation L1 ∝ L2) is a function f : Σ∗1 → Σ∗2 that satisfies
the following conditions :
239
HC ∝ TS
• The set of cities is identical to the set of vertices of the graph, i.e.
C =V.
(
1 si (ci, cj ) ∈ E
• The distances are the following (ci, cj ) = .
2 si (ci, cj ) 6∈ E
240
Properties of ∝
If L1 ∝ L2, then
• if L2 ∈ P then L1 ∈ P,
• if L1 6∈ P then L2 6∈ P.
If L1 ∝ L2 et L2 ∝ L3, then
• L1 ∝ L3.
241
Polynomially equivalent problems
Definition
Two languages L1 and L2 are polynomially equivalent (notation L1 ≡P L2)
if and only if L1 ∝ L2 and L2 ∝ L1.
242
The class NP
• Modelisation : nondeterminism.
243
The complexity of nondeterministic Turing machines
244
The definition of NP
Définition
The class NP (from Nondeterministic Polynomial) is the class of languages
that are accepted by a polynomial nondeterministic Turing machine.
Exemple
HC and TS are in NP.
245
Theorem
Consider L ∈ NP. There exists a deterministic Turing machine M and a
polynomial p(n) such that M decides L and has a time complexity
bounded by 2p(n).
2. Simulate each execution of Mnd of length q(n) (let the time needed be
q 0(n)). If r is the largest number of possible choices within an
execution of Mnd, there are at most rq(n) executions of length q(n).
246
3. If one of the simulated executions accepts, M accepts. Otherwise, M
stops and rejects the word w.
0
Complexity : bounded by rq(n) × q 0(n) and thus by 2log2(r)(q(n)+q (n)),
which is of the form 2p(n).
247
The structure of NP
Smallest class in NP : P
248
Largest class in NP : NPC
A language L is NP-complete if
1. L ∈ NP,
Theorem
If there exists an NP-complete language L decided by a polynomial
algorithm, then all languages in NP are polynomially decidable, i.e.
P = NP.
249
NPC
NP
250
Proving NP-completeness
or, alternatively,
251
A first NP-complete problem
propositional calculus
Boolean calculus :
p q p∧q
p ¬p 0 0 0
0 1 0 1 0
1 0 1 0 0
1 1 1
p q p∨q p q p⊃q
0 0 0 0 0 1
0 1 1 0 1 1
1 0 1 1 0 0
1 1 1 1 1 1
252
• Boolean expression: (1 ∧ (0 ∨ (¬1))) ⊃ 0.
253
Cook’s theorem
Theorem
The SAT problem is NP-complete
Proof
1. SAT is in NP.
254
Word w (|w| = n) and nondeterministic polynomial Turing machine
M = (Q, Γ, Σ, ∆, s, B, F ) (bound p(n)).
Q P C T
···
···
···
... ... ... ...
p(n) + 1
···
···
···
| {z }
p(n)+1
255
Representing an execution with propositional variables:
256
Formula satisfied only by an execution of M that accepts the word w :
conjunction of the following formulas.
^ _ ^
( tijα) ∧ (¬tijα ∨ ¬tijα0 )
^ _ ^
( pij ) ∧ (¬pij ∨ ¬pij 0 )
257
^ ^
t0jwj+1 ∧ t0jB ∧ q0s ∧ p00
0≤j≤n−1 n≤j≤p(n)
^
[(tijα ∧ ¬pij ) ⊃ t(i+1)jα]
0≤i<p(n)
0≤j≤p(n)
α∈Γ
^
[¬tijα ∨ pij ∨ t(i+1)jα]
0≤i<p(n)
0≤j≤p(n)
α∈Γ
(¬qiκ ∨ ¬pij ∨ ¬tijα ∨ ¬cik ∨ q(i+1)κ0 )∧
^
(¬qiκ ∨ ¬pij ∨ ¬tijα ∨ ¬cik ∨ t
(i+1)jα0 )∧
0≤i<p(n) (¬qiκ ∨ ¬pij ∨ ¬tijα ∨ ¬cik ∨ p(i+1)(j+d))
0≤j≤p(n)
α∈Γ
1≤k≤r
259
_
[qiκ]
0≤i≤p(n)
κ∈F
260
Other NP-complete problems
SAT ∝ 3-SAT.
261
3. A clause
(x1 ∨ x2 ∨ · · · ∨ xi ∨ · · · ∨ x`−1 ∨ x`)
with ` ≥ 4 literals is replaced by
(x1 ∨ x2 ∨ y1) ∧ (¬y1 ∨ x3 ∨ y2)
∧ (¬y2 ∨ x4 ∨ y3) ∧ · · ·
∧ (¬yi−2 ∨ xi ∨ yi−1) ∧ · · ·
∧ (¬y`−4 ∨ x`−2 ∨ y`−3)
∧ (¬y`−3 ∨ x`−1 ∨ x`)
262
The vertex cover problem (VC) is NP-complete.
sf sf sf
@
@
@
@
@
@
sf @s
@ s
263
3-SAT ∝ VC
Instance of 3-SAT :
E1 ∧ · · · ∧ Ei ∧ · · · ∧ Ek
Each Ei is of the form
xi1 ∨ xi2 ∨ xi3
where xij is a literal. The set of propositional variables is
P = {p1, . . . , p`}.
264
1. The set of vertices V contains
(a) a pair of vertices labeled pi and ¬pi for each propositional variable
in P,
(b) a 3-tuple of vertices labeled xi1, xi2, xi3 for each clause Ei.
265
2. The set of edges E contains
(a) The edge (pi, ¬pi) for each pair of vertices pi, ¬pi, 1 ≤ i ≤ `,
(b) The edges (xi1, xi2), (xi2, xi3) et (xi3, xi1) for each 3-tuple of
vertices xi1, xi2, xi3, 1 ≤ i ≤ k,
(c) an edge between each vertex xij and the vertex p or ¬p representing
the corresponding literal.
266
Example
ps 1 ¬p
s 1
ps 2 ¬p
s 2
ps 3 ¬p
s 3
ps 4 ¬p
s 4
E Z
E Z
Z
E Z
E Z
E Z
Z
E Z
E Z
E Z
Z
E
E ZZ
E Z
Z
E
Es Zs
Z
@ @
x12@@
x22 @
@
@ @
@ @
@ @
@ @
s @s s @s
@ @
267
Other examples
The Hamiltonian circuit (HC) and travelling salesman (TS) problems are
NP-complete.
268
The integer programming problem is NP-compete. An instance of this
problem consists of
2. a vector d of size n,
3. a constant b.
Over the rationals this problem can be solved in polynomial time (linear
programming).
269
The problem of checking the equivalence of nondeterministic finite
automata is NP-hard. Notice that there is no known NP algorithm for
solving this problem. It is complete in the class PSPACE.
270
8.8 Interpreting NP-completeness
• Worst case analysis. Algorithms that are efficient “on average” are
possible.
271
8.9 Other complexity classes
272
The class PSPACE is the class of languages decided by a deterministic
Turing machine whose space complexity (the number of tape cells used) is
bounded by a polynomial.
NP
P⊆ ⊆ PSPACE ⊆ EXPTIME.
co-NP
273