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 MM with one input tape and kk work tapes. It includes:

  • Finite set QQ: set of states

    • Element sQs\in Q: start state
    • Element yesQyes\in Q: accept state
    • Element noQno\in Q: reject state
  • Finite set Γ\Gamma: the tape alphabet

    • non-empty finite set ΣΓ\Sigma\subseteq\Gamma: input alphabet
  • Element ΔΓΣ\Delta\in\Gamma\diagdown\Sigma: blank symbol

  • Function

    δ:(Q{yes,no})×(Σ{Δ})×ΓkQ×(Γ{Δ})k×{L,S,R}k+1\delta:(Q\diagdown\{yes,no\})\times(\Sigma\cup\{\Delta\})\times\Gamma^k\rarr Q\times(\Gamma\diagdown\{\Delta\})^k\times\{L,S,R\}^{k+1}

    is the transition function.

状态转移方程的意思:

转移前:(Q{yes,no})(Q\diagdown\{yes,no\}) 代表转移前状态,不能是接受或拒绝态(因为接受或拒绝就停机了);(Σ{Δ})(\Sigma\cup\{\Delta\}) 代表输入字符;Γk\Gamma^k 代表之前当前针头分别指 kk 个工作纸带对应位置的字符。

转移后:QQ 代表转移后的状态,可以是接受或拒绝态;(Γ{Δ})k(\Gamma\diagdown\{\Delta\})^k 表示针头分别在 kk 个工作纸带上对应位置写入的字符;{L,S,R}k+1\{L,S,R\}^{k+1} 表示接下了输入纸带和 kk 个工作纸带应该左移(LL)、右移(RR),还是不动(SS)。

Transition Function has following properties:

  1. MM will stop operation when entering yesyes or nono state.
  2. MM marks all cells visited on its work tapes

The operation of MM:

  • k+1k+1 two-way infinite tapes. One for input, the rest for work.
  • The cells of each work tape are numbered by the set Z\mathbb Z.
  • Input tape on which the cell 1,,x1,\cdots,|x| are filled with char xix_i. The other cells are filled with Δ\Delta.
  • Each tape has a tape head, which initially stays at position 00.
  • The machine MM maintain an element of AA as its internal state.

The computation of MM:

  • Move the tapes according to transition function
  • If input head is called to “move left” at position 00, or “move right” at position x+1|x|+1, let MM “crash”. (So there are x+2|x|+2 legal cell for input tape head)
  • When MM enters yesyes or nono, it stops. We called MM halts. (M(x)=yesM(x)=yes or M(x)=noM(x)=no)

Turing machine can be seen as language acceptor useful for decision problems whether the language is formal language, i.e., the language computed by MM is L(M)={xΣM(x)="yes"}L(M)=\{x\in\Sigma|M(x)="yes"\}.

An Extension on Turing Machine

Add an additional output tape which is write-only.

Λ\Lambda: non-empty finite set, output alphabet. (Usually Λ=Σ\Lambda=\Sigma)

In each step of computation MM can choose to write a single symbol to the output tape. Then transition function:

δ:(Q{yes,no})×(Σ{Δ})×ΓkQ×(Γ{Δ})k×(Λ{ϵ})×{L,S,R}k+1\delta:(Q\diagdown\{yes,no\})\times(\Sigma\cup\{\Delta\})\times\Gamma^k\\ \rarr Q\times(\Gamma\diagdown\{\Delta\})^k\times(\Lambda\cup\{\epsilon\})\times\{L,S,R\}^{k+1}

ϵ\epsilon here means write nothing.

Such a Turing machine is also called a transducer.

Time and Space Complexity

For a given input xΣx\in\Sigma^*:

  • timeM(x)time_M(x) is the number of computational steps that MM performs on input xx until halting.
  • spaceM(x)space_M(x) is the total number of cells on the work tapes that are at some point scanned by a tape head during computation on input xx.

Both time and space can be infinite. Space can be infinite when MM does not halt.

📖Definition of time/space-bounded: let T:NNT:\mathbb N\rarr\mathbb N and S:NNS:\mathbb N\rarr\mathbb N be functions with T(n)nT(n)\ge n. We say MM is T(n)T(n) time-bounded, if for every xΣx\in\Sigma^* we have timeM(x)T(x)time_M(x)\le T(|x|). Similarly, MM is S(n)S(n) space-bounded, if for every xΣx\in\Sigma^* we have spaceM(x)S(x)space_M(x)\le S(|x|).

Then define the first complexity classes based on time/space bounds.

📖Definition of DTIME,DSPACEDTIME,DSPACE: DTIME(T(n))DTIME(T(n)) is the class of languages computed by a O(T(n))O(T(n)) time-bounded Turing machine and DSPACE(S(n))DSPACE(S(n)) is the class of languages computed by a O(S(n))O(S(n)) space Turing machine.

DD 代表 deterministic (确定)。确定性图灵机每次状态转移只有一种。

NN 代表 non-deterministic (非确定)。非确定性图灵机每次状态转移可能有多种,机器随机选择其中的一种进行转移。

Why OO notation here?

  1. Compressing several tapes symbols to one class by an arbitrary linear factor.

  2. WLOG, one work tape can simulate kk work tapes by special marking char.

    也就是说可以用一个标记字符把一个工作纸带分成 kk 份。

📖Definition of time/space-constructible: TT is time-constructible if there is a O(T(n))O(T(n)) time-bounded Turing machine computing the function 1n1T(n)1^n\mapsto 1^{T(n)}. SS is space-constructible if there is a O(S(n))O(S(n)) time-bounded Turing machine computing the function 1n1S(n)1^n\mapsto 1^{S(n)}.

Universal Turing Machines

Universal Turing machine has a fixed amount of work tapes and a fixed tape alphabet.

Set of states QQ is identified with positive integers from 11 to Q|Q|.

Σ\Sigma and Γ\Gamma is also identified with positive integers.

δ\delta can be encoded by its function table.

Given: encoding of a Turing machine MM with kk work tapes with an encoding of an input xx to MM. (encoding of xx is concatenation of each char in xx).

🎯Theorem 1. For any k1k\ge1, there exist a Turing machine UkU_k with k+1k+1 work tapes s.t. when given as input an encoding of a Turing machine MM with kk work tapes together with an encoding of an input xx, simulates the computation of MM on input xx using time O(timeM(x))O(time_M(x)) and space O(spaceM(x))O(space_M(x)).

“Simulates” here means Uk+1U_{k+1} provides same output, terminal state as MM.

Sublogarithmic Space

Usually assume that S(n)lognS(n)\ge\log n.

What if S(n)=o(logn)S(n)=o(\log n)? In this case Turing machine can’t even be able to describe the position of the input tape head.

O(1)O(1) space-bounded Turing machine is equivalent to a two-way finite automaton.

To accept non-regular language, the minimal space should be O(loglogn)O(\log\log n).

Storage configuration: a state of MM, position of tape heads, non-black portions of the work tapes. # storage configuration: at most QskΓs+k1=2O(s)|Q|s^k|\Gamma|^{s+k-1}=2^{O(s)}.

🎯Theorem 2. Let MM be a S(n)S(n) space-bounded Turing machine for a function S(n)=o(loglogn)S(n)=o(\log\log n). Then MM is in fact O(1)O(1) space-bounded.

Proof via contradiction.

Storage configuration is periodic.

MM will produce at most 22O(s)2^{2^{O(s)}} crossing sequences.

Turing Machine Configurations

Configuration 被翻译为“格局”……无力吐槽

A configuration of a Turing machine MM with kk work tapes:

  1. State of MM
  2. Positions of k+1k+1 tapes head
  3. 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 S2(n)lognS_2(n)\ge\log n be space constructible. If S1(n)=o(S2(n))S_1(n)=o(S_2(n)), then

DSPACE(S1(n))DSPACE(S2(n)).DSPACE(S_1(n))\subsetneq DSPACE(S_2(n)).

中文简单解释一下:图灵机的可用渐进存储空间越多,那么解决的问题也就越多。

It suffices to construct a O(S2(n))O(S_2(n)) space bounded Turing machine MM s.t. L(M)∉DSPACE(S1(n))L(M)\not\in DSPACE(S_1(n)).

Input xx of length n=xn=|x|:

  1. Mark S2(n)S_2(n) cells of work tape using the space constructability of S2S_2. During the remaining computation:
    • Ensuring that computation does not use more than S2(n)S_2(n) additional cells of work tape. This is done by immediately halting (reject).
    • Ensuring that computation does not run for more than 22S2(n)2^{2S_2(n)} steps, by keeping time with a binary counter on 2S2(n)2S_2(n) bits. (accept)
  2. Check if the input is on the form x=0i1wx=0^i1w, here ww is an encoding of a Turing machine with a single work tape. Otherwise halt by rejecting.
  3. Simulate MM' on input xx using the universal Turing machine U1U_1. If this causes MM' to halt, halt and reject if MM' accepts. Otherwise accept.

Then analysis MM and MM'

Tape Reduction and Oblivious Turing Machines

A T(n)T(n) time-bounded computation of a Turing machine with any number of work tapes can be simulated by a O(T(n)2)O(T(n)^2) time-bounded Turing machine with a single work tape. (Simple divide work tape into kk tracks.)

This is used to prove DTIME(T1(n))DTIME(T2(n))DTIME(T_1(n))\subsetneq DTIME(T_2(n)) when T2(n)>nT_2(n)>n is time-constructible and (T1(n))2=o(T2(n))(T_1(n))^2=o(T_2(n)).

📖Definition of oblivious: Let MM be a Turing Machine. MM is oblivious if for any n1n\ge1 and any input xx of length n=xn=|x|, during computation with input xx and until MM halts, the location of all tape heads of MM is a function of nn and the number tt of steps of the computation so far.

It is easy to modify the O(T(n)2)O(T(n)^2) to be oblivious by first copying the input to an additional track, and thereafter keeping the input head stationary.

🎯Theorem 4: Let T(n)nT(n)\ge n and suppose MM is a T(n)T(n) time-bounded Turing machine with kk work tapes. Then there exist a O(T(n)logT(n))O(T(n)\log T(n)) time-bounded oblivious Turing machine MM' with 22 work tapes s.t. L(M)=L(M)L(M)=L(M').

Hard proof.

The Time Hierarchy Theorem

🎯Theorem 5: Let T2(n)nT_2(n)\ge n be time constructible. If T1(n)nT_1(n)\ge n satisfies T1(n)logT1(n)=o(T2(n))T_1(n)\log T_1(n)=o(T_2(n)), then

DTIME(T1(n))DTIME(T2(n)).DTIME(T_1(n))\subsetneq DTIME(T_2(n)).

Proof by tape reduction.

Time and Space Complexity Classes

There are some standard complexity classes given by natural classes of time and space bounds.

L=DSPACE(logn)P=k>0DTIME(nk)PSPACE=k>0DSPACE(nk)EXP=k>0DTIME(2nk)L=DSPACE(\log n)\\ P=\bigcup_{k>0}DTIME(n^k)\\ PSPACE=\bigcup_{k>0}DSPACE(n^k)\\ EXP=\bigcup_{k>0}DTIME(2^{n^k})

Trivially, LPPSPACEEXPL\subseteq P\subseteq PSPACE\subseteq EXP.

A space bounded Turing machine cannot repeat a configuration without entering an infinite loop, thus DSPACE(S(n))DTIME(2O(S(n)))DSPACE(S(n))\subseteq DTIME(2^{O(S(n))}) for S(n)>lognS(n)>\log n.

Unknown: whether any of the inclusions are strict. But time and space hierarchy theorems give that LPSPACEL\subsetneq PSPACE and PEXPP\subsetneq EXP.

LL means LOGSPACELOGSPACE, PP denotes PTIMEPTIME, EXPEXP denotes EXPTIMEEXPTIME.

Obviously(???really???), DTIME(T(n))DSPACE(T(n))DTIME(T(n))\subseteq DSPACE(T(n)), showing that space is more “valuable than” time. More precisely, DTIME(T(n))DSPACE(T(n)/logT(n))DTIME(T(n))\subseteq DSPACE(T(n)/\log T(n)) for T(n)nT(n)\ge n.

The Padding Technique

Whether LPL\subseteq P and PSPACEEXPPSPACE\subseteq EXP are strict is related.

🎯Theorem 6: If L=PL=P, then PSPACE=EXPPSPACE=EXP.