Completeness
Jennya 2013/10/31
為什麼Polynomial time就是
”容易解”, ”可解的”?
(1)
Θ(𝑛100)雖然是polynomial time, 但實務上這麼高次的多項式並 不常見 通常如果找到一個polynomial-time algorithm, 比較快的方法很 快也會被找到
(2)
通常使用不同的computation model(之後自動機會教到, 現在可 以想像是單CPU v.s. 多CPU的機器), 某model可用polynomial- time解的問題在另外一個model也可用polynomial-time解
(3)
Polynomials are closed under addition, multiplication, and composition.
Abstract problem
I
problem instances
S
problem solutions Q: Abstract problem
(binary relation) Example: PATH
𝑖 = 𝐺, 𝑢, 𝑣, 𝑘
𝑃𝐴𝑇𝐻 𝑖 = 1 if a shortest path from u to v has at most k edges 𝑃𝐴𝑇𝐻 𝑖 = 0 otherwise
Decision problem:
S={0,1}
Encoding
A set S of abstract objects
The set of binary strings
encoding:
mapping Polygons, numbers,
graphs, functions, ordered pairs, programs, …
Abstract problem轉換成 concrete problem
We can use encodings to map abstract problems to concrete problems
Instance set I solution set S
{0,1}
Q
Abstract problem Abstract Decision Problem Q
𝑒: 𝐼 → 0,1 ∗
e(I): {0,1}* solution set S
{0,1}
e(Q)
Concrete problem Concrete Decision Problem e(Q)
Concrete problem:
instance set = the set of binary strings
「An algorithm solves a concrete problem in O(T(n))」
一個problem的instance長度為n (i的長度, 即為binary string長度)
而此algorithm可在O(T(n))時間產生解
「A concrete problem is polynomial-time solvable」
有一個𝑂 𝑛𝑘 𝑓𝑜𝑟 𝑠𝑜𝑚𝑒 𝑘的algorithm可以解此 problem
Concrete problem
P的正式定義
The complexity class P:
The set of concrete decision problems
that are polynomial-time solvable
Encoding和花的時間有關嗎?
有! 極端的例子: unary
input: integer k
running time: Θ 𝑘
Unary encoding: 11111…1111 input length n
running time: Θ(𝑘) = Θ(𝑛)
binary encoding:
input length n = log 𝑘 + 1
running time:Θ(𝑘) = Θ(2𝑛)
Encoding決定是Θ(𝑛) or Θ(2𝑛)!!
k個
Encoding和花的時間有關嗎?
然而如果我們不考慮這麼極端的encoding方式 (unary), 其他的encoding都不會影響到一個問題是 否可以在polynomial time解決.
例: 使用三進位數和二進位數是沒有差別的, 因為
我們可以在polynomial time裡面將三進位數轉換 成二進位數.
polynomial-time computable function
f: {0,1}*{0,1}*
input output
如果f花polynomial time可以把任何input轉成 output, 則稱為polynomial-time computable
Polynomially related
I: instances of problem
𝑒1: 0,1 ∗
𝑒1: 𝐼 → 0,1 ∗ 𝑒2: 𝐼 → 0,1 ∗
𝑒2: 0,1 ∗ 𝑓12 𝑒1 𝑖 = 𝑒2(𝑖)
𝑓21 𝑒2 𝑖 = 𝑒1(𝑖)
如果有𝑓12和𝑓21是polynomial-time computable, 則𝑒1和𝑒2為 polynomially related.
I: instances of
problem S: solutions
Q: Abstract problem
(binary relation) Decision problem:
S={0,1}
𝑒1: 0,1 ∗ 𝑒1: 𝐼 → 0,1 ∗
𝑒1(𝑄): Concrete problem 𝑒2: 0,1 ∗
𝑒2: 𝐼 → 0,1 ∗
𝑒2(𝑄): Concrete problem
polynomially related
if:
Then: 𝑒1(𝑄) ∈ 𝑃 if and only if 𝑒2(𝑄) ∈ 𝑃
Proof:
假設𝑒1(𝑄)可以在𝑂(𝑛𝑘)時間內解決(for some constant k)
假設 對每個problem instance i, 𝑒2(𝑖)轉換成𝑒1(𝑖)需花 𝑂(𝑛𝑐)(for some constant c), 𝑛 = 𝑒2 𝑖
則解決𝑒2 𝑄 (input為𝑒2(𝑖)) 先花𝑂(𝑛𝑐)轉換成𝑒1(𝑖)
𝑒1 𝑖 = 𝑂(𝑛𝑐)
再解決𝑒1(𝑄) (input為𝑒1(𝑖)), 花𝑂 𝑒1 𝑖 𝑘 = 𝑂 𝑛𝑐𝑘
c, k都是constant, 因此為polynomial time
因為是對稱的, 所以只需要證明一個方向.
只要encoding都是”合理的” (“簡要的”)表示方式, 一個問題的複雜度 (能否在polynomial time裡面解掉)不會被encoding影響.
A Formal-language Framework
An alphabet Σ: a finite set of symbols
A language 𝐿 over Σ: 使用Σ裡面的symbol組合而 成的字串 (不一定包含全部可能的字串)
Ex: Σ = 0,1 , 𝐿 (over Σ)={10,11,101,111, … }
empty string: ϵ
empty language: ∅
Σ∗: the language with all strings over Σ
Operations on languages
Union
Intersection
Complement: 𝐿 = Σ∗ − 𝐿
Concatenation of 𝐿1𝐿2:
𝐿 = 𝑥1𝑥2: 𝑥1 ∈ 𝐿1 𝑎𝑛𝑑 𝑥2 ∈ 𝐿2
Closure (Kleene Star):
𝐿∗ = 𝜖 ⋃𝐿 ⋃𝐿2 ⋃𝐿3⋃…
𝐿𝑘:concatenation 自己k次
應用formal language framework…
We can view
「a decision problem Q 」as
「a language L over Σ = 0,1 」
=> 𝐿 = {𝑥 ∈ Σ∗: 𝑄 𝑥 = 1}
Q的instance set為Σ∗
Q = 能夠產生答案為1(yes)的這些instances
i.e. PATH problem的language:
Accepts and Rejects
An algorithm A accepts a string 𝑥 ∈ 0,1 ∗ if, given input x, the algorithm’s output A(x) = 1
An algorithm A rejects a string 𝑥 ∈ 0,1 ∗ if, given input x, the algorithm’s output A(x) = 0
The language accepted by an algorithm A is the set of strings 𝐿 = {𝑥 ∈ 0,1 ∗: 𝐴 𝑥 = 1}
注意: L is accepted by A, 不一定表示𝑥 ∉ 𝐿會被A reject! (ex. 無窮迴圈)
A language is decided by an algorithm A if every binary string in L is accepted by A and every binary string not in L is rejected by A
A language is accepted in polynomial time if it is accepted by A and if A accepts x in time 𝑂(𝑛𝑘) for a constant k and any length-n string 𝑥 ∈ 𝐿.
使用formal-language framework 定義complexity class P
可以用「a set of languages」定義 「complexity class」
如何決定是不是在這個class(set)中:
由「決定一個string x是否屬於L」的 algorithm的 running time而定
使用這個方式, 我們可以重新定義P這個complexity class:
𝑃 = {𝐿 ⊆ 0,1 ∗:
there exists an algorithm A that decides L in polynomial time}
Theorem:
𝑃 = {𝐿: 𝐿 is accepted by a polynomial time algorithm}.
Proof:
The class of languages decided by polynomial-time
algorithms是the class of languages accepted by polynomial- time algorithms的subset.
所以我們只需要證如果L is accepted by a polynomial-time algorithm, 它也可以decided by a polynomial-time algorithm.
𝑃 = {𝐿 ⊆ 0,1 ∗:
there exists an algorithm A that 𝐝𝐞𝐜𝐢𝐝𝐞𝐬 L in polynomial time}
𝑃 = {𝐿 ⊆ 0,1 ∗:
there exists an algorithm A that 𝐚𝐜𝐜𝐩𝐞𝐭𝐬 L in polynomial time}
假設L是被某polynomial-time algorithm A accept.
我們要利用A做成一個algorithm A’可以decides L.
因為A accepts L in 𝑂(𝑛𝑘) for some constant k, 所 以我們也可以說 A accepts L 最多花𝑐𝑛𝑘個steps for a constant c
對任何input x, A’ 利用A, 先執行𝑐𝑛𝑘個steps. 如 果這時候A accept x了, A’就accept x. 如果A還沒 accept x, A’就reject x.
A’使用A的overhead不會超過一個polynomial factor, 所以A’是一個可以decide L的polynomial time algorithm.