Time complexity·
Definition·
- Let M be a deterministic Turing machine that halts on all input. The running time or time complexity of M is the function f:N→N, where f(n) is the maximum number of steps that M uses on any input of length n.
Time complexity class·
- TIME(t(n)): languages decidable by O(t(n)) time deterministic TM
- NTIME(t(n)): languages decidable by O(t(n)) time nondeterministic TM

- NP=∪kNTIME(nk) 的理解:
- NP 是能在多项式时间内验证答案正确性,那么可以用 非确定性图灵机 猜一个答案 然后多项式时间内验证他 猜的时候可以保证如果有答案就能猜到答案 所以 NP ⇔ NTIME
The Cobham-Edmonds thesis·
- For any realistic models of computation M1 and M2, M1 can be simulated on M2 with at most polynomial slowdown.
- 只有多项式复杂度的东西才能够在实际计算机上计算
Space complexity·
Space complexity class·
Low Space classes·
- L = SPACE(logn)
- NL = NSPACE(logn)
- PSPACE = ∪k SPACE(nk)
- NPSPACE = ∪k NSPACE(nk)
3-TAPE machines·

- Configuration
- the state O(c)
- the content of the work tape O(gf(n))
- the head position of input tape O(n)
- the head position of work tape O(f(n))
- total number = O(cnf(n)gf(n))=O(n⋅2f(n))
- If f(n)=O(logn), configuration 的总数 O(n)
- 消耗 空间 O(f(n)) 的 图灵机 在 时间 n2O(f(n)) 内运行
Some observations·
-
TIME(f(n))⊆SPACE(f(n))
- a machine uses f(n) time can use at most f(n) space
-
SPACE(f(n))⊆TIME(f(n)⋅2O(f(n)))
-
a machine uses O(f(n)) space can have at most 2O(f(n)) configurations
-
a TM that halts may not repeat a configuration
-
the total time to “list” all configurations is f(n)⋅2O(f(n))
-
NTIME(f(n))⊂SPACE(f(n))
- we can enumerate all O(f(n)) guesses in O(f(n)) space
-
$ L⊆P⊆NP⊆PSPACE=NPSPACE⊆EXPTIME$
NL Completeness·
Log-space reduction·
- A is log-space reducible to B, written A≤LB, if there exists a log space TM M that, given input w, outputs f(w) s.t. w∈A iff f(w)∈B.
Definition·
- A language B is NL-complete if
- B∈NL
- ∀A∈NL,A≤LB
- Thm: If A≤LB and B∈L, then A∈L.
- 直接考虑 对于 A 的输入 w,用 M 计算 f(w) 不可行,因为虽然计算的过程是 log space 但是输出 f(w) 可能会很大
- 我们不计算整个 f(w),只在 B 需要用到 f(w) 的某个 bit 的时候去计算那个字符。f(w) 的长度 is bounded by poly(n) 故我们只要 O(logn) bits.
- 从 w 到 f(w) 和从 f(w) 到最终的 output 都是 log space,输入是 poly(n) 所以空间开销是 O(logn)
- More generally, if f and g are log-space computable functions, f∘g is also log-space computable. (就等 g 的结果的第 i 位算出来在用到 f 里面)
- log space 可以让输出和输入的长度是poly关系 (在log 意义下同阶)
PATH·
Savitch’s Theorem·
- NL⊂SPACE(log2n)
- Proof:
- First prove PATH is NL-complete
- Then show an algorithm for PATH that uses log2n space
PATH is NL-complete·
- 已经证明了 PATH∈NL,下面证明任何 NL 都可以对数空间规约到 PATH
- 对于一个语言 A,存在一个 NTM M 在 O(logn) 的空间内能 decide A,不妨设 M 只有一个 accept configuration
- For input w, we construct a directed graph $\langle G, s, t\rangle $ in 对数空间内,s.t. G contains a path from s to t iff M accepts w.
- M 的每个 configuration 视作一个节点,如果 c1 出发下一个能到 c2,那么 (c1,c2) 是 G 的一条边,s 是一个初始 configuration,t 是 accept configuration
- 从 w 到 ⟨G,s,t⟩ 的转换也是 log-space
- 列举所有的 nodes nodes就对应 configuration 所以是log space
- For every two nodes, check whether connected 这只需要看一下head指向的位置
NL⊂P·
- a simple corollary
- PATH∈P
- all NL language is log-space reducible to PATH
- -> all NL language is poly-time reducible to PATH
- any NL language is in P
Then show PATH can be decided by a deterministic TM in O(log2n) space·

- S(n)=S(n/2)+O(logn)
So we have proven NL⊂SPACE(log2n)
Padding argument – Example·
-
Claim: If P=NP, then EXP=NEXP.
-
Proof.
Since EXP⊂NEXP is by definition, we only need to show NEXP⊂EXP.
考虑 NEXP 中的某个语言 L,存在某个自动机 M 能够在 2nc 的时间内 decide L. 我们定义
L′={x12∣x∣c∣x∈L}
其中 1 表示一个不在 L 中的符号.
首先我们证明 L′ is in NP, 然后我们通过 NP=P, 我们证明 L is in EXP.
首先证明 L′ is in NP.
给定输入 x′ 我们需要判断 x′∈L′ or not. 我们先看 x′ 的形式. 如果 x′ 符合 L′ 的形式, 就是说存在一个x, x′=x{x12∣x∣c∣x∈L}, simulate M(x). 这个 simulation 的时间 是 2∣x∣c, 关于 x′ 的长度是线性的. 自然也是多项式的. 这整个过程就能 decide x′ is in L′ or not. 并且是 NP 的. 因此, L′ is in NP.
由于假设 P=NP, L′ is in P. Then, 存在一个确定自动机, 能够在 poly time 内decide L′. 这个自动机关于 ∣x∣ 的复杂度就是 EXP. 因此 L∈EXP.
-
padding 指的就是在 x 后面加许多个 1 的操作. 这有时用于不同复杂度类型的转换.
-
Theorem:
∀S(n)≥log(n), NSPACE(S(n))⊂SPACE(S(n)2)
-
用 NL⊂SPACE(log2n) 证明
Definition·
-
A function f:N→N, where f(n)≥logn, is called space constructable, if the function that maps 1n to the binary representation of f(n) is computable in space O(f(n)).
-
A function f:N→N, where f(n)≥nlogn, is called time constructable if the function that maps 1n to the binary representation of f(n) is computable in time O(f(n)).
-
All commonly used functions are space/time constructable.
Claim·
-
For any two space constructable functions s1(n),s2(n)≥logn,f(n)≥n:
NSPACE(s1(n))⊂SPACE(s2(n)) can derive that NSPACE(s1(f(n)))⊂SPACE(s2(f(n)))
Proof·
我们也用 padding 的方式去证明 Savitch’s Theorem.
假设 L∈NSPACE(s1(f(n)))
就是有一个 s1(f(n)) 空间复杂度的 NTM ML 能够 decide L.
我们想要转化到一个 NSPACE(s1(n)) 的问题 就是把输入长度变成 f(n)
我们将输入 x 从长度 n 补到 f(n)
令 L′={x@0f(n)−n∣x∈L} , 那么 我们考虑这样一个 NTM
- 数最后的 0 的数量, check 是否有某个 n 满足 0 的数量 等于 f(n)−n
- 假如找到了这样的 n, 我们相当于得到了输入 x, 然后 run ML on x
之前那个 ML 的空间复杂度是 s1(f(n)) 其中 n 指的是 x 的长度, 所以现在这个 NTM 的复杂度就是 s1(n). 那么 L′∈NSPACE(s1(n)). 于是, 根据条件, L′∈SPACE(s2(n)), 再做一个从 L′→L 的转换, 我们就得到了一个 确定性图灵机, works in O(s2(f(n))) space.
原始定理的证明·
- 只要 s1(n)=log(n), s2(n)=log2(n), 我们已经有 NSPACE(s1(n))⊂SPACE(s2(n)), 那么我们就有 NSPACE(s1(f(n)))⊂SPACE(s2(f(n))) 对任意的 f(n)≥n. 代入就是 NSPACE(log(f(n)))⊂SPACE(log2(f(n))). 令 g(n)=log(f(n)), 那么就是 NSPACE(g(n))⊂SPACE(g2(n)), g(n) 的限制条件只有 g(n)≥logn.
Corollary·
-
PSPACE=NPSPACE
-
Clearly, PSPACE⊂NPSPACE. By Savitch’s theorem, NPSPACE⊂PSPACE.
可以看到, 时间复杂度和空间复杂度有很大不同. NP 和 P 差距极大, 而 NSPACE 和 PSPACE 并没有太大的差别.
PSPACE·
- 在多项式空间内能被 确定图灵机 decide 的语言
- e.g. SAT is in PSPACE 只需要顺序枚举每一个 xi 的值 也因此 NP⊂PSPACE
Problem statement·
- Instance: a fully quantified Boolean formula ϕ
- fully quantified 就是对于 formula 中的每个变量, 都有一个 ∃ 或者 ∀ 去限定他 -> quantifier
- Problem: to decide if ϕ is true
TQBF is in PSPACE·
- We describe a poly-space algorithm for evaluating ϕ
- If ϕ has no quantifiers: 那么式子里所有变量取值都确定了, 直接算
- If ϕ=∀x(ψ(x)): 那么把 x=0 和 x=1 都带进去算, 都 accept 才 accept
- If ϕ=∃x(ψ(x)): 把 x=0 和 x=1 带进去算, 只要有一个 accept 就 accept
- 空间是线性的
PSPACE Completeness·
Definition·
- A language B is PSPACE-complete iff
- B∈PSPACE
- ∀A∈PSPACE,A≤PB
- 这里的 ≤P 就是多项式时间的归约
TQBF is PSPACE-complete·
- 已经证明了 TQBF is in PSPACE
- 需要证明 TQBF is PSPACE-hard
- 给定一个图灵机 M for a language L∈PSPACE, 给定一个输入 x, 需要将 M 是否 accept x 多项式时间内归约到 TQBF
- construct a QBF ϕ of polynomial size s.t. ϕ is true 等价于 M accepts x
- 对所有的 configuration 编码, for configurations u,v and an integer t, define ϕ(u,v,t)=true iff v is reachable from u in t steps
- 下面用 分治
- 首先考虑 ϕ(u,v,1) 就是说 u 与 v 一步就到达, 那么他们最多在三个位置上能不同, 其他位置都相同, 非常好判断
- 对于 t>1, 我们有 ϕ(u,v,t)=∃m[ϕ(u,m,t/2) and ϕ(m,v,t/2)]
- 问题在于 t 并不一定是 poly(|x|) 的
- change the previous 递推式 to
ϕ(u,v,t)=(∃m)(∀(a,b)∈{(u,m),(m,v)}[ϕ(a,b,t/2)])ϕ(u,v,t)=(∃m)(∀a)(∀b)[((a=u&b=m) or (a=m&b=v))→ϕ(a,b,t/2)]
- size: S(t)=S(t/2)+poly(∣x∣), thus S(t) is poly(∣x∣)
- ϕM,x=ϕ(cstart,caccept,h) is TRUE 当且仅当 M accepts x in h steps
- ϕ is constructible in poly-time
- 证毕
Description·
- 一个 formula ψ with variables x1,x2,⋯,xn
- 两个人轮流选择 xi 的取值, 第一个人 A 想要 ψ 为真, 第二个人 E 想要 ψ 为假
- FORMULA-GAME = {⟨ψ⟩∣ 在 ψ 的 formula game 中 E 有必胜策略 }
- 这个问题等价于 TQBF
Generalized Geography game·
Description·
- 一个有向图 G 起点 s
- 两个人轮流选择一条边往下走 走不了的输
- GG={⟨G,b⟩∣Player I has a winning strategy on G starting from b}
- GG is PSPACE-complete
-
GG is PSPACE

-
把 Formula Game 规约到他
Hierarchy theorem (层次定理)·
Time Hierarchy Theorem·
- For any time constructable function f:N→N, 存在语言 L that is decidable in time O(f(n)), but not in time O(logf(n)f(n))
Space Hierarchy Theorem·
- For any space constructable function f:N→N, 存在语言 L that is decidable in space O(f(n)) but not in space o(f(n))
证明思路·
- 采用跟证明 ATM 不可解时用的 对角线法
- 我们想要一个函数 D, 他对应的语言 L, 有 D 在 O(f(n)) 空间内运行, 并且 L 不同于任何在 o(f(n)) 内能判定的语言
- 不同于任何这样的语言 -> 有至少一个输入结果不同 -> 对于 M, 在输入 <M> 上不同
Proof·

对于所有的 o(f(n)) 空间内能判定的语言, 在第四步的判定中能够运行完, 因为模拟一个 g(n) 空间内运行的图灵机 M 只需要 dg(n) 空间, 其中 d 是依赖于 M 的常数. 所以可以找到一个充分大的 n0, dg(n0)<f(n0). 我们在 ⟨M⟩ 后面补上 10n0, 让长度足够, 所以第四步就能运行完.
这样, 运行的结果一定与 M(⟨M⟩) 本身的结果相反, 所以 D 不能判定 A.
Corollary·



The polynomial Hierarchy (PH)·
For i≥1, a language L is in Σip if there exists a polynomial time TM M and a polynomial q s.t.
x∈L⇔∃u1∈{0,1}q(∣x∣)∀u2∈{0,1}q(∣x∣)…Qiui∈{0,1}q(∣x∣)M(x,u1,…,ui)=1
where Qi is ∃ when i is odd; is ∀ when i is even.
(sometimes we can omit superscript “p”)
-
Theorem: Any wf. A 等价于 wf. B in prenex form.
-
Σ0=P
- Σ0 就是 x∈L⇔M(x)=1 就是一个多项式时间内能 decide 的 TM
-
Σ1=NP
- Σ1 就是 x∈L⇔∃u,M(x,u)=1 就是先猜一个解然后多项式时间内判断是否正确
-
定义 PH=∪iΣi
-
定义 Πip=coΣip, which is
x∈L⇔∀u1∈{0,1}q(∣x∣)∃u2∈{0,1}q(∣x∣)…Qiui∈{0,1}q(∣x∣)M(x,u1,…,ui)=1
-
跟之前 Σ 和 Π prenex form 差不多
-
Note that Σip⊂Πi+1p⊂Σi+2p, 所以 PH=∪iΠi
Oracle Turing Machine (OTM)·
Definition·
- 针对一个语言 A 的 oracle 是一个能判断 w 是否属于 A 的黑盒子. Oracle Turing Machine MA 指的是在一个通常的图灵机上增加查询 A 的 oracle 的能力. 有三个特殊的状态 qquery,qyes,qno. 每当进入到 qquery 态的时候, 就可以在一步之内查询在询问纸带上的 y 是否属于 A 并且依照结果进入到 qyes 或者 qno 状态.
- 我们可以类似地定义 Nondeterministic OTM
一些记号·
-

-

-
Both together: CD = languages decided by OTM “in” C with oracle language from D
- e.g. PSAT=PNP
-
Σ2=NPNP
-
Π2=coNPNP
-

Relativization·
- Many proofs and techniques we have seen are relativize
- they hold after replacing all TMs with oracle TMs that have
access to an oracle A
- including diagonalization
- 我们想要说明 P 是否等于 NP 的问题不是简单的对角化就能解决的
- 只要说明 加了某个 oracle 之后 PA=NPA, 加了另一个 oracle 之后 PB=NPB
PA=NPA·
- 这需要 A 很牛逼
- A=TQBF works
- PSPACE⊆PTQBF⊆NPTQBF⊆NPSPACE
- we also know PSPACE=NPSPACE
PB=NPB·
-
定义 L(B)={1k:∃x∈B,s.t.∣x∣=k}
-
we will find B such that L(B)∈NPB−PB
-
首先, L(B)∈NPB
- 对于任意 w 我们想判断是否属于 L(B)
- 只需要猜一个 x∈B 然后让 ∣x∣=∣w∣
-
其次, find B such that L(B)∈/PB
Randomized Computation·