Languages and automata
László Kabódi
Time and space complexity
I Let M be a deterministic Turing machine
I The time complexity TM(n) is the maximum number of steps M takes on an input ofn length
I The space complexity SM(n) is the maximum number of cells M uses on an input of n length
I On a multitape Turing machine it is the sum of the used cell on all tapes
I TM(n) andSM(n) can be∞
I For nondeterministic Turing machines TM(n) andSM(n)are the maximum for all computations
I ifTM(n)<∞, thenL(M)∈R
The big O notation
I f(n) =O(g(n))if there exists ac >0 and ann0>0 constant where |f(n)| ≤c|g(n)|for all n≥n0
I It means that for large enough numbers f(n)can be upper bounded by c·g(n)
I Or informally, f(n)is not larger thang(n)by orders of magnitude
I Examples:
I 3n+4=O(n) I 3n+4=O(n2) I 4n3+2n2+3=O(n3)
Simulation of k -tape Turing machines
I For every k-tape M Turing machine there exists anM0 single tape Turing machine that
I TM0(n) =O(TM2(n)) I SM0(n) =O(SM(n) +n)
I Time complexity: in each step of M the simulatingM0 travels through all reached cells. Because withTM(n) timeM can only reach at most TM(n)cells, it takes at most
TM(n)·TM(n) steps.
I Space complexity: the input needs n cells, and than at most as many cells at the multitape machine uses.
Linear speedup theorem
I For every M Turing machine whereTM(n) =f(n),f(n)>n, there is an M0 Turing machine whereL(M) =L(M0)and TM0 =n+ε·f(n) for allε >0
I M0 packs several tape symbols ofM to one tape symbol of M0 I M0 is a more complex Turing machine with a bigger tape
alphabet and more rules, but uses less steps in its calculations I The constant multipliers does not matter in complexity
Some language classes based on complexity
I TIME(f(n)) ={L language| ∃M deterministic Turing machine, TM(n) =O(f(n)) for alln andL(M) =L}
I SPACE(f(n)) ={L language| ∃M deterministic Turing machine, SM(n) =O(f(n))for all n andL(M) =L}
I NTIME(f(n)) ={Llanguage| ∃M nondeterministic Turing machine, TM(n) =O(f(n)) for alln andL(M) =L}
I NSPACE(f(n)) ={Llanguage| ∃M nondeterministic Turing machine, SM(n) =O(f(n))for all n andL(M) =L}
Relations between these language classes
1. TIME(f(n))⊆NTIME(f(n)) 2. SPACE(f(n))⊆NSPACE(f(n)) 3. TIME(f(n))⊆R
4. SPACE(f(n))⊆RE 5. iff(n)≤g(n)∀n, then
TIME(f(n))⊆TIME(g(n))and SPACE(f(n))⊆SPACE(g(n))
6. If s(n)≥log(n), then NSPACE(s(n))⊆SPACE(s2(n)) (Savitch)
Proofs
1. A deterministic Turing machine is a special case of a nondeterministic Turing machines.
2. A deterministic Turing machine is a special case of a nondeterministic Turing machines.
3. If the Turing machine have a time complexityf(n) then it stops in nite steps fot all inputs. So it is recursive.
4. If a language has a Turing machine that accepts it, it is recursively enumerable.
5. Follows from the denition.
Some complexity classes
I P =
∞
S
k=1TIME(nk) I NP=
∞
S
k=1NTIME(nk) I PSPACE=
∞
S
k=1SPACE(nk) I EXPTIME =
∞
S
k=1TIME(2nk)
I These are very robust classes, they are the same for every computational models
Relations between these complexity classes
1. P ⊆NP
2. NP⊆ EXPTIME 3. NP⊆ PSPACE 4. P ⊂EXPTIME 5. P =coP 6. P ⊆coNP
Proofs
1. Because TIME(f(n))⊆NTIME(f(n)).
2. Simulating all computations require exponential time.
3. Simulating all computations require linear space.
4. ⊆from denition.
5. Like R=coR.
6. P ⊆NP, so coP⊆ coNP, but P=coP.
Connection between time and space complexity
I TIME(f(n))⊆SPACE(f(n))
I Because inf(n)steps the machine can not use more thanf(n) cells.
I But in the other way this is not true.
I In fact from the denition it does not follow, that a space bounded language is recursive.
I If L∈SPACE(s(n)),s(n)≥log(n) then there is acL >0 constant (depending on L) soL∈TIME(cLs(n))
Proof
I If L∈SPACE(s(n))then there is an M Turing machine where L(M) =L andM uses at mostd·s(n) cells
I We create an M0 Turing machine which simulatesM is it stops, and rejects the input is M would go to an innite loop I We can dene the conguration of a Turing machine as its
state, the contents of its tapes and the locations of its heads I If the machine is in the same conguration as it were before,
then it is in a loop
Number of dierent congurations
I Current state: |Q|
I Contents of its tapes: |Γ|SM(n)≤ |Γ|d·s(n)
I Location of the heads on the work tapes: SM(n)k ≤2k·d·s(n) I Location of the head on the input tape: n+1≤22·c(n) I The number of all the possible congurations are the product
of these
I |Q| · |Γ|d·s(n)·2k·d·s(n)·22·s(n)≤ |Q| ·(|Γ|d·2kd+2)s(n)=t= O(cs(n))
Idea for M
0I TheM machine can have at most t dierent congurations I If the simulation stops before thetth step,M0 stops, and does
tha same thing azM
I otherwise, when the simulation runs for at leastt+1 steps, then it is in an innite loop, we can stop and reject the input I To do this we must calculatet, but this is not possible in some
cases
Description of M
0I M0 uses two copies ofM: M1 andM2
I it simulates one step of M1, and increases a counter that stores how many stepsM1 already used
I then it runsM2from the beginning to the previous step ofM1 I in each step ofM2, M0 compares the conguration ofM1 and
M2
I if the two congurations are the same,M0 stops and rejects the word
I ifM1 stops, M0 stops and outputs the same answer as M1
Running time of M
0I M1 runs for at mostt+1 steps. It either stops before it, or we nd a loop
I For thisM2 runs at most for 1+2+. . .+t=O(t2) steps I So M0 runs for at mostO(c2·s(n))steps
I We choose cL=c2, so L∈TIME(cLs(n))
I Also, this simulation increases the space complexity only by a constant multiplier, so it still ∈SPACE(s(n))
Consequences
1. SPACE(s(n))⊆R
2. SPACE(s(n)) =coSPACE(s(n)) 3. PSPACE= coPSPACE
4. PSPACE⊆ EXPTIME
Proofs
1. The Turing machine from the proof stops on all inputs 2. We can change the Turing machine from the proof, swap the
accepting and rejecting states 3. Follows from the denition
4. L∈PSPACE so there is ak thatL∈SPACE(nk). Using the theoremL∈TIME(cnk). Becausec ≤2c we know thatL∈ TIME(2nk+1)⊆ EXPTIME
Further consequence
I P ⊆NP⊆ PSPACE⊆EXPTIME I And we know that P ⊂EXPTIME
I But we do not no if P =NP or NP=PSPACE or PSPACE= EXPTIME is true