Complexity Theory
Markus Lohrey
Universität Leipzig
http://www.informatik.uni-leipzig.de/alg/lehre/ws11_12/KOMPL/
Winter semester 2012/2013
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
1 / 144
Part 1: Foundations
In the following we introduce some preliminaries:
Turing machines (non-deterministic, deterministic)
configurations
computations,...
Most of these preliminaries are not really important, because:
Turing machines can be defined in several variants.
Turing machines can be replaced by other models of computation
(e. g. register machines).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
2 / 144
Turing machines: Definition
Definition 1
A non-deterministic k-tape Turing machine is a tuple
M = (Q, Σ, Γ, δ, q0 , F , ¤)
Q: finite set of states
q0 ∈ Q : initial state
F ⊆ Q : set of final states
Γ : finite tape alphabet
Σ ( Γ : finite input alphabet
¤ ∈ Γ \ Σ : blank symbol
δ ⊆ (Q \ F ) × (Σ ∪ {¤}) × Γk × Q × Γk × {←, →, •}k+1 : transition
relation, where ← (→, •) means move head left (move head right, no
movement).
For all (q, ¤, b1 , . . . , bk , p, c1 , . . . , ck , d0 , . . . , dk ) ∈ δ we have d0 ∈ {←, •}.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
3 / 144
Turing machines: Definition
Remarks:
The last restriction from the previous slide means that the input head
stays within the input word (and the first cell after the right end of
the input).
Each tape is restricted to the left and the head for that tape cannot
move left of the first tape cell.
For a deterministic k-tape Turing machine M, δ is a partial mapping
δ : (Q \ F ) × (Σ ∪ {¤}) × Γk → Q × Γk × {←, →, •}k+1 .
If M is supposed to compute a function, then M has in addition an output
alphabet Σ′ and for δ we have
δ : (Q \ F ) × (Σ ∪ {¤}) × Γk → Q × Γk × {←, →, •}k+1 × (Σ′ ∪ {ε}),
where ε is the empty word.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
4 / 144
Turing machines: configurations
Definition 2
A configuration α of the Turing machine M with input w ∈ Σ∗ is a tuple
α = (q, i, u1 , i1 , . . . , uk , ik ) with:
q ∈ Q : current state of the Turing machine
1 ≤ i ≤ |w | + 1: The read-write head for the input tape is currently
scanning the i-th symbol of w ¤.
∀j ∈ {1, . . . , k} : uj ∈ Γ∗ , 1 ≤ ij ≤ |uj | + 1: The j-th working tape has
content uj ¤¤ · · · and the j-th read-write head is scanning the ij -th
symbol of uj ¤. If ij ≤ |uj |, then uj does not end with ¤.
The length |α| of the configuration α = (q, i, u1 , i1 , . . . , uk , ik ) is
|α| = max{|uj | | 1 ≤ j ≤ k}.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
5 / 144
Turing machines: Inital configuration, accepting
configurations, . . .
1
2
3
For input w ∈ Σ∗ let Start(w ) = (q0 , 1, ε, 1, . . . , ε, 1) the inital
configuration corresponding to w .
Note: | Start(w )| = 0.
For t ∈ δ and configurations α, β we write α ⊢t β, if “instruction” t
can be applied to configuration α and yields configuration β.
Excercise: Define this formally.
[
Let ⊢M =
⊢t .
t∈δ
4
5
With Accept we denote the set of all accepting configurations
(current state is from F ⊆ Q).
Note: ∀α ∈ Accept : there is no configuration β with α ⊢M β
Note: α ⊢M β ⇒ |α| − |β| ∈ {−1, 0, 1}
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
6 / 144
Turing machines: Computations, protocols
1
A computation of M on input w is a sequence of configurations
α0 , α1 , . . . , αm with
Start(w ) = α0
∀1 ≤ i ≤ m : αi−1 ⊢M αi
The computation is successful if αm ∈ Accept.
2
The protocol of this computation is the sequence d0 d1 . . . dm−1 ∈ δ ∗
with αi ⊢di αi+1
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
7 / 144
Turing machines: accepted set, time and space
1
The time (resp., space) needed by the computation α0 , α1 , . . . , αm is
m (resp., max{|αi | | 0 ≤ i ≤ m}).
2
M needs time (resp., space) at most N ∈ N on input w if every
computation of M on input w needs time (resp., space) ≤ N.
3
Let f : N → N be a monotonically increasing function.
M is f -time bounded, if for every input w , M needs time at most
f (|w |).
M is f -space bounded, if for every input w , M needs space at most
f (|w |).
4
L(M) = {w ∈ Σ∗ | ∃ successful computation of M on input w } is the
set accepted by M.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
8 / 144
Turing machines: number of configurations
The following simple lemma will be used several times:
Lemma 3
For every Turing machine M there are constants c, d such that for every
input w for M of length n ≥ 1 and every m ≥ 1 the following hold:
There are at most c · n · d m configurations of length ≤ m with input
w.
Let M be f -space bounded with f monotonically increasing. The
number of configurations that can be reached from Start(w ) is at
most c · n · d f (n) .
In particular: If f ∈ Ω(log(n)), then the number of configurations that
can be reached from Start(w ) is bounded by 2O(f (n)) .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
9 / 144
Complexity classes
Let f : N → N be a monotonically increasing function.
DTIME(f ) = {L(M) | M deterministic & f -time bounded}
NTIME(f ) = {L(M) | M non-deterministic & f -time bounded}
DSPACE(f ) = {L(M) | M deterministic & f -space bounded}
NSPACE(f ) = {L(M) | M non-deterministic & f -space bounded}
For a class C of languages let CoC = {L | Σ∗ \ L ∈ C} be the set of all
complements of languages from C.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
10 / 144
Complexity classes
We will consider the classes DTIME(t) and NTIME(t) only for functions
t(n) with ∀n ∈ N : t(n) ≥ n.
This allows to read the whole input.
We will consider the classes DSPACE(s) and NSPACE(s) only for
functions s(n) ∈ Ω(log(n)).
This allows to store a position i ∈ {1, . . . , n} in the input word on the
working tapes.
Lemma 4
Let f , g : N → N be monotonically increasing functions that differ for only
finitely many values and let X ∈ {D, N}.
If f (n), g (n) ≥ n then XTIME(f ) = XTIME(g ).
XSPACE(f ) = XSPACE(g )
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
11 / 144
Important complexity classes
Some abbreviations:
L = DSPACE(log(n))
(1)
NL = NSPACE(log(n))
[
DTIME(nk )
P =
(2)
(3)
NP =
(4)
k≥1
[
NTIME(nk )
k≥1
PSPACE =
[
k≥1
DSPACE(nk ) =
[
NSPACE(nk )
(5)
k≥1
The identity = in (5) is known as Savitch’s theorem.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
12 / 144
Some relations between complexity classes
PSPACE = IP
?
6=
NSPACE(n) = CoNSPACE(n)
? (1. LBA Problem)
DSPACE(n)
6=
S
S
k
k
k≥1 NSPACE(log (n))
k≥1 DSPACE(log (n)) =
NP
?
NP ∩ CoNP
?
P
6=
?
NL
?
L
There are many other complexity classes, see the complexity zoo
(http://qwiki.caltech.edu/wiki/Complexity Zoo)
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
13 / 144
Examples
{an bn c n | n ≥ 1} ∈ L
{w $w | w ∈ Σ∗ } ∈ L
The set PRIM = {p ∈ 1{0, 1}∗ | p is the binary coding of a prime
number} belongs to DSPACE(n).
Agrawal, Kayal and Saxena proved in 2002 that PRIM ∈ P holds, see
e.g. Dietzfelbinger’s book Primality Testing in Polynomial Time.
Note: PRIM consists of binary coded numbers. For the set
{an | n is a prime number}
of unary codings of prime numbers it is easy to show that it belongs
to the class P.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
14 / 144
Variants of algorithmic problems
Beispiel 1: Traveling Salesman Problem (TSP)
A sales man wants to visit several cities without visiting a city twice, and
he wants to take the shortest root. We can view the map as a directed
graph with edge weights. The nodes are the cities and the weight of the
edge from u to v is the distance when traveling from u to v .
Let G = (V , E , γ : E → N) be a graph with node set V = {1, . . . , n},
edges E ⊆ V × V and edge weights γ(e) ∈ N \ {0} for all e ∈ E .
A round tour W is a sequence of nodes W = (x0 , . . . , xn ), x0 = xn , xi 6= xj
for 1 ≤ i < j ≤ n and (xi−1 , xi ) ∈ E for 1 ≤ i ≤ n.
The cost γ(W ) ofP
the round tour W is given by the sum of the edge
weights: γ(W ) = ni=1 γ(xi−1 , xi ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
15 / 144
Variants of algorithmic problems
(A) Decision variant:
input: G = (V , E , γ : E → N) and k ≥ 0.
question: Does there exist a round tour with cost ≤ k?
(B) Computation variant:
input: G = (V , E , γ : E → N) and k ≥ 0.
goal: Compute a round tour W with γ(W ) ≤ k; if such a round tour does
not exist then output “no”.
(C) Optimization variant:
input: G = (V , E , γ : E → N).
goal: Compute a round tour with minimal cost.
Size of the input (up to some multiplicative constant):
P
|V | + e∈E ⌈log(γ(e))⌉ + ⌈log(k)⌉ for (A) and (B)
P
|V | + e∈E ⌈log(γ(e))⌉ for (C).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
16 / 144
Variants of algorithmic problems
From a practical point of view, variant (C) is the most relevant one.
But: (A) solvable in poly. time
=⇒
(C) solvable in poly. time.
Proof:
Step 1:
Check, whether there exists a round tour:
Call (A) with kmax = |V | · max{γ(e) | e ∈ E }.
Note: There exists a round tour if and only if there exists a round tour
with cost ≤ kmax .
In the following, we assume that there exists a round tour.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
17 / 144
Variants of algorithmic problems
Step 2:
Compute kopt = min{γ(W ) | W is a round tour} using binary search:
FUNCTION kopt
kmin := 1 (alternatively kmin := |V |)
while kmin < kmax do
min
kmiddle := kmin + ⌈ kmax −k
⌉
2
if ∃ round tour W with γ(W ) ≤ kmiddle then kmax := kmiddle
else kmin := kmiddle + 1
endif
endwhile
return kmin
ENDFUNC
Note: The number of executions of the while-loop is bounded by
log2 (kmax ) = log2 (|V | · max{γ(e) | e ∈ E }) = log2 (|V |) + log2 (max{γ(e) |
e ∈ E }) ≤ input size.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
18 / 144
Variants of algorithmic problems
Step 3:
Compute an optimal round tour:
FUNCTION optimal round tour
let e1 , e2 , . . . , em be arbitrary enumeration of E
G0 := G
for i := 1 to m do
if ∃ round tour W in Gi−1 \ {ei } with γ(W ) ≤ kopt then
Gi := Gi−1 \ {ei }
else
Gi := Gi−1
endif
endfor
return Gm
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
19 / 144
Variants of algorithmic problems
Claim: For all i ∈ {0, . . . , m} we have:
1 In G there exists a round tour W with γ(W ) = k
opt .
i
2 Every round tour W in G with γ(W ) = k
contains
all edges from
opt
i
{e1 , . . . , ei } ∩ E [Gi ] (E [Gi ] = set of edges of Gi ).
Proof:
1
2
Easy induction over i.
Assume that there is a round tour W in Gi with γ(W ) = kopt and an
edge ej (1 ≤ j ≤ i) with:
ej belongs to the graph Gi
ej does not belong to the round tour W
W is also a round tour in Gj−1 . ⇒
W is a round tour in Gj−1 \ {ej }. ⇒
ej does not belong to Gj and therefore not to Gi . Contradiction!
Consequence: Gm has a round tour W with γ(W ) = kopt and every edge
of Gm belongs to W .
⇒ Gm = W
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
20 / 144
Variants of algorithmic problems
Beispiel 2: Vertex Cover (VC)
¡ ¢
Let G = (V , E ) be an undirected graph (i.e., E ⊆ V2 ).
A subset C ⊆ V is a vertex cover of G if {u, v } ∩ C 6= ∅ for every edge
{u, v } ∈ E .
(A) Decision variant:
input: G = (V , E ) and k ≥ 0.
question: Does G have a vertex cover C with |C | ≤ k?
(B) Computation variant:
input: G = (V , E ) and k ≥ 0.
goal: Compute a vertex cover C with |C | ≤ k (if such a vertex cover
exists).
(C) Optimization variant:
input: G = (V , E ).
goal: Compute a vertex cover of G of minimal cardinality.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
21 / 144
Variants of algorithmic problems
Again we have: (A) solvable in poly. time =⇒ (C) solvable in poly. time.
Sow this as an excercise.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
22 / 144
The graph reachability problem
The graph reachability problem (GAP — for graph accessibility problem) is
a central decision problem in complexity problem:
INPUT: A directed graph G = (V , E ) and two nodes s, t ∈ V .
QUESTION: Does there exist a path in G from s to t?
GAP belongs to the class P: GAP can be solved in time O(|V |) using
breadth-first search.
But GAP even belongs to NL (soon we will show NL ⊆ P):
FUNCTION GAP
var v := s
while v 6= t do
choose non-deterministically a node w ∈ V with (v , w ) ∈ E
v := w
endwhile
return there is a path from s to t.“
”
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
23 / 144
The graph reachability problem
This non-deterministic algorithm can be easily implemented on a
non-deterministic Turing machine.
Why does this algorithm only use logarithmic space?
At every point of time, the algorithm only has to store the current
node v ∈ V .
If the graph has n nodes, then we can identify the nodes with the
numbers 1, . . . , n. A number from this interval can be stored using
only log2 (n) = log2 (|V |) many bits.
Remarks:
From Savitch’s theorem (later) we will obtain
GAP ∈ DSPACE(log2 (n)).
Reingold proved in 2004 that the graph reachability problem for
undirected graphs (UGAP) belongs to the class L, see
http://www.wisdom.weizmann.ac.il/∼reingold/publications/sl.ps
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
24 / 144
Chapter 2: Relationships between complexity classes
The proofs of the following results can be found in standard text books
(e.g. Hopcroft, Ullman; Introduction to Automata Theory, Languages and
Computation, Addison Wesley 1979).
We will only sketch the proofs.
S
For a function f : N → N let DTIME(O(f )) = c∈N DTIME(c · f ), and
analogously for NTIME, DSPACE, NSPACE.
Theorem 5
Let f : N → N.
1
For X ∈ {D, N} we have XSPACE(O(f )) = XSPACE1-tape (f ).
2
∃ǫ > 0 ∀n : f (n) ≥ (1 + ǫ)n
3
NTIME(O(f )) = NTIME(f ).
4
DTIME(n) ( DTIME(O(n)).
=⇒
DTIME(O(f )) = DTIME(f ).
Point 1 combines tape reduction with tape compression.
The statements in points 2 and 3 are known as time compression.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
25 / 144
The theorem of Hennie and Stearns (1966)
The theorem of Hennie and Stearns is a tape reduction theorem for time
complexity classes:
Theorem 6
Let k ≥ 1 and assume that ∃ε > 0 ∀n : f (n) ≥ (1 + ε)n. Then we have:
DTIMEk-tape (f ) ⊆ DTIME2-tape (f · log(f )).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
26 / 144
DTIME(f ) ⊆ NTIME(f ) ⊆ DSPACE(f )
Theorem 7
Assume that ∀n : f (n) ≥ n. Then
DTIME(f ) ⊆ NTIME(f ) ⊆ DSPACE(f ).
Proof: We only have to show that NTIME(f ) ⊆ DSPACE(f ).
Let M = (Q, Σ, Γ, δ, q0 , F , ¤) be a non-deterministic f -time bounded
Turing machine.
An input w ∈ Σ∗ of length n is accepted by M if and only if there exists a
protocol P = d1 d2 · · · dm ∈ δ ∗ with m ≤ f (n) uand
Start(w ) ⊢d1 c1 ⊢d2 c2 · · · ⊢dm cm ∈ Accept.
We systematically search over all protocols P of length ≤ f (n) (e. g. in
length lexicographical order) and check whether P leads from Start(w ) to
an accepting configuration.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
27 / 144
DTIME(f ) ⊆ NTIME(f ) ⊆ DSPACE(f )
Note:
Every configuration that can be reached from Start(w ) in ≤ f (n)
steps only needs space f (n).
A protocol of length ≤ f (n) can be stored in space O(f (n)).
Total space needed: O(f ) + O(f ) = O(f ).
FUNCTION search-protocol(w )
for all P ∈ δ ∗ with |P| ≤ f (|w |) do
let P = d1 d2 · · · dm
compute the unique configuration cm (if it exists) with
Start(w ) ⊢d1 c1 ⊢d2 c2 · · · ⊢dm cm
if cm ∈ Accept then
return M accepts w
endfor
return M does not accept w
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
28 / 144
DSPACE(f ) ⊆ NSPACE(f ) ⊆ DTIME(2O(f ) )
Theorem 8
Assume that f (n) ∈ Ω(log(n)). Then:
DSPACE(f ) ⊆ NSPACE(f ) ⊆ DTIME(2O(f ) ).
Proof: We only have to show NSPACE(f ) ⊆ DTIME(2O(f ) ).
Let M be an f -space bounded non-deterministic Turing machine and
w ∈ Σ∗ an input of length n.
By Lemma 3, the number of configurations that can be reached from
Start(w ) is bounded by 2O(f (n)) .
We compute the set R of all configurations that can be reached from
Start(w ):
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
29 / 144
DSPACE(f ) ⊆ NSPACE(f ) ⊆ DTIME(2O(f ) )
FUNCTION set-of-reachable-configurations
var R := {Start(w )}
while ∃ configurations α, β : α ∈ R ∧ β 6∈ R ∧ α ⊢M β do
R := R ∪ {β}
endwhile
if Accept ∩ R 6= ∅ then return M accepts w
ENDFUNC
Total time needed:
R contains at most 2O(f (n)) many configurations of length ≤ f (n).
Thus, the condition
∃ configurations α, β : α ∈ R ∧ β 6∈ R ∧ α ⊢M β can be checked in
time 2O(f (n)) · 2O(f (n)) · O(f (n)) = 2O(f (n)) .
Total time needed: 2O(f (n))
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
30 / 144
Consequences
L ⊆ NL ⊆ DTIME(2O(log(n)) ) = P
CS = LBA = NSPACE(n) ⊆ DTIME(2O(n) )
Here, CS denotes the class of context-sensitive languages and LBA
the class of languages accepted by linear bounded automata.
2
DSPACE(n2 ) ⊆ DTIME(2O(n ) )
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
31 / 144
Savitch’s Theorem (1970)
Theorem 9 (Savitch’s Theorem)
Assume that s ∈ Ω(log(n)). Then NSPACE(s) ⊆ DSPACE(s 2 ).
We only proof Savitch’s theorem under the additional assumption that the
function s is space constructible:
A function f : N → N with f ∈ Ω(log(n)) is space constructible, if
there is a deterministic f -space bounded Turing machine that for
input an (i.e. n unary coded) marks (with some special tape symbol)
the first f (n) many cells on each work tape and then stops.
A function f : N → N with f ∈ Ω(n) is time constructible, if there is
a deterministic Turing machine that on input an terminates after
exactly f (n) steps.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
32 / 144
Proof of Savitch’s Theorem
Proof of Savitch’s Theorem:
Let M be an s-space bounded non-deterministic Turing machine and w an
input for M.
Let Conf(M, w ) be the set of all configurations α with:
The input tape contains w .
|α| ≤ s(|w |).
Thus, Conf(M, w ) contains all configurations that can be reached from
Start(w ).
W.l.o.g. we can assume that Accept only contains a single configuration
αf .
For α, β ∈ Conf(M, w ) and i ≥ 0 we define:
Reach(α, β, i)
⇐⇒
∃k ≤ 2i , α0 , α1 , . . . , αk ∈ Conf(M, w ) :
α0 = α, αk = β,
k
^
αi−1 ⊢M αi
i=1
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
33 / 144
Proof of Savitch’s Theorem
By Lemma 3 and s(n) ∈ Ω(log(n)), there exists a constant c such that for
all inputs w :
w ∈ L(M)
⇐⇒
Reach(Start(w ), αf , c · s(|w |)).
Our goal is to check the predicate Reach(α, β, i) for α, β ∈ Conf(M, w )
and 0 ≤ i ≤ c · s(|w |) in space O(s(|w |)2 ) on a deterministic machine.
For i > 0 we use the following recursion:
Reach(α, β, i)
⇐⇒
∃γ ∈ Conf(M, w ) : Reach(α, γ, i − 1) ∧
Reach(γ, β, i − 1).
Translation into a deterministic algorithm:
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
34 / 144
Proof of Savitch’s Theorem
FUNCTION Reach(α, β, i) (where α, β ∈ Conf(M, w ) and i ≤ c · s(|w |)
var b := false
if i = 0 then
b := [(α = β) ∨ (α ⊢M β)]
else
forall γ ∈ Conf(M, w ) do
if not b and Reach(α, γ, i − 1) then
b := Reach(γ, β, i − 1)
endif
endfor
endif
return b
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
35 / 144
Proof of Savitch’s Theorem
Claim: There is a constant ̺ such that every call of Reach(α, β, i) needs
space at most ̺ · (i + 1) · s(|w |).
We prove the claim by induction over i ≥ 0:
i = 0: The condition [(α = β) ∨ (α ⊢M β)] can be checked in space
̺ · s(|w |) for a suitable constant ̺.
i > 0: By induction, the 1st call Reach(α, γ, i − 1) needs space
̺ · i · s(|w |). The same holds for the 2nd call Reach(γ, β, i − 1).
Note: For the 2nd call Reach(γ, β, i − 1) we can reuse the space needed
for the 1st call Reach(α, γ, i − 1).
In addition we need space 3 · s(|w |) + c · s(|w |) ≤ ̺ · s(|w |) (if ̺ ≥ c + 3)
for the configurations α, β, γ and the number i (unary coded). This proves
the claim.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
36 / 144
Proof of Savitch’s Theorem
In order to check w ∈ L(M) we call Reach(Start(w ), αf , c · s(|w |)).
Note: For this, we have to compute s(|w |) (unary coded). This is possible
since by assumption the function s is space constructible.
Total space needed: O(c · s(|w |) · s(|w |)) = O(s(|w |)2 ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
37 / 144
Remarks to Savitch’s Theorem
Savitch’s theorem says that a non-deterministic space bounded Turing
machine can be simulated by a deterministic Turing machine with a
quadratic blowup in space. This simulation increases the computation time
a lot!
Exercise: How much time needs the algorithm in our proof of Savitch’s
theorem to check whether w ∈ L(M)?
In order to get rid of space constructibility of the function s, one has to
show that the actual space needed by an s-space bounded
non-deterministic Turing machine can be computed in DSPACE(s 2 ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
38 / 144
Consequences of Savitch’s Theorem
Theorem 10
GAP belongs to DSPACE(log2 (n)).
Follows from GAP ∈ NL and Savitch’s theorem.
Theorem 11
PSPACE =
S
k≥1 DSPACE(n
k)
=
S
k≥1 NSPACE(n
k)
Follows from NSPACE(nk ) ⊆ DSPACE(n2k )
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
39 / 144
Hierarchy Theorems
Theorem 12 (Space hierarchy theorem)
Let s1 , s2 : N → N, s1 ∈
/ Ω(s2 ), s2 ∈ Ω(log(n)), and s2 be space
constructible. Then, DSPACE(s2 ) \ DSPACE(s1 ) 6= ∅.
Comments:
s1 ∈
/ Ω(s2 ) means ∀ǫ > 0 ∃ infinitely many
½ n2 with s1 (n) < ǫ · s2 (n).
n , if n is even
,
For instance, for s1 (n) = n and s2 (n) =
log n, else
we have s2 ∈
/ Ω(s1 ) and s1 ∈
/ Ω(s2 ).
The space hierarchy theorem implies for instance
L ( DSPACE(log2 (n)) ( DSPACE(n)
⊆ NSPACE(n) ( DSPACE(n2,1 ) ( PSPACE
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
40 / 144
Proof of the space hierarchy theorem
The proof of the space hierarchy theorem is similar to the proof of
undecidability of the halting problem: diagonalisation
First, we choose a suitable binary encoding of deterministic 1-tape Turing
machines with input alphabet {0, 1} that allows an efficient simulation
(will be made more precise in a moment).
Every word x ∈ {0, 1}∗ has to be the encoding of a Turing machine Mx
(if x is not well-formed, then Mx is a fixed default Turing machine).
Important convention: For all x ∈ {0, 1}∗ and all k ∈ N, Mx = M0k x ,
i. e. x and 0k x encode the same machine.
Consequence: Every Turing machine has a code for almost every length.
Goal: A deterministic s2 -space bounded Turing machine M with
L(M) ∈
/ DSPACE(s1 ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
41 / 144
Proof of the space hierarchy theorem
s2 ∈ Ω(log(n)) Ã ∃δ > 0 ∃m ∀n ≥ m : log2 (n) ≤ δ · s2 (n)
We start with a deterministic universal Turing machine U.
The input of U consists of the binary code x of a deterministic 1-tape
Turing machine Mx and an input w ∈ {0, 1}∗ for Mx .
U simulates Mx on input w .
We can choose the coding of Turing machines and U such that for every
x ∈ {0, 1}∗ there is a constant kx (depends only on Mx ) we have:
If Mx is s-space bounded, then U on input hx, w i needs space at most
1
kx · s(|w |) + 1+δ
log2 (|w |).
Lemma 3 Ã there is a constant c such that there are ≤ n · c m many
configurations of U with space m and a fixed input of length n.
Our machine M works for an input y = 0ℓ x (where x does not start with
0) of length n = |y | as follows:
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
42 / 144
Proof of the space hierarchy theorem
1
2
3
4
5
Mark space s2 (n) on the working tapes and install a counter C with
initial value 2n · c s2 (n) + 1 (needs space ≤ s2 (n) after sufficient space
compression).
This is possible since s2 is space constructible.
As soon as the machine M leaves the marked space it stops in a
non-accepting state.
This ensures that M is s2 -space bounded.
Execute the universal machine U with input hy , y i (of length 2n) and
set C := C − 1 after every transition of U.
If C reaches the value 0 and the simulation of My = Mx hasn’t
terminated so far, then U must be in an endless loop.
This means that Mx does not terminate on input y .
Then M accepts the input y .
If the simulation terminates before, then M accepts input y if and
only if Mx does not accept input y .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
43 / 144
Proof of the space hierarchy theorem
Claim: L(M) ∈
/ DSPACE(s1 )
Proof by contradiction: Assume that L(M) ∈ DSPACE(s1 ).
Let M ′ be an s1 -space bounded deterministic 1-tape Turing machine with
L(M ′ ) = L(M) (exists!).
Let M ′ = Mx .
The machine U simulates the machine M ′ = Mx on an input of length n in
1
log2 (n).
space kx · s1 (n) + 1+δ
Here, kx is a constant that only depends on x (in particular, it does not
depend on n).
Since s1 ∈
/ Ω(s2 ), there exists n ≥ |x| with
kx (1 + δ) · s1 (n) + log2 (n) ≤ s2 (n) + log2 (n) ≤ (1 + δ) · s2 (n)
and hence
kx · s1 (n) +
Markus Lohrey (Universität Leipzig)
1
log2 (n) ≤ s2 (n).
1+δ
Complexity Theory
WS 2012/2013
44 / 144
Proof of the space hierarchy theorem
Therefore, during the simulation of M ′ = Mx = M0n−|x| x on input 0n−|x| x
(of length n), the machine M does not leave the space which was marked
during step 1.
Hence:
0n−|x| x ∈ L(M)
Markus Lohrey (Universität Leipzig)
⇐⇒
M accepts 0n−|x| x
⇐⇒
Mx does not accept 0n−|x| x
⇐⇒
M ′ does not accept 0n−|x| x
⇐⇒
0n−|x| x 6∈ L(M ′ ) = L(M)
Complexity Theory
WS 2012/2013
45 / 144
Time hierarchy theorem
By the theorem of Hennie und Stearns (Theorem 6) one can simulate an
arbitrary number of tapes on two tapes with only a logarithmic increase of
computation time.
Using this, one can show analogously to the space hierarchy theorem the
following time hierarchy theorem.
Theorem 13 (Deterministic time hierarchy theorem (without proof))
Let t1 , t2 : N → N, t1 · log(t1 ) ∈
/ Ω(t2 ), t2 ∈ Ω(n log(n)) and t2 be time
constructible. Then DTIME(t2 ) \ DTIME(t1 ) 6= ∅.
A consequence is:
DTIME(O(n)) ( DTIME(O(n2 )) ( P
( DTIME(O(2n )) ( DTIME(O((2 + ε)n ))
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
46 / 144
The theorem of Borodin
In the above hierarchy theorems, we assumed space (reps., time)
constructibility. By the following gap theorem, this cannot be avoided.
Theorem 14 (Theorem of Borodin (1972))
Let r be a total, computable and monotone function with r (n) ≥ n for all
n. Then there exists effectively a total and computable function s : N → N
such that s(n) ≥ n + 1 for all n and DTIME(s) = DTIME(r ◦ s).
Remarks:
The composition r ◦ s is defined by r ◦ s(x) = r (s(x)).
That the total computable function s : N → N exists effectively
means that from a Turing machine that computes r we can compute
a Turing machine that computes s.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
47 / 144
Proof of Borodin’s theorem
Let M1 , M2 , . . . be an enumeration of all deterministic Turing machines.
Let tk (n) ∈ N ∪ {∞} be the maximal length of a computation of the
machine Mk on an input of length ≤ n.
Consider the set
Nn = {tk (n) | 1 ≤ k ≤ n} ⊆ N ∪ {∞}.
This set is finite, hence there exists for every n a number s(n) with
Nn ∩ [s(n), r (s(n))] = ∅.
An s(n), which satisfies this condition is
s(n) = 1 + max{tk (n) | 1 ≤ k ≤ n, tk (n) < ∞}.
But this value is too big and cannot be computed from n.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
48 / 144
Proof of Borodin’s theorem
Instead, we compute for a number n the value s(n) as follows:
FUNCTION s(n)
s := max{n + 1, s(n − 1)} (s := 1 for n = 0)
repeat
s := s + 1
until ∀k ≤ n : [tk (n) < s or tk (n) > r (s)]
return s
ENDFUNC
Remark: The function s is computable and grows monotonically.
But s is not time constructible.
Claim: DTIME(s) = DTIME(r ◦ s)
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
49 / 144
Proof of Borodin’s theorem
Proof of the claim:
Since r (n) ≥ n for all n, DTIME(s) ⊆ DTIME(r ◦ s) is obvious.
Assume that L ∈ DTIME(r ◦ s).
Let Mk be an (r ◦ s)-time bounded deterministic Turing machine with
L = L(Mk ).
Then ∀n : tk (n) ≤ r (s(n)) holds.
By the algorithm for s, we get tk (n) < s(n) for all n ≥ k.
We get L ∈ DTIME(s), because for all inputs of length < k (a constant)
the Turing machine can directly after reading the input output the right
answer; for this only n + 1 ≤ s(n) steps are necessary.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
50 / 144
The Theorem of Immerman and Szelepcsényi (1987)
The classes DTIME(f ) and DSPACE(f ) are closed under complement.
Whether this holds for the class NSPACE(f ) as well was open for a long
time.
Already in 1964, Kuroda asked, whether the class of context-sensitive
languages is closed under complement (2nd LBA problem).
Equivalently: NSPACE(n) = CoNSPACE(n)?
After more than 20 years, this question was answered independently by
R. Szelepcsényi und N. Immerman:
Theorem 15 (Theorem of Immerman and Szelepcsényi)
Let f ∈ Ω(log(n)) be monotonically increasing. Then
NSPACE(f ) = CoNSPACE(f ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
51 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Proof technique: Inductive counting
Let M be a non-deterministic f -space bounded 1-tape Turing machine and
w ∈ Σ∗ an input word of length n.
Goal: Check non-deterministically in space O(f (n)), whether w 6∈ L(M).
W.l.o.g. let α0 = (qf , 1, ε, 1) be the unique accepting configuration, where
qf is the unique accepting state (note: |α0 | = 0).
We need an enumeration α0 ≺ α1 ≺ α2 · · · of all configurations of M with
input w such that:
α0 is the smallest configuration w.r.t. ¹.
α ¹ α′ implies |α| ≤ |α′ |.
α ¹ α′ can be checked in space |α| + |α′ |.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
52 / 144
Proof of the Theorem of Immerman and Szelepcsényi
We can define ¹ as follows, where α = (q, i, u, j) and α′ = (q ′ , i ′ , u ′ , j ′ )
are configurations of M with input w :
If |u| < |u ′ |, then α ≺ α′ .
If |u| = |u ′ | and u <lex u ′ , then α ≺ α′ .
If u = u ′ and j < j ′ , then α ≺ α′ .
If u = u ′ , j = j ′ and i < i ′ , then α ≺ α′ .
If u = u ′ , j = j ′ , i = i ′ and q < q ′ , then α ≺ α′ .
Here, we fix an arbitrary order ≤ on the set of states of M, where qf
is the smallest state.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
53 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Let k ≥ 0:
R(k) = {α | ∃i ≤ k : Start(w ) ⊢iM α}
r (k) = |R(k)| (number of configurations reachable from
Start(w ) in ≤ k steps)
r (∗) = max{r (k) | k ≥ 0}
(number of configurations reachable from Start(w ))
Note: By Lemma 3 we have
r (k) ≤ r (∗) ∈ 2O(f (n)) .
Since f is not assumed to be space constructible, we also need the value
m(k) = max{|α| | α ∈ R(k)}.
We compute r (∗) in space O(f (n)). Our algorithm will output ERROR if
w ∈ L(M). If w ∈
/ L(M), then the correct value r (∗) will be returned.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
54 / 144
Proof of the Theorem of Immerman and Szelepcsényi
We compute r (∗) under the assumption that r (k + 1) can be computed
from r = r (k) with the function compute-r(k + 1, r ) in space O(f (n)):
FUNCTION r (∗)
k := 0
r := 1 (∗ stores r (k) ∗)
while true do
r ′ := compute-r(k + 1, r )
if r = r ′ then return r
else k := k + 1; r := r ′
endwhile
ENDFUNC
Space needed: Because of r (∗) ∈ 2O(f (n)) , we need space at most
O(f (n)) for the variables k, r , and r ′ .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
55 / 144
Proof of the Theorem of Immerman and Szelepcsényi
The computation of compute-r(k + 1, r ) is divided into three steps.
Step 1: Compute m(k) from r = r (k) with the function compute-m(k, r )
FUNCTION compute-m(k, r )
α := α0 ; m := 0(= |α0 |)
repeat r times
compute an arbitrary α′ ∈ R(k)
if α ≺ α′ then
α := α′
m := |α′ | (∗ = max{m, |α′ |} due to the order ∗)
else
return ERROR
endif
endrepeat
return m
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
56 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Note:
If compute-m(k, r ) does not stop with ERROR and r = r (k) holds,
then the correct value m(k) will be returned.
If α0 ∈ R(k) (and hence w ∈ L(M)), then compute-m(k, r ) will stop
with ERROR, since in R(k) there do not exist r many configurations
which are strictly larger than α0 .
Inparticular: If w ∈ L(M), then there exists a k such that
compute-m(k, r ) will stop with ERROR. This will also stop the
computation of r (∗).
If w 6∈ L(M), then our non-determinisitic algorithm has the chance to
avoid stopping with ERROR. Then then the correct value m(k) will
be computed.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
57 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Space needed by compute-m(k, r ): We have to store:
configurations α, α′ with |α|, |α′ | ≤ f (n).
m ≤ f (n)
binary counter up to k (in order to generate non-deterministically an
arbitrary α′ ∈ R(k))
binary counter up to r = r (k) (for repeat r times).
Space O(f (n)) suffices for this.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
58 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Step 2: Let β be a configuration. Procedure Reach(r , k + 1, β) tests
non-deterministically, using the value r = r (k), whether β ∈ R(k + 1)
holds:
FUNCTION Reach(r , k + 1, β)
α := α0
repeat r times
compute arbitrary α′ ∈ R(k)
if α′ ¹ α then return ERROR
elseif α′ = β ∨ α′ ⊢M β then return true (∗ i.e. β ∈ R(k + 1) ∗)
else α := α′
endif
endrepeat
return false (∗ i.e. β ∈
/ R(k + 1) ∗)
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
59 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Note:
If Reach(r (k), k + 1, β) does not stop with ERROR, then the correct
answer will be returned.
If w 6∈ L(M) (and hence α0 6∈ R(k)), then Reach(r (k), k + 1, β) has
the chance to avoid stoppig with ERROR.
Space needed: We have to store:
configurations α, α′ with |α|, |α′ | ≤ f (n).
binary counter up to k (in order to non-deterministically generate an
arbitrary α′ ∈ R(k))
binary counter up to r = r (k) (for repeat r times).
Space O(f (n)) suffices for this.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
60 / 144
Proof of the Theorem of Immerman and Szelepcsényi
Step 3: Compute r (k + 1) with the function compute-r(k + 1, r ) and
r = r (k).
FUNCTION compute-r(k + 1, r )
r ′ := 0 (∗ equals r (k + 1) at the end ∗)
m := compute-m(k, r )
forall configurations β with |β| ≤ m + 1 do
if Reach(r , k + 1, β) then
r ′ := r ′ + 1
endif
endforall
return r ′
ENDFUNC
It is sufficient to only consider configurations β with |β| ≤ m(k) + 1, since
m(k + 1) ≤ m(k) + 1.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
61 / 144
Proof of the Theorem of Immerman and Szelepcsényi
A successful computation of r (∗) is possible if and only if w ∈
/ L(M).
To see this, note that: If w ∈ L(M), then every computation will return
ERROR, since the function call m(k) has to return ERROR as soon as k
reaches a value for which the accepting configuration α0 belongs to R(k).
Hence: If the value r (∗) is computed, then we know that w belongs to the
complement of L(M).
Space needed: Our previous space considerations show that the whole
algorithm only uses space O(f (n)).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
62 / 144
The translation technique
Translation theorems allow to deduce from an inclusion between small
complexity classes an inclusion between larger complexity classes.
Idea: Padding of languages.
Let
L ⊆ Σ∗ be a language,
f : N → N a function with ∀n ≥ 0 : f (n) ≥ n, and
$∈
/ Σ a new symbol.
Define the language
Padf (L) = {w $f (|w |)−|w | | w ∈ L} ⊆ (Σ ∪ {$})∗ .
Note: to every word from L of length n we assign a word from L$∗ of
length f (n).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
63 / 144
The translation theorem for time classes
Theorem 16 (Translation theorem for time classes)
Let f , g be monotone functions with ∀n ≥ 0 : f (n), g (n) ≥ n. Let g be
time constructible, and assume that from the unary input 1n one can
compute 1f (n) in time g (f (n)). For every L ⊆ Σ∗ we have:
1
Padf (L) ∈ DTIME(O(g )) ⇐⇒ L ∈ DTIME(O(g ◦ f )),
2
Padf (L) ∈ NTIME(O(g )) ⇐⇒ L ∈ NTIME(O(g ◦ f )).
Proof: We only prove the statement for DTIME; the proof for NTIME
works analogously.
⇒“: Let Padf (L) ∈ DTIME(O(g )) and w ∈ Σ∗ an input, |w | = n.
”
We check whether w ∈ L in time O(g (f (n))) as follows:
1
2
Compute the word w $f (n)−n in time g (f (n)).
Check in time O(g (f (n))), whether w $f (n)−n ∈ Padf (L).
By definition we have: w $f (n)−n ∈ Padf (L) ⇐⇒ w ∈ L.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
64 / 144
Proof of the translation theorem
⇐“: Let L ∈ DTIME(O(g ◦ f )) and let x ∈ (Σ ∪ {$})∗ be an input of
”
length m.
We check in time O(g (m)), whether x ∈ Padf (L) as follows:
1
Check in time m ≤ g (m) whether x ∈ w $∗ for some word w ∈ Σ∗ .
Let x = w $m−n with w ∈ Σ∗ , |w | = n.
2
Compute 1g (m) in time g (m) (g is time constructible).
3
Check in time g (m), whether f (n) = m holds:
Compute 1f (n) in time g (f (n)). If thereby the machine wants to
compute for more than g (m) steps, we reject (since g is monotone,
we have g (f (n)) > g (m) → f (n) > m).
If 1f (n) will be computed, we can compare 1f (n) with 1m .
Let x = w $f (n)−n .
4
Check in time O(g (f (n))) = O(g (m)), whether w ∈ L holds.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
65 / 144
The translation theorem for space classes
Theorem 17 (Translation theorem for space classes (without proof))
Let g ∈ Ω(log(n)) be space constructible and f (n) ≥ n for all n ≥ 0.
Assume that for a unary input 1n one can compute the binary
representation of f (n) in space g (f (n)). Then, for every L ⊆ Σ∗ we have:
1
Padf (L) ∈ DSPACE(g ) ⇐⇒ L ∈ DSPACE(g ◦ f ),
2
Padf (L) ∈ NSPACE(g ) ⇐⇒ L ∈ NSPACE(g ◦ f ).
Consequences: A collapse of complexity classes is more likely to happen
at the higher part of the complexity spectrum. There is more hope to
separate complexity classes at the lower part of the complexity spectrum.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
66 / 144
Consequences of the translation theorem for space classes
Theorem 18 (Corollary of the translation theorem for space classes)
DSPACE(n) 6= NSPACE(n) =⇒ L 6= NL.
Proof: Assume that L = NL.
Let L ∈ NSPACE(n).
We have Padexp (L) ∈ NSPACE(log(n)) = NL = L = DSPACE(log(n)).
The translation theorem for space classes implies
L ∈ DSPACE(exp ◦ log) = DSPACE(n).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
67 / 144
Consequences of the translation theorems
Using translation techniques one can in some cases prove that two
complexity classes are different:
Theorem 19 (Corollary of the translation theorems)
P 6= DSPACE(n).
Proof: Choose a language L ∈ DSPACE(n2 ) \ DSPACE(n) (exists by the
space hierarchy theorem) and the padding function f (n) = n2 .
We get Padf (L) ∈ DSPACE(n).
Assume now that DSPACE(n) = P.
We get Padf (L) ∈ DTIME(nk ) for some k ≥ 1 and
L ∈ DTIME(O(n2k )) ⊆ P = DSPACE(n).
This is a contradiction.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
68 / 144
Consequences of the translation theorems
Remarks:
Hence, P is not equal to the class of deterministic context sensitive
languages.
According to the current knowledge, each of DSPACE(log(n)) = P,
DSPACE(n) ⊂ P and P ⊂ DSPACE(n) is possible.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
69 / 144
Part 3: Reductions and complete problems
Let L ⊆ Σ∗ and L′ ⊆ Σ′ ∗ be two languages.
A reduction of L to L′ is a total computable function f : Σ∗ → Σ′ ∗ with:
∀x ∈ Σ∗ : x ∈ L ⇐⇒ f (x) ∈ L′ .
Assume we have an algorithm for deciding L′ . Then we can check whether
x ∈ L as follows:
∗
1 Compute the string f (x) ∈ Σ′
2 Decide with the algorithm for L′ whether f (x) ∈ L′ holds.
x
-
Mf
f (x)
-
M L′
- yes
- no
ML
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
70 / 144
Polynomial time reductions
A reduction f : Σ∗ → Σ′ ∗ of L to L′ is a polynomial time reduction, if f
can be computed by a deterministic polynomial time bounded Turing
machine.
Proposition 20
L′ ∈ P and ∃ polynomial time reduction of L to L′
=⇒
L ∈ P.
Proof: Assume that L′ belongs to DTIME(nk ) and f can be computed in
time nℓ .
For an input x ∈ Σ∗ of length n, f (x) can be computed in time nℓ .
This implies |f (x)| ≤ nℓ . Hence, we can check in time (nℓ )k = nk·ℓ
whether f (x) ∈ L′ (i.e., x ∈ L) holds.
Total time needed: nℓ + nk·ℓ
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
71 / 144
Logspace reductions
Many reductions can actually computed in logarithmic space.
⇒ logspace reductions
Definition Logspace transducer
A logarithmic space bounded transducer (logspace transducer) is a
deterministic Turing machine M with
a read-only input tape,
a read-write working tape of length log(input length), and
a write-only output tape.
In each computation step, M either
writes a new symbol on the output tape and the output tape head
moves one cell to the right, or
M does not write a new symbol on the output tape; in this case the
output tape head does not move.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
72 / 144
Logspace reductions
Definition
1
2
A function f : Σ∗ → Σ′ ∗ is logspace computable, if:
∃ logspace transducer M ∀x ∈ Σ∗ :
M finally stops on input x with f (x) ∈ Σ′ ∗ on the output tape.
A language L ⊆ Σ∗ is logspace reducible to L′ ⊆ Σ′ ∗ , if there exists a
logspace computable function f : Σ∗ → Σ′ ∗ with
∀x ∈ Σ∗ : x ∈ L ⇐⇒ f (x) ∈ L′ .
′
Briefly: L ≤log
m L.
The index m stands for many-one. This means that the reduction can
map several words from Σ∗ to Σ′ ∗ .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
73 / 144
Logspace reductions
Remarks:
Logspace reductions can be applied to classes within P and allow a
finer classification than polynomial time reductions.
Every logspace computable function f : Σ∗ → Σ′ ∗ can be computed
in polynomial time.
In particular: ∃k ≥ 0 ∀x ∈ Σ∗ : |f (x)| ≤ |x|k .
Logspace reductions and polynomial time reductions have equal
power if and only if L = P.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
74 / 144
≤log
m is transitive
Proposition 21 (≤log
m is transitive)
log ′′
′
L ≤log
m L ≤m L
=⇒
′′
L ≤log
m L
Note: The corresponding statement for polynomial time reductions is
trivial.
But there is a problem with the composition of two logspace reductions
f : Σ∗ → Σ′ ∗ and g : Σ′ ∗ → Σ′′ ∗ :
For input w ∈ Σ∗ with |w | = n we have |f (w )| ≤ nk (for some
constant k).
Hence, g (f (w )) can be computed from f (w ) in space
O(log(nk )) = O(log(n)).
But: in general, f (w ) cannot be stored on the working tape in
logarithmic space.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
75 / 144
≤log
m is transitiv
Proof of Proposition 21:
We compute g (f (w )) in space O(log(|w |) as follows:
Start the logspace transducer for g (without computing f (w ) before).
If during the computation of g the i-th symbol of f (w ) is needed,
then we restart the logspace transducer for f on the input w and run
the computation until the i-th symbol of f (w ) is computed.
Thereby, we do not write down the symbols 1, . . . , i − 1 of f (w ).
To accomplish this, we increment a binary counter every time the
logspace transducer for f outputs the next symbol of f (w ).
This binary counter needs space O(log(|f (w )|)) = O(log(|w |).
Example: Let f (n) = nk . Then f is logspace computable.
k −|w |
Hence, also the mapping w 7→ w $|w |
shows L ≤log
m Padf (L).
is logspace computable, which
∗
Vice versa: Padf (L) ≤log
m L for L 6= Σ .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
76 / 144
Complete problems
Definition
Let C be a complexity class and let L ⊆ Σ∗ be a language.
1
L is hard for C, briefly C-hard, (w.r.t. logspace reductions), if:
∀K ∈ C : K ≤log
m L.
2
L is C-complete (w.r.t. logspace reductions), if L is C-hard and L ∈ C.
Intuition: C-complete problems are the most difficult problems in the class
C. In some sense they represent the whole class C.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
77 / 144
GAP is NL-complete
Here is a first important example:
Theorem 22
The graph reachability problem GAP is NL-complete.
Proof: GAP ∈ NL was already shown.
Let L ∈ NL, and let M be a non-deterministic log(n)-space bounded
Turing machine with L = L(M).
We define a reduction f as follows: For w ∈ Σ∗ let f (w ) = (G , s, t), where
G = (V , E ) is the directed graph with:
V
= {c | c is config. of M with input w , |c| ≤ log(|w |)}
E
= {(c, d) | c, d ∈ V , c ⊢M d}
s = Start(w )
t = the w.l.o.g. unique accepting configuration of M.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
78 / 144
GAP is NL-complete
We have:
w ∈ L(M) ⇐⇒ in G there is a directed path from s to t.
Moreover, f can be computed in logspace.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
79 / 144
Part 4: NP-completeness
Theorem 23
If there is an NP-complete language, then there is an NP-complete
language in NTIME(n):
∃L : L is NP-complete ⇒ ∃L̃ ∈ NTIME(n) : L̃ is NP-complete.
Proof: Let L be an NP-complete problem.
There is a constant k > 0 with L ∈ NTIME(nk ).
The translation theorem for time classes implies that
Padnk (L) ∈ NTIME(n).
Take an arbitrary language L′ ∈ NP.
log
⇒ L′ ≤log
m L ≤m Padnk (L)
log
′
Since ≤log
m is transitive, we get L ≤m Padnk (L).
⇒ Padnk (L) is NP-complete.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
80 / 144
The generic NP-complete problem
Let hw , Mi be the encoding of a non-deterministic Turing machine M and
an input word w ∈ Σ∗ .
LGen = {hw , Mi $m |w ∈ Σ∗ , M non-deterministic Turing machine,
m ∈ N, M has an accepting computation
on input w of length ≤ m}
Theorem 24
LGen is NP-complete.
Proof:
LGen ∈ NP:
Here is a non-deterministic polynomial time algorithm for LGen :
On input hw , Mi $m , simulate M on input w non-deterministically for at
most m steps.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
81 / 144
The generic NP-complete problem
LGen is NP-hard:
Let L ∈ NP arbitrary and let M be an nk -time bounded non-deterministic
Turing machine with L = L(M) (k is a constant).
A reduction of L to LGen computes in logspace from an input w ∈ Σ∗ the
output
®
k
f (w ) = w , M $|w | .
We have: w ∈ L(M) ⇐⇒ f (w ) ∈ LGen .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
82 / 144
The Cook-Levin Theorem
Let Σ0 = {¬, ∧, ∨, ⇒, ⇔, 0, 1, (, ), x}.
Let A ⊆ Σ∗0 be the set of all propositional formulas with variables from
V = x1{0, 1}∗ .
A ⊆ Σ∗0 is deterministic context-free and therefore belongs to DTIME(n).
Let SAT = {F ∈ A | F is satisfiable}.
(A propositional formula F is satisfiable, if there exists an assignment
B : Var(F ) → {true, false} for the variables appearing in F such that F
evaluates to true under this assignment.)
Theorem 25 (Cook-Levin theorem)
SAT is NP-complete.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
83 / 144
Proof of the Cook-Levin Theorem
(A) SAT ∈ NP: For F ∈ Σ∗0 we check “F ∈ SAT” as follows:
1
Check in time O(|F |) whether F ∈ A holds.
2
If F ∈ A, then guess nondeterministically an assignment
B : Var(F ) → {true, false}.
3
Accept if F evaluates to true under the assignment B.
(B) SAT is NP-complete.
Let L ∈ NP.
From a given w ∈ Σ∗ we construct a formula f (w ) such that
w ∈L
⇐⇒
f (w ) satisfiable .
The function f will be logspace computable.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
84 / 144
Proof of the Cook-Levin Theorem
W.l.o.g. we can assume that every word x ∈ L has the form ⊲y where the
symbol ⊲ does not occur in y .
Let M = (Q, Σ, Γ, δ, q0 , F , ¤) be a p(n)-time bounded non-deterministic
Turing machine with L = L(M)
(p(n) > n is a polynom).
Let w = w1 w2 · · · wn ∈ Σ∗ be an input of length n that starts with w1 = ⊲.
W.l.o.g. M has the following properties:
1
M has only one read-write tape, where intitially the input w is stored.
2
(q, a, q ′ , a′ , D), (q, b, p ′ , b′ , D ′ ) ∈ δ =⇒ a = b, a′ = b′ , D = D ′
Only with respect to the next state q ′ there is a non-deterministic
choice (see next slide).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
85 / 144
Proof of the Cook-Levin Theorem
Property (2) can be enforced as follows:
W.l.o.g. we can asume that if M reads the symbol ⊲, then M writes again
⊲ on the tape and the head moves right.
Redefine the state set and the transition relation as follows:
Q ′ ={(q[a, a′ , D] | q ∈ Q, a, a′ ∈ Γ, D ∈ {→, ←, N}}
δ ′ ={(q[a, a′ , D], a, q ′ [b, b′ , D ′ ], a′ , D) | (q, a, q ′ , a′ , D) ∈ δ,
b, b′ ∈ Γ, D ′ ∈ {→, ←, N}}
The new initial state is q0 [⊲, ⊲, →].
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
86 / 144
Proof of the Cook-Levin Theorem
Assumption (1) implies that every configuration that can be reached from
the initial configuration can be represented by a word from the set
Conf = {¤uqv ¤ | q ∈ Q, uv ∈ Γp(n) }.
The initial configuration is ¤q0 w ¤p(n)−n+1 .
M accepts the input w if and only if M can reach from the initial
configuration in ≤ p(n) steps a state q ∈ F .
Notation: For α ∈ Conf we write
α = α[−1]α[0] · · · α[p(n)]α[p(n) + 1]
where α[−1] = ¤, α[0], . . . , α[p(n)] ∈ Q ∪ Γ, α[p(n) + 1] = ¤.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
87 / 144
Proof of the Cook-Levin Theorem
Define the set of 4-tuples
∆1 = {(a, b, c, b) | a, b, c ∈ Γ}
∪ {(c, b, q, p), (b, q, a, b), (q, a, d, a′ ) | (q, a, p, a′ , ←) ∈ δ, c, b, d ∈ Γ}
∪ {(c, b, q, b), (b, q, a, p), (q, a, d, a′ ) | (q, a, p, a′ , N) ∈ δ, c, b, d ∈ Γ}
∪ {(c, b, q, b), (b, q, a, a′ ), (q, a, d, p) | (q, a, p, a′ , →) ∈ δ, c, b, d ∈ Γ}
Because of assumption (2), we have for all α, α′ ∈ ¤(Q ∪ Γ)∗ ¤ with
|α| = |α′ |:
α, α′ ∈ Conf and α ⊢M α′
⇐⇒
α ∈ Conf and ∀i ∈ {0, . . . , p(n)} : (α[i − 1], α[i], α[i + 1], α′ [i]) ∈ ∆1 .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
88 / 144
Proof of the Cook-Levin Theorem
Example:
If (q, a, p, a′ , ←) ∈ δ then the following local tape modification is possible
for all b ∈ Γ:
Position
i−1
i
i+1
α
=
···
···
b
q
a
···
···
α′
=
···
···
p
b
a′
···
···
If (q, a, p, a′ , →) ∈ δ, then the following local tape modification is possible
for all b ∈ Γ:
position
i−1
i
i+1
α
=
···
···
b
q
a
···
···
α′
=
···
···
b
a′
p
···
···
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
89 / 144
Proof of the Cook-Levin Theorem
A computation of M can be represented as a matrix of the form:
α0
α1
= ¤
= ¤
α0,0
α1,0
α0,1
α1,1
..
.
...
...
αp(n) = ¤ αp(n),0 αp(n),1 . . .
α0,p(n)
α1,p(n)
¤
¤
αp(n),p(n) ¤
Define a second set of 4-tuples for looping at accepting states:
∆2 = {(q, a, b, a), (a, q, b, q), (a, b, q, b) | q ∈ F , a, b ∈ Γ}
For very tripel (a, i, t) (a ∈ Q ∪ Γ, −1 ≤ i ≤ p(n) + 1, 0 ≤ t ≤ p(n) + 1)
let x(a, i, t) be a propositional variable.
Interpretation: x(a, i, t) = true if and only if at time t, the i-th symbol
in the current configuration is a.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
90 / 144
Proof of the Cook-Levin Theorem
At position −1 and p(n) + 1 the symbol is always ¤:
µ
¶
^
G (n) =
x(¤, −1, t) ∧ x(¤, p(n) + 1, t)
0≤t≤p(n)+1
For every pair (i, t), exactly onle variable x(a, i, t) is true (i.e., at every
point of time, every tape position contains exactly one tape symbol):
X (n) =
^
0≤t≤p(n)+1
−1≤i≤p(n)+1
Markus Lohrey (Universität Leipzig)
¶
^
_ µ
¬x(b, i, t)
x(a, i, t) ∧
a∈Q∪Γ
Complexity Theory
b6=a
WS 2012/2013
91 / 144
Proof of the Cook-Levin Theorem
At time t = 0, the current configuration is ¤q0 w ¤p(n)−n+1 :
p(n)
n
^
^
S(w ) = x(q0 , 0, 0) ∧
x(wi , i, 0) ∧
x(¤, i, 0)
i=1
i=n+1
The computation respects the local relation ∆1 ∪ ∆2 :
!
Ã
_
^
x(a, i − 1, t) ∧ x(b, i, t) ∧
D(n) =
x(c, i + 1, t) ∧ x(d, i, t + 1)
0≤i≤p(n) (a,b,c,d)∈∆1 ∪∆2
0≤t≤p(n)
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
92 / 144
Proof of the Cook-Levin Theorem
Finally, let
f (w ) = G (n) ∧ X (n) ∧ S(w ) ∧ D(n).
Then there is a natural bijection between the set of satisfying
truth-assignments for the formula f (w ) and the set of accepting
computations for M on input w .
Hence, we have:
f (w ) satisfiable
⇐⇒
w ∈ L.
Number of variables of f (w ) ∈ O(p(n)2 )
Length of f (w ) ∈ O(p(n)2 log p(n))
The factor O(log p(n)) is necessary, since we need log p(n) bits for writing
down the indices in the variables x(a, i, t).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
93 / 144
Further NP-complete problems: (1) SAT ∩ CNF
Definition: Literals, CNF
A literal x̃ is either a propositional variable x or a negated propositional
variable ¬x.
Instead of ¬x we also write x. Moreover, let x = x.
Let CNF (resp., DNF) be the set of all propositional variables in
conjunctive normal form (resp., disjunctive normal form):
DNF = {F | F is a disjunction of conjunctions of literals}
CNF = {F | F is a conjunction of disjunctions of literals}
Fact: For every propositional formula F there exist equivalent formulas
DNF(F ) ∈ DNF and CNF(F ) ∈ CNF.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
94 / 144
Further NP-complete problems: (1) SAT ∩ CNF
Example:
F =
^
i=1,...,k
Ã
_
j=1,...,m
x̃i,j
!
≡
_
f ∈{1,...,m}{1,...,k}
Ã
^
x̃i,f (i)
i=1,...,k
!
= F′
Note:
|F | = m · k but |F ′ | = mk · k, i.e., a CNF-formula with k disjunctions
of length m can be transformed into an equivalent DNF-formula
consisting of mk conjunctions of length k.
For DNF-formulas satisfiability can be checked deterministically in
quadratic time.
We will see soon that satisfiability for CNF-formulas is still
NP-complete.
Hence, the exponential blow-up for the transformation from CNF to
DNF is not surprising.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
95 / 144
SAT ∩ CNF is NP-complete
Theorem 26
SAT ∩ CNF is NP-complete.
Proof:
(1) SAT ∩ CNF ∈ NP: trivial, since (i) SAT ∈ NP and (ii) for a formula
of length n we can check in time O(n) whether it is in CNF.
(2) SAT ∩ CNF is NP-hard:
In the proof for the NP-hardness of SAT we only constructed formulas
which are already in CNF apart from inner subformulas of constant length.
Hence, we can tranform the constructed formula in logspace into an
equivalent CNF-formula.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
96 / 144
3-SAT is NP-complete
Definition: 3-SAT
Let 3-CNF be the set of all CNF-formulas, where every clause
(=disjunction) has exactly 3 literals:
3-CNF := {F ∈ CNF | every clause of F contains exactly 3 literals}
3-SAT is the set of satisfiable 3-CNF formulas:
3-SAT := 3-CNF ∩ SAT
Theorem 27
3-SAT is NP-complete.
Proof: Only NP-hardness is non-trivial.
We show: SAT ∩ CNF ≤log
m 3-SAT.
Let F be a CNF-formula. We distinguish three cases:
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
97 / 144
3-SAT is NP-complete
1
F contains a clause (x̃) with a single literal.
Introduce a new variable y and replace (x̃) by (x̃ ∨ y ) ∧ (x̃ ∨ y ).
This has no influence on the satisfiability of F .
2
F contains a clause (x̃ ∨ ỹ ) with two literals.
Introduce a new variable z and replace (x̃ ∨ ỹ ) by
(x̃ ∨ ỹ ∨ z) ∧ (x̃ ∨ ỹ ∨ z).
3
F contains a clause with more than 3 literals.
Let c = (x̃1 ∨ x̃2 ∨ · · · ∨ x̃k ) be such a clause with k ≥ 4 literals.
Introduce k − 3 new variables v (x̃3 ), v (x̃4 ), . . . , v (x̃k−2 ), v (x̃k−1 ) and
replace c by
^¡
¢
¡
¢ k−2
v (x̃j ) ∨ x̃j ∨ v (x̃j+1 )
c ′ = x̃1 ∨ x̃2 ∨ v (x̃3 ) ∧
j=3
¢
¡
∧ v (x̃k−1 ) ∨ x̃k−1 ∨ x̃k .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
98 / 144
3-SAT is NP-complete
Note: c ′ can be also written as
c′ =
¡
^¡
¢
¢ k−2
v (x̃j ) ⇒ x̃j ∨ v (x̃j+1 )
x̃1 ∨ x̃2 ∨ v (x̃3 ) ∧
j=3
¡
¢
∧ v (x̃k−1 ) ⇒ x̃k−1 ∨ x̃k .
That (3) has now influence on satisfiability follows from the following
three points:
(A) Let σ be a satisfying assignment for c.
We must have σ(x̃i ) = 1 for some 1 ≤ i ≤ k.
Extend σ to a satisfying assignment for c ′ by:
(
1 if j ≤ i
′
σ (v (x̃j )) =
0 if j > i
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
99 / 144
3-SAT is NP-complete
(B) Let σ ′ be a satisfying assignment for c ′ .
Assume that σ ′ (x̃i ) = 0 for all 1 ≤ i ≤ k.
=⇒ σ ′ (v (x̃3 )) = 1 (since σ ′ (x̃1 ∨ x̃2 ∨ v (x̃3 )) = 1)
By induction we get: σ ′ (v (x̃i )) = 1 for all 3 ≤ i ≤ k − 1.
=⇒ σ ′ (v (x̃k−1 ) ∨ x̃k−1 ∨ x̃k )) = 0
Markus Lohrey (Universität Leipzig)
Contradiction!
Complexity Theory
WS 2012/2013
100 / 144
Integer Programming
Let
LinProg(Z) := {hA, bi | A ∈ Zm×n , b ∈ Zm×1 , ∃x ∈ Zn×1 : Ax ≥ b}
For numbers from Z we use the binary coding.
Theorem 28
LinProg(Z) is NP-complete.
Proof:
(1) LinProg(Z) ∈ NP:
This is the difficult part of the proof, see e.g. Hopcroft, Ullman;
Introduction to Automata Theory, Languages and Computation, Addison
Wesley 1979
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
101 / 144
Integer Programming
(2) LinProg(Z) is NP-hard.
We show 3-SAT ≤log
m LinProg(Z).
Let F = c1 ∧ c2 ∧ · · · ∧ cq be a 3-CNF formula.
Let x1 , . . . , xn be the variables of F .
We construct a system S of inequalities over Z and the variables
xi , xi , 1 ≤ i ≤ n:
1
xi ≥ 0, 1 ≤ i ≤ n
2
xi ≥ 0, 1 ≤ i ≤ n
3
xi + xi ≥ 1, 1 ≤ i ≤ n
4
−xi − xi ≥ −1, 1 ≤ i ≤ n
5
x̃j1 + x̃j2 + x̃j3 ≥ 1, for every clause cj = (x̃j1 ∨ x̃j2 ∨ x̃j3 ).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
102 / 144
Integer Programming
(3) and (4)
=⇒
xi + xi = 1
(1) and (2)
=⇒
xi = 1, xi = 0 oder xi = 0, xi = 1
(5)
=⇒
for every clause cj at least one literal x̃ij
has value 1
Hence: S is solvable if and only if F is satisfiable.
Size of S: 4n + q inequalities, 2n variables.
If we write S in matrix form Ax ≥ b, then A (resp.,. b) has (4n + q) × 2n
(resp., 4n + q) entries with absolute value ≤ 1.
Remarks:
Our hardness proof shows that LinProg(Z) is also NP-hard if we use
the unary coding of numbers.
LinProg(Q) ∈ P: This is a very difficult result
(Khachiyan 1979, Karmarkar 1984).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
103 / 144
Digression: Binary coded prime numbers
Let
PRIM = {w ∈ 1{0, 1}∗ | w is the binary coding of a prime number}
be the set of all binary coded prime numbers.
In August 2002, Agrawal, Kayal and Saxena proved PRIM ∈ P.
We only prove the following weaker result:
Theorem 29
PRIM ∈ NP ∩ CoNP.
Proof:
(1) PRIM ∈ CoNP is easy:
On input w ∈ 1{0, 1}∗ guess u, v ∈ 1{0, 1}+ with |u|, |v | ≤ |w | and check
whether w = u · v holds.
Note: From u, v ∈ 1{0, 1}∗ we can compute the product u · v in
polynomial time using the school method.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
104 / 144
PRIM ∈ NP
(2) PRIM ∈ NP: We need Fermat’s little theorem:
Fermat’s little theorem (without proof)
p is prime ⇐⇒ ∃x ∈ {0, . . . , p − 1} : x p−1 ≡ 1 mod p and
∀i ∈ {1, . . . , p − 2} : x i 6≡ 1 mod p
A non-deterministic algorithm (not the final algorithm) for checking
p ∈ PRIM can work as follows:
1
2
3
4
5
Accept if p = 2 or p = 3, otherwise go to (2).
Guess non-deterministically the prime factorization
p − 1 = p1 · · · · · pk , k ≥ 2.
Check whether pj ≥ 2 and recursively whether bin(pj ) ∈ PRIM for
every j ∈ {1, . . . , k}.
Guess non-deterministically x ∈ {0, . . . , p − 1} and check whether
x p−1 ≡ 1 mod p.
Verify for all j ∈ {1, . . . , k} the inequality x
Markus Lohrey (Universität Leipzig)
Complexity Theory
p−1
pj
6≡ 1 mod p.
WS 2012/2013
105 / 144
PRIM ∈ NP
(A) If the algorithm accepts the input p, then p ∈ PRIM.
Assume that the algorithm accepts input p > 3.
Let x ∈ {0, . . . , p − 1} be the number guessed in step (4).
x p−1 ≡ 1 mod p.
=⇒
Assume that x i ≡ 1 mod p for some i ∈ {1, . . . , p − 2}.
Let m be the greatest common divisor of p − 1 and i.
Since i ≤ p − 2, we have m < p − 1, i.e., m is a proper divisor of p − 1.
Euklid
=⇒
=⇒
∃α, β ∈ Z : m = α · (p − 1) + β · i.
x m = x α·(p−1)+β·i = (x p−1 )α · (x i )β ≡ 1 mod p
Since m is a proper divisor of p − 1, there is a pj with: m divides
=⇒
x
p−1
pj
≡ 1 mod p
Markus Lohrey (Universität Leipzig)
p−1
pj .
Contradiction to (5)
Complexity Theory
WS 2012/2013
106 / 144
PRIM ∈ NP
(B) If p ∈ PRIM, then the algorithm can accept input p.
This follows directly from Fermat’s little theorem.
(C) The algorithm can be implemented such that it runs in polynomial
time.
Consider for a prime p a successful computation of the algorithm.
This computation can be described by a proof tree (for p) which contains
for each recursive call a node.
In the leaves of the proof tree, only step (1) of the algorithm is executed,
while steps (2)–(5) are executed at inner nodes of the proof tree.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
107 / 144
PRIM ∈ NP
Claim: If p is prime, then there is a proof tree with at most
2 · ⌊log2 (p)⌋ − 1 many nodes.
Proof of the claim:
p = 2 or p = 3: Then there is a proof tree with a single node and
2 · ⌊log2 (2)⌋ − 1 = 2 · ⌊log2 (3)⌋ − 1 = 1.
Now assume that p > 3 is prime and let p − 1 = p1 · · · pk (k ≥ 2) be the
prime factorization of p − 1.
The proof tree for p consists of the proof trees for p1 , . . . , pk and the root
node.
By induction we get for the number of nodes of the proof tree for p:
1+
k
X
(2 · ⌊log2 (pi )⌋ − 1) ≤ 2 · ⌊log2 (p1 · . . . · pk )⌋ − (k − 1)
i=1
Markus Lohrey (Universität Leipzig)
≤ 2 · ⌊log2 (p)⌋ − 1, since k ≥ 2.
Complexity Theory
WS 2012/2013
108 / 144
PRIM ∈ NP
The final NP-algorithm that checks p ∈ PRIM works as follows:
Guess a proof tree with at most 2 · ⌊log2 (p)⌋ − 1 many nodes.
Every node of the proof tree is labeled with a number q ≤ p.
Every leaf is labeled with 2 or 3.
If a node is labeled with q and its children are labeled with q1 , . . . , qk ,
then we have: k ≥ 2 and q − 1 = q1 · q2 · · · qk (this can be checked in
polynomial time).
For every q-labeled inner node v we also guess a number
y ∈ {0, . . . , q − 1} and check whether: y q−1 ≡ 1 mod q and
y (q−1)/qj 6≡ 1 mod q for every qj that labels a child of v .
This can be also checked in polynomial time: y q−1 mod q (and
y (q−1)/qj mod q) can be computed by iterated squaring: Compute
i
successively y 1 mod q, y 2 mod q, y 4 mod q, . . ., y 2 mod q, where 2i
is the greatest power of 2 with 2i ≤ q − 1.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
109 / 144
Vertex Cover is NP-complete
A vertex cover for an undirected graph G = (V , E ) is a subset C ⊆ V of
the nodes such that for every edge {u, v } ∈ E we have: {u, v } ∩ C 6= ∅
Vertex Cover (VC) is the following problem:
input: An undirected graph G = (V , E ) and k ≥ 0.
Question: Does G has a vertex cover C with |C | ≤ k?
Theorem 30
VC is NP-complete.
Proof:
(1) VC ∈ NP: Guess a set of nodes C with |C | ≤ k and check in
polynomial time whether C is a vertex cover.
(1) VC isNP-hard:
We show 3-SAT ≤log
m VC.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
110 / 144
Vertex Cover is NP-hard
Let
F = c1 ∧ · · · ∧ c q
be a 3-CNF formula, where
f
cj = (f
xj1 ∨ xf
j2 ∨ x
j3 ).
We contruct a graph G (F ) as follows:
f
First we construct for every clause cj = (f
xj1 ∨ xf
j2 ∨ x
j3 ) the following
graph G (cj ):
xf
j3
xf
j1
Markus Lohrey (Universität Leipzig)
xf
j2
Complexity Theory
WS 2012/2013
111 / 144
Vertex Cover is NP-hard
S
The graph G (F ) is obtained from the disjoint union qj=1 G (cj ) of all
these graphs G (cj ) by adding all edges {x, x} (x is a variable in F ).
Example:
For the formula F = (x ∨ y ∨ z) ∧ (x ∨ s ∨ r ) ∧ (y ∨ s ∨ z) ∧ (x ∨ s ∨ r ) we
obtain the following graph G (F ):
z
x
r
y
Markus Lohrey (Universität Leipzig)
x
r
z
s
Complexity Theory
y
s
x
WS 2012/2013
s
112 / 144
Vertex Cover is NP-hard
Note: G (F ) cannot have a vertex cover U with |U| < 2q since for each of
the q triangles at least 2 nodes have to be in U.
Claim:F ∈ 3-SAT if and only if G (F ) has a vertex cover U with |U| = 2q.
(A) Let σ be a satisfying assignment for F .
Then, in each clause cj at least one literal xeji has to be true.
Let U be a set of nodes that contains for each subgraph G (cj ) exactly two
nodes so that false literals belong to U.
Then U is a vertex cover with |U| = 2q.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
113 / 144
Vertex Cover is NP-hard
(B) Let U be a vertex cover with |U| = 2q.
Then U contains from every subgraph G (cj ) exactly two nodes.
Define an assignment σ by
1 if a copy of x does not belong to U.
σ(x) = 0 if a copy of x does not belong to U.
0 if all copies of x and x belong to U.
Note: Since U is a vertex cover, and all edges {x, x} are present in G (F ),
there is no variable which will be set to 0 and 1 and the same time.
Clearly, σ(F ) = 1.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
114 / 144
Hamilton Circuit and Hamilton Path are NP-complete
A Hamilton path in a finite directed graph G = (V , E ) is a sequence of
nodes v1 , v2 , . . . , vn with
(vi , vi+1 ) ∈ E for all 1 ≤ i ≤ n − 1 and
for every v ∈ V there is exactly one 1 ≤ i ≤ n with v = vi .
A Hamilton circuit is a Hamilton path v1 , v2 , . . . , vn with (vn , v1 ) ∈ E .
Let
HP = {G | G is a graph with a Hamilton path}
HC = {G | G is a graph with a Hamilton circuit}
Theorem 31
HP and HC are both NP-complete (even for undirected graphs).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
115 / 144
Hamilton Circuit and Hamilton Path are NP-complete
Proof: We only prove the NP-completeness of HC.
(A) HC ∈ NP: trivial.
(B) 3-SAT ≤log
m HC:
V
Let F = c∈C c be a 3-CNF formula, where every c ∈ C is a clause
consisting of 3 literals (we view it as a set of 3 literals).
We construct a graph G (F ), that contains a Hamilton circuit if and only if
F ∈ SAT.
First we define for every clause c = (x̃ ∨ ỹ ∨ z̃) ∈ C a graph G (c):
c1
c0
cz̃4
cz̃3
cz̃2
Markus Lohrey (Universität Leipzig)
cz̃1
cỹ 4
cỹ 3
cỹ 2
Complexity Theory
cỹ 1
cx̃4
cx̃3
cx̃2
cx̃1
WS 2012/2013
116 / 144
Hamilton Circuit and Hamilton Path are NP-complete
Claim 1:
In G (c) there is no Hamilton path from c0 to c1 .
If we remove from G (c) at least one of the paths cl1 − cl2 − cl3 − cl4 ,
l ∈ c, then the resulting graph has a Hamilton path from c0 to c1 .
Let x be a variable, let {c1 , . . . , ck } be the set of clauses with x ∈ ci , and
let {d1 , . . . , dl } be the set of clauses with x ∈ dj .
For the variable x we define the following graph G (x):
x d1 1
x d1 2
x d1 3
x d1 4
x dl 1
x dl 2
x dl 3
x dl 4
xc1 1
xc1 2
xc1 3
xc1 4
xck 1
xck 2
xck 3
xck 4
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
117 / 144
Hamilton Circuit and Hamilton Path are NP-complete
The graph G (F ) is constructed by connecting the graphs G (c) and G (x),
where c1 , . . . , cm are the clauses and x1 , . . . , xn are the variables:
G (x1 )
G (c1 )
G (xj )
G (ci )
G (xn )
G (cm )
In addition we add for every clause c, every literal x̃ ∈ c, and every
1 ≤ i ≤ 4 a length-2 path between cx̃,i (a node of G (c)) and x̃c,i :
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
118 / 144
Hamilton-Circuit and Hamilton-Path are NP-complete
G (x)
x̃c1
x̃c2
x̃c3
G (y )
x̃c4
(let c = (x̃ ∨ ỹ ∨ z̃) ∈ C )
Markus Lohrey (Universität Leipzig)
ỹc1
ỹc2
ỹc3
G (z)
ỹc4
z̃c1
z̃c2
z̃c3
z̃c4
G (c)
Complexity Theory
WS 2012/2013
119 / 144
Hamilton-Circuit and Hamilton-Path are NP-complete
Example: Here is G (F ) for F = (x1 ∨ x2 ∨ x3 ) ∧ (x1 ∨ x2 ∨ x3 ):
|
{z
} |
{z
}
G (x1 )
c1
c2
G (x2 )
G (x3 )
G (c1 )
Markus Lohrey (Universität Leipzig)
G (c2 )
Complexity Theory
WS 2012/2013
120 / 144
Hamilton-Circuit and Hamilton-Path are NP-complete
Claim: F ∈ SAT if and only if G (F ) has a Hamilton circuit.
Assume that σ is a satisfying assignment for F .
We obtain a Hamilton circuit for G (F ) as follows:
The circuit visits for every variable x the x-branch (resp. x-branch) of the
subgraphs G (x) if σ(x) = 1 (resp. σ(x) = 0). Thereby we visit via the
length-2 paths in every subgraph G (c) at least one of the paths
cx̃1 − cx̃2 − cx̃3 − cx̃4 , where x̃ ∈ c is a satisfied literal (it exists!).
After the circuit has visited all subgraphs G (x), the remaining nodes from
the subgraphs G (c) and G (x) will be visited. This is possible by Claim 1.
Then the path ends at the start node.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
121 / 144
Hamilton-Circuit and Hamilton-Path are NP-complete
Let C be a Hamilton circuit for G (F ).
This circuit visits for each subgraph G (x) one of the two branches.
This defines a satisfying assignment σ for F .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
122 / 144
Non-NP-complete sets in NP \ P
By our current knowledge the following 3 different scenarios are possible:
NP-
NP-
NP
complete
NP
complete
sets
sets
P = NP
P
P
I
II
III
By Ladner’s theorem the third scenario is not possible:
Theorem 32 (Ladner)
If P 6= NP, then there exists (effectively) a language L ∈ NP \ P, which is
not NP-complete (under polynomial time reductions).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
123 / 144
Complete Problems for P
Let Lcfe = {hG i| G is a context-free grammar with L(G ) 6= ∅}.
Here, hG i denotes a suitable encoding of the grammar G , and cfe stands
for “context–free–empty”.
Theorem 33
Lcfe is P-complete.
Proof:
(A) Lcfe ∈ P
Compute the set of those nonterminals that can produce a terminal word
and check whether it contains the start nonterminal.
(B) Lcfe is P-hard.
Let L ∈ P and L(M) = L for a p(n)-time bounded deterministic Turing
machine M = (Q, Σ, Γ, δ, q0 , {qf }, ¤), p(n) > n is a polynomial.
Let w = w1 · · · wn ∈ Σ∗ be an input for M with |w | = n.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
124 / 144
Emptiness for context-free languages is P-complete
We make similar assumptions on M as in the proof of the Cook-Levin
Theorem:
1
2
3
4
Configurations of M will be described by words from the language
Conf = {¤uqv ¤ | q ∈ Q, uv ∈ Γp(n) }.
The initial configuration is ¤q0 w1 · · · wn ¤p(n)−n+1 .
w ∈ L(M) if and only if M reaches in at most p(n) steps the final
state qf .
There are functions f1 : Q → Q and f2 : Q → {←, →, N} such that
for every state q we have: (i) ∀a ∈ Γ : δ(q, a) ∈ Q × Γ × {N} or (ii)
∀a ∈ Γ : δ(q, a) = (f1 (q), a, f2 (q)).
For this, we introduce for every “old” state q new states hq, Di
(D ∈ {←, →, N}).
A transition δ(q, a) = (p, b, D) is decomposed into:
δ(q, a) = (hp, Di, b, N) and ∀x ∈ Γ : δ(hp, Di, x) = (p, x, D).
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
125 / 144
Emptiness for context-free languages is P-complete
From (4) follows that there exists a partial function
∆ : (Γ ∪ Q)3 → (Γ ∪ Q) such that for all α, α′ ∈ ¤(Q ∪ Γ)∗ ¤ with
|α| = |α′ |:
α, α′ ∈ Conf and α ⊢M α′
⇐⇒
α ∈ Conf and ∀i ∈ {0, . . . , p(n)} : ∆(α[i − 1], α[i], α[i + 1]) = α′ [i].
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
126 / 144
Emptiness for context-free languages is P-complete
We define the context-free grammar G (w ) = (V , ∅, P, S) with the set of
nonterminals
V = {S} ∪ {V (a, t, j) | a ∈ Γ ∪ Q, 0 ≤ t ≤ p(n), −1 ≤ j ≤ p(n) + 1},
empty terminal alphabet, the start nonterminal S and the following set P
of productions:
S → V (qf , t, j) for 0 ≤ t, j ≤ p(n)
V (a, t, j) → V (b, t − 1, j − 1)V (c, t − 1, j)V (d, t − 1, j + 1)
if ∆(b, c, d) = a, 0 < t ≤ p(n), 0 ≤ j ≤ p(n)
V (¤, t, −1) → ε for 0 ≤ t ≤ p(n)
V (¤, t, p(n) + 1) → ε for 0 ≤ t ≤ p(n)
V (q0 , 0, 0) → ε
V (wj , 0, j) → ε for 1 ≤ j ≤ n
V (¤, 0, j) → ε for n < j ≤ p(n)
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
127 / 144
Emptiness for context-free languages is P-complete
Claim: L(G (w )) 6= ∅ ⇐⇒ w ∈ L.
Let α0 ⊢M α1 ⊢M · · · ⊢M αp(n) be the unique computation that starts in
α0 = ¤q0 w1 · · · wn ¤p(n)−n+1 , αi ∈ Conf.
For −1 ≤ j ≤ p(n) + 1 and 0 ≤ t ≤ p(n) let α(t, j) = αt [j].
We prove the claim by showing the following more general statement:
L(G (w ), V (a, t, j)) 6= ∅ ⇐⇒ α(t, j) = a
⇐=: Let α(t, j) = a.
The cases t = 0, j = −1, j = p(n) + 1 follow immediately from the
definition of G (w ).
If t > 0 and 0 ≤ j ≤ p(n), then there are b, c, d ∈ Γ ∪ Q with
∆(b, c, d) = a and α(t − 1, j − 1) = b, α(t − 1, j) = c, α(t − 1, j + 1) = d.
By induction over t it follows that the languages
L(G (w ), V (b, t − 1, j − 1)), L(G (w ), V (c, t − 1, j)) and
L(G (w ), V (d, t − 1, j + 1)) are non-empty.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
128 / 144
Emptiness for context-free languages is P-complete
Since G (w ) contains the production
V (a, t, j) → V (b, t − 1, j − 1)V (c, t − 1, j)V (d, t − 1, j + 1),
we get L(G (w ), V (a, t, j)) 6= ∅.
=⇒: Let L(G (w ), V (a, t, j)) 6= ∅.
The cases t = 0, j = −1, j = p(n) + 1 follow immediately from the
definition of G (w ).
If t > 0 and 0 ≤ j ≤ p(n), then there must be a production
V (a, t, j) → V (b, t − 1, j − 1)V (c, t − 1, j)V (d, t − 1, j + 1)
(in particular ∆(b, c, d) = a) such that L(G (w ), V (b, t − 1, j − 1)),
L(G (w ), V (c, t − 1, j)) and L(G (w ), V (d, t − 1, j + 1)) are non-empty.
By induction we have α(t − 1, j − 1) = b, α(t − 1, j) = c,
α(t − 1, j + 1) = d.
Since ∆(b, c, d) = a we get α(t, j) = a.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
129 / 144
Boolean circuits
Definition (boolean circuit)
A boolean circuit C is a directed node-labeled graph
C = ({1, . . . , o}, E , s) for o ∈ N such that:
∀(i, j) ∈ E : i < j, i.e. G is acyclic.
s : {1, . . . , o} → {¬, ∧, ∨, 0, 1} such that:
s(i) ∈ {∧, ∨}
⇒
indegree(i) = 2
s(i) = ¬
⇒
indegree(i) = 1
s(i) ∈ {0, 1}
⇒
indegree(i) = 0
s(i) is the label of node i.
Nodes will be also called gates.
Gate o is the output gate of C .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
130 / 144
Boolean circuits
A boolean circuit can be evaluated. Thereby, we assgin to each gate i a
truth value v (i) ∈ {0, 1}.
A circuit is monotone, if it contains no ¬-gates.
Circuit Value (CV) is the following problem:
INPUT: A boolean circuit C
QUESTION: Does the output gate of C evaluate to 1?
Monotone Circuit Value (MCV) is the following problem:
INPUT: A monotone boolean circuit C
QUESTION: Does the output gate of C evaluate to 1?
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
131 / 144
Circuit Value is P-complete
Theorem 34
CV and MCV are P-complete.
Proof:
(i) CV ∈ P: Evaluate all gates in the order 1, 2, . . . , o.
(ii) MCV is P-hard:
Consider the P-hardness proof for Lcfe .
For a language L ∈ P and a word v ∈ Σ∗ we constructed a context-free
grammar G (v ) such that v ∈ L ⇔ L(G (v )) 6= ∅.
All productions of G (v ) have the type
A → B| · · · |Z
or
A → B1 B2 B3 | · · · |Z1 Z2 Z3
or A → ε
We construct a monotone circuit C (v ) as follows:
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
132 / 144
Circuit Value is P-complete
Every nonterminal of G (v ) becomes a gate of C (v ).
The start nonterminal of G (v ) is the output gate of C (v ).
The production A → B1 B2 B3 | · · · |Z1 Z2 Z3 leads to the following wires in
the circuit:
B1 B2 B3
Z1 Z2 Z3
·········
A
Analogously for productions of the form A → B| · · · |Z .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
133 / 144
Circuit Value is P-complete
A nonterminal A with the production A → ε becomes a 1-input gate.
A variable A, for which there is no production with left-hand side A
becomes a 0-input gate.
Note: The circuit C (v ) constructed in this way is indeed acyclic, since in
G (v ) there do not exist derivations of the form A →+ uAv with u, v ∈ V ∗
and A ∈ V .
We have: L(G (v ), A) 6= ∅ ⇐⇒ gate A of C (v ) evaluates to 1.
Only problem: The indegree of ∧- and ∨-gates in C (v ) may be larger than
2.
But: The indegree of ∧- and ∨-gates in G (v ) is bounded polynomially in
n = |v |.
Therefore, C (v ) can be transformed into an equivalent circuit C ′ (v ) with
maximal indegree 2, thereby the number of gates only grows by a
polynomial factor.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
134 / 144
Circuit Value is P-complete
We have: L(G (v )) 6= ∅ ⇐⇒ output gate of C ′ (v ) evaluates to 1.
Remark: In a circuit gates may have outdegree > 1. This seems to be
crucial for P-hardness:
The set of (variable-free) boolean expressions can be defined by the
following grammar:
A ::= 0 | 1 | (¬A) | (A ∧ A′ ) | (A ∨ A′ )
Boolean expressions can be seen as boolean circuits that have the shape of
a tree (every non-output gate has outdegree 1).
Buss 1987: The set of all boolean expressions that evaluate to 1 is
complete for the complexity class NC1 ⊆ L.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
135 / 144
Complete problems for PSPACE: Quantified Boolean
formulas
Quantified Boolean formulas
The set M of quantified Boolean formulas is the smallest set with:
xi ∈ M for all i ≥ 1
0, 1 ∈ M
E , F ∈ M, i ≥ 1 =⇒ (¬E ), (E ∧ F ), (E ∨ F ), ∀xi E , ∃xi E ∈ M
Alternatively: M can be generated by a context-free grammar over the
terminal alphabet Σ = {x, 0, 1, (, ), ¬, ∧, ∨, ∀, ∃}.
Thereby, variables will be identified with words from x1{0, 1}∗ .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
136 / 144
Satisfiability of quantified Boolean formulas
Satisfiability of quantified Boolean formulas is defined by the existence of a
satisfying assignment.
An assignment is a function b : {x1 , x2 , . . .} → {0, 1}.
Such an assignment can be restricted to those variables that appear in the
formula F that is checked for satisfiability.
For z ∈ {0, 1} and an assignment b let b[xj 7→ z] be the assignment with
b[xj 7→ z](xi ) = b(xi ) for i 6= j and
b[xj 7→ z](xj ) = z.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
137 / 144
Satisfiability of quantified Boolean formulas
Now we can define satisfiability of a formula F under the assignment b
inductively:
The assignment b satisfies the formula F if and only if one of the following
conditions holds:
F = 1,
F = xj
and b(xj ) = 1,
F = (¬E )
and b satisfies E not,
F = (F1 ∧ F2 ) and b satisfies F1 and F2 ,
F = (F1 ∨ F2 ) and b satisfies F1 or F2 ,
F = ∃xj E
and b[xj 7→ 0] or b[xj →
7 1] satisfies E ,
F = ∀xj E
and b[xj 7→ 0] and b[xj →
7 1] satisfy E .
F is valid if every assignment satisfies F .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
138 / 144
Satisfiability of quantified Boolean formulas
The set Free(F ) of free variables of F is defined by:
Free(0) = Free(1) = ∅
Free(xi ) = {xi }
Free(¬F ) = Free(F )
Free((F ∧ G )) = Free((F ∨ G )) = Free(F ) ∪ Free(G )
Free(∃xj F ) = Free(∀xj F ) = Free(F ) \ {xj }
A formula F with Free(F ) = ∅ is closed.
Note: Satisfiability of a closed formula F does not depend on the
assignment, i.e., if there exists a satisfying assignment for F then F is
valid.
Let QBF be the set of all closed valid quantified Boolean formulas.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
139 / 144
QBF is PSPACE-complete
Theorem 35
QBF is PSPACE-complete.
Proof:
(i) QBF ∈ PSPACE:
Let E be a closed quantified Boolean formula, in which the variables
x1 , . . . , xn appear.
W.l.o.g., E is build up from 1, x1 , . . . , xn , ¬, ∧, ∃, and no variable xi is
quantified twice in E (for instance, for the formula ∃x((∃x : 0) ∨ x) the
algorithm on the next slide would output the wrong answer 0).
The following recursive algorithm checks whether E is valid. It uses global
variables x1 , . . . , xn .
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
140 / 144
QBF is PSPACE-complete
FUNCTION check(E )
if E = 1 then return(1)
elseif E = xi then return(xi )
elseif E = (¬F ) then return(not check(F ))
elseif E = (E1 ∧ E2 ) then return(check(E1 ) and check(E2 ))
elseif E = ∃xi F then
xi := 1
if check(F ) = 1 then
return(1)
else
xi := 0
return(check(F ))
endif
endif
ENDFUNC
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
141 / 144
QBF is PSPACE-complete
(ii) QBF is PSPACE-hard:
Let L ∈ PSPACE. We have L = L(M) for a q(n)-space bounded
1-tape-Turing machine, where q(n) is a polynomial.
In the following, configurations of M will be coded as binary strings.
There is a polynomial p(n) such that: The length of all binary codings of
configurations that can be reached from the intial configuration Start(w )
with |w | = n is bounded by p(n). Then, the number of such configurations
is at most 2p(n) .
Consider the following recursion from the proof of Savitch’s theorem:
Reach(Start(w ), Accept, p(n)) ⇐⇒ w ∈ L
¡
¢
Reach(α, β, i) = ∃γ Reach(α, γ, i −1)∧Reach(γ, β, i −1) for i > 0
Reach(α, β, 0) = (α = β ∨ α ⊢M β)
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
142 / 144
QBF is PSPACE-complete
Problem: Iterating this recursion leads to a quantified boolean formula of
exponential length.
Solution: Introduce configuration variables X , Y , U, V , . . . and define for
i > 0:
Reach(X , Y , i) :=
¶ !
à µ
(V = X ∧ W = U) ∨ (V = U ∧ W = Y )
∃U ∀V ∀W
=⇒ Reach(V , W , i − 1)
1. Step: By iterating the above recursion (starting with
Reach(Start(w ), Accept, p(n))) we compute for an input w ∈ Σ∗ with
|w | = n a formula F of length O(p(n)) with configuration variables
X , Y , . . ..
The atomic formulas in F have the form X ⊢M Y and X = Y . Moreover,
the constants Start(w ) and Accept appear.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
143 / 144
QBF is PSPACE-complete
2. Step: We transform F into a closed quantified Boolean formula:
Replace every configuration variable X by a block of p(n) boolean
variables x1 , . . . , xp(n) . A quantifier ∀X is replaced by
∀x1 ∀x2 · · · ∀ xp(n) and similarly for ∃X .
The constants Start(w ) and Accept are replaced by a concrete bit
strings.
Vp(n)
X = Y is replaced by the formula i=1 (xi ⇔ yi ).
An atomic formula X ⊢M Y is replaced by a boolean formula that
uses the set ∆1 of 4-tuples from the proof of the Cook-Levin theorem.
In this way, we obtain a closed quantified boolean formula, which is
satisfiable if and only if w ∈ L.
Markus Lohrey (Universität Leipzig)
Complexity Theory
WS 2012/2013
144 / 144
© Copyright 2026 Paperzz