算法和计算复杂度 1 Turing Machines, Time and Space
Theory of Algorithms and Computational Complexity
Lecturer: Kristoffer Arnsfelt Hansen
☠️☠️☠️The most difficult (no “one of”) course in my master’s study.☠️☠️☠️
Brief Intro to TACC
Study of efficient computation
1960s Hartmanis, Stearns - Time Hierarchy Theorem.
Turing machine, register based machine can simulate each other.
Turing Machines
Turing machines - simple, and has some nice properties:
- Clean definition of complexity (time and space)
- Straightforward to non-determinism and randomness.
Consider “offline multi-tape sequential Turing machine”
Turing machine is a finite-state machine that can access and modify chars written on “tapes” according to some rules.
Formal Definition
Turing machine with one input tape and work tapes. It includes:
Finite set : set of states
- Element : start state
- Element : accept state
- Element : reject state
Finite set : the tape alphabet
- non-empty finite set : input alphabet
Element : blank symbol
Function
is the transition function.
状态转移方程的意思:
转移前: 代表转移前状态,不能是接受或拒绝态(因为接受或拒绝就停机了); 代表输入字符; 代表之前当前针头分别指 个工作纸带对应位置的字符。
转移后: 代表转移后的状态,可以是接受或拒绝态; 表示针头分别在 个工作纸带上对应位置写入的字符; 表示接下了输入纸带和 个工作纸带应该左移()、右移(),还是不动()。
Transition Function has following properties:
- will stop operation when entering or state.
- marks all cells visited on its work tapes
The operation of :
- two-way infinite tapes. One for input, the rest for work.
- The cells of each work tape are numbered by the set .
- Input tape on which the cell are filled with char . The other cells are filled with .
- Each tape has a tape head, which initially stays at position .
- The machine maintain an element of as its internal state.
The computation of :
- Move the tapes according to transition function
- If input head is called to “move left” at position , or “move right” at position , let “crash”. (So there are legal cell for input tape head)
- When enters or , it stops. We called halts. ( or )
Turing machine can be seen as language acceptor useful for decision problems whether the language is formal language, i.e., the language computed by is .
An Extension on Turing Machine
Add an additional output tape which is write-only.
: non-empty finite set, output alphabet. (Usually )
In each step of computation can choose to write a single symbol to the output tape. Then transition function:
here means write nothing.
Such a Turing machine is also called a transducer.
Time and Space Complexity
For a given input :
- is the number of computational steps that performs on input until halting.
- is the total number of cells on the work tapes that are at some point scanned by a tape head during computation on input .
Both time and space can be infinite. Space can be infinite when does not halt.
📖Definition of time/space-bounded: let and be functions with . We say is time-bounded, if for every we have . Similarly, is space-bounded, if for every we have .
Then define the first complexity classes based on time/space bounds.
📖Definition of : is the class of languages computed by a time-bounded Turing machine and is the class of languages computed by a space Turing machine.
代表 deterministic (确定)。确定性图灵机每次状态转移只有一种。
代表 non-deterministic (非确定)。非确定性图灵机每次状态转移可能有多种,机器随机选择其中的一种进行转移。
Why notation here?
Compressing several tapes symbols to one class by an arbitrary linear factor.
WLOG, one work tape can simulate work tapes by special marking char.
也就是说可以用一个标记字符把一个工作纸带分成 份。
📖Definition of time/space-constructible: is time-constructible if there is a time-bounded Turing machine computing the function . is space-constructible if there is a time-bounded Turing machine computing the function .
Universal Turing Machines
Universal Turing machine has a fixed amount of work tapes and a fixed tape alphabet.
Set of states is identified with positive integers from to .
and is also identified with positive integers.
can be encoded by its function table.
Given: encoding of a Turing machine with work tapes with an encoding of an input to . (encoding of is concatenation of each char in ).
🎯Theorem 1. For any , there exist a Turing machine with work tapes s.t. when given as input an encoding of a Turing machine with work tapes together with an encoding of an input , simulates the computation of on input using time and space .
“Simulates” here means provides same output, terminal state as .
Sublogarithmic Space
Usually assume that .
What if ? In this case Turing machine can’t even be able to describe the position of the input tape head.
space-bounded Turing machine is equivalent to a two-way finite automaton.
To accept non-regular language, the minimal space should be .
Storage configuration: a state of , position of tape heads, non-black portions of the work tapes. # storage configuration: at most .
🎯Theorem 2. Let be a space-bounded Turing machine for a function . Then is in fact space-bounded.
Proof via contradiction.
Storage configuration is periodic.
will produce at most crossing sequences.
Turing Machine Configurations
Configuration 被翻译为“格局”……无力吐槽
A configuration of a Turing machine with work tapes:
- State of
- Positions of tapes head
- Non-blank portions of the work tapes
Observation: If a Turing machine repeats a configuration, it will enter an infinite loop, infinitely repeating the computation taking place between two repeating configurations.
The Space Hierarchy Theorem
Idea: More resources means more can be computed.
🎯Theorem 3: Let be space constructible. If , then
中文简单解释一下:图灵机的可用渐进存储空间越多,那么解决的问题也就越多。
It suffices to construct a space bounded Turing machine s.t. .
Input of length :
- Mark cells of work tape using the space constructability of . During the remaining computation:
- Ensuring that computation does not use more than additional cells of work tape. This is done by immediately halting (reject).
- Ensuring that computation does not run for more than steps, by keeping time with a binary counter on bits. (accept)
- Check if the input is on the form , here is an encoding of a Turing machine with a single work tape. Otherwise halt by rejecting.
- Simulate on input using the universal Turing machine . If this causes to halt, halt and reject if accepts. Otherwise accept.
Then analysis and …
Tape Reduction and Oblivious Turing Machines
A time-bounded computation of a Turing machine with any number of work tapes can be simulated by a time-bounded Turing machine with a single work tape. (Simple divide work tape into tracks.)
This is used to prove when is time-constructible and .
📖Definition of oblivious: Let be a Turing Machine. is oblivious if for any and any input of length , during computation with input and until halts, the location of all tape heads of is a function of and the number of steps of the computation so far.
It is easy to modify the to be oblivious by first copying the input to an additional track, and thereafter keeping the input head stationary.
🎯Theorem 4: Let and suppose is a time-bounded Turing machine with work tapes. Then there exist a time-bounded oblivious Turing machine with work tapes s.t. .
Hard proof.
The Time Hierarchy Theorem
🎯Theorem 5: Let be time constructible. If satisfies , then
Proof by tape reduction.
Time and Space Complexity Classes
There are some standard complexity classes given by natural classes of time and space bounds.
Trivially, .
A space bounded Turing machine cannot repeat a configuration without entering an infinite loop, thus for .
Unknown: whether any of the inclusions are strict. But time and space hierarchy theorems give that and .
means , denotes , denotes .
Obviously(???really???), , showing that space is more “valuable than” time. More precisely, for .
The Padding Technique
Whether and are strict is related.
🎯Theorem 6: If , then .