np-completeness

41
NP- Completenes s Michael Tsai 2013/11/21

Upload: aleron

Post on 24-Feb-2016

79 views

Category:

Documents


0 download

DESCRIPTION

NP-Completeness. Michael Tsai 2013/11/21. 1. 這些問題目前尚未找到可以在 polynomial time 內解決的 algorithm. NP-Complete. 2. 這些問題目前尚未被證明無法在 polynomial time 內解決 . NP. 這些問題可以在 polynomial time 內解決. P. 這些問題可以在 polynomial time 內被 verify. P=NP???. 2011/05/04 為 P v.s . NP 提出之四十周年紀念 !! - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: NP-Completeness

NP-CompletenessMichael Tsai2013/11/21

Page 2: NP-Completeness

2

NP-Complete

1. 這些問題目前尚未找到可以在polynomial time 內解決的

algorithm.

𝑂 (𝑛𝑘 ) , 𝑓𝑜𝑟 𝑠𝑜𝑚𝑒𝑘

2. 這些問題目前尚未被證明無法在polynomial time 內解決 .

Page 3: NP-Completeness

3

NP

P這些問題可以在 polynomial time 內解決

2011/05/04 為 P v.s. NP 提出之四十周年紀念 !!Ref: http://blog.computationalcomplexity.org/2011/05/forty-years-of-p-v-np.html

這些問題可以在 polynomial time 內被 verify

P=NP???

Page 4: NP-Completeness

4

Euler tour versus hamiltonian cycle Digraph Euler tour: 每個邊都走過一遍 , 可以重複走過某個 vertex Hamiltonian cycle: 一個 simple cycle 把所有的 vertex 都走一遍

Page 5: NP-Completeness

5

一些 NP-complete 的問題Shortest simple

pathLongest simple

path

Solvable in polynomial time

NP-Complete

Hamiltonian CycleEuler Tour

2-CNF satisfiability

3-CNF satisfiability

2-CNF example: CNF: conjunctive normal form

Page 6: NP-Completeness

6

NP-Complete 一個問題是 NP, 而且跟 NP 裡面的其他問題至少”一樣難” ( 一樣難 : 所有 NP 裡面的問題可以在 polynomial time 裡面轉換成 NP-complete 的問題 ) 因為以上 , 所以”一解則全解” 學這個有什麼用 ? 雖然還沒有人證明出 NP-complete problems 無法在

polynomial time 裡面解出來 但是經過了 40 年了 , 沒有任何 NP-complete problem 被解出來 (polynomial time), 因此證明某問題為 NP-

complete 某種程度上也證明了它非常難解 ( 或甚至無法解 )

Page 7: NP-Completeness

7

Page 8: NP-Completeness

8

Decision problem v.s. optimization problem Decision problem: 輸出是 yes/no (1/0)

( 可不可以找到答案 ) Optimization problem: 輸出是最好的解

( 可以的答案中找出最好的那個 ) 例子 : Shortest path v.s. Path NP-Complete 只適用於 decision problems

Page 9: NP-Completeness

9

Decision problem v.s. optimization problem 怎麼將 optimization problem 轉換成

decision problem 呢 ? 對要 optimize 的值設定一個 bound 將 Shortest path 轉換成 decision problem: 給定 graph G, vertices u & v, integer k, 有沒有從 u 到 v 的路徑使用少於 k 個 edge?

Page 10: NP-Completeness

10

Reduction

Page 11: NP-Completeness

11

用 Reduction 證明”一樣難” 假設以下兩樣存在

則 B 也沒有 polynomial-time algorithm 可以解 使用反證法 , 假設有

A: no polynomial-time algorithm exist

Polynomial-time reduction algorithm:

instances of A instances of B

B: polynomial-time algorithmPolynomial-time reduction

algorithm:instances of A instances of B

A: polynomial-time algorithm 矛盾 . 所以 B 也沒有 .

Page 12: NP-Completeness

12

為什麼 Polynomial time就是”容易解” ? 雖然是 polynomial time, 但實務上這麼高次的多項式並不常見 通常如果找到一個 polynomial-time algorithm, 比較快的方法很快也會被找到 通常使用不同的 computation model( 之後自動機會教到 , 現在可以想像是單 CPU v.s. 多 CPU 的機器 ), 某 model 可用 polynomial-time 解的問題在另外一個 model 也可用 polynomial-time 解 Polynomials are closed under addition,

multiplication, and composition.

Page 13: NP-Completeness

13

Abstract problem

I: instances of problem

S: solutionsQ: Abstract problem(binary relation) Decision problem:

S={0,1}Example: PATH

𝑖=⟨𝐺 ,𝑢 ,𝑣 ,𝑘 ⟩

𝑃𝐴𝑇𝐻 (𝑖 )=0

if a shortest path from u to v has at most k edgesotherwise

Page 14: NP-Completeness

14

Encoding

A set S of abstract objects

The set of binary strings

encoding:mapping

Polygons, numbers, graphs, functions, ordered pairs, programs, …

Page 15: NP-Completeness

15

Some more definitions Concrete problem: 一個 problem 的 instance是 binary string 的 set, 則稱為 concrete

problem. 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

Page 16: NP-Completeness

16

P 的正式定義The complexity class P:The set of concrete decision problems that are polynomial-time solvable

Page 17: NP-Completeness

17

Abstract problem轉換成concrete problem

I: instances of problem S: solutionsQ: Abstract

problem(binary relation) Decision problem:

S={0,1}

e(I): {0,1}*

𝑒 : 𝐼→ {0,1 }∗

e(Q): Concrete problem

Page 18: NP-Completeness

18

Encoding 和花的時間有關嗎 ? 有 ! 極端的例子 : unary input: integer k, running time: 假設 encoding 是 unary: 11111…1111 則在這樣的 case 下 input length: n running time: 可是如果以正常的 binary encoding 表示 input length: running time: Encoding 決定是 or !!

k 個

Page 19: NP-Completeness

19

Encoding 和花的時間有關嗎 ? 然而如果我們不考慮這麼極端的例子 (unary), 大部分的

encoding 都不會影響到一個問題是否可以在 polynomial time 解決 .

例 : 使用三進位數和二進位數是沒有差別的 , 因為我們可以在 polynomial time 裡面將三進位數轉換成二進位數 .

f: {0,1}*{0,1}*input output

如果 f 花 polynomial time 可以把任何 input轉成 output, 則稱為 polynomial-time computable

Page 20: NP-Completeness

20

I: instances of problem S: solutions

Q: Abstract problem(binary relation)

Decision problem:S={0,1}

𝑒1: {0,1 }∗𝑒1: 𝐼→ {0,1 }∗

: Concrete problem

𝑒2: {0,1 }∗𝑒2: 𝐼→ {0,1 }∗

: Concrete problem

polynomially related

if:

Then: if and only if

Lemma:

Page 21: NP-Completeness

21

Proof: 因為是對稱的 , 所以只需要證明一個方向 . 假設可以在時間內解決 (for some constant

k) 假設對每個 problem instance i, 轉換成需花 (for some constant c), 則解決 (input 為 ) 先花轉換成 再解決 (input 為 ), 花 c, k 都是 constant, 因此為 polynomial

time只要 encoding 都是”合理的” (“ 簡要的” ) 表示方式 , 一個問題的複雜度 ( 能否在 polynomial time 裡面解掉 ) 不會被encoding 影響 .

Page 22: NP-Completeness

22

A Formal-language Framework An alphabet : a finite set of symbols A language over : 使用裡面的 symbol 組合而成的字串 ( 不一定包含全部可能的字串 ) Ex: , (over )= empty string: empty language: : the language with all strings over

Page 23: NP-Completeness

23

A Formal-language Framework

Operations on languages: Union, intersection Complement: Concatenation of : Closure or Kleene Star:

…concatenation 自己 k 次

Page 24: NP-Completeness

24

應用 formal language framework… Decision problem Q 的 set of instances 為 Q 的主要特性可以想成是會產生答案為 1(yes) 的這些

instances 因此可以把 Q 重新定義為一個 language over , 而 例子 : PATH= is an undirected graph, is an

integer, and 從 u 到 v 在 G 裡面有一條路徑含有最多 k 條 edge

Page 25: NP-Completeness

25

Accepts and Rejects An algorithm A accepts a string if, given input

x, A outputs 1 An algorithm A rejects a string if, given input

x, A outputs 0 The language accepted by an algorithm A

is the set of strings 注意 : 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 .

Page 26: NP-Completeness

26

: PATH The language PATH can be accepted in

polynomial time. 這句話什麼意思 ? 如果可以找到解 ( 從 u 到 v 在 G 裡面有一條路徑含有最多 k 條 edge), 則可以在 polynomial time 裡面說”有 (1, yes)”! 可以嗎 ? 可以 ! 用 BFS 找出最短路徑 , 然後看有沒有比 k 大 ( 只需 polynomial time) 假設我們設計這個 algorithm 發現比 k 大的話就無窮迴圈 , 這樣的話就沒有 decided in polynomial

time.

Page 27: NP-Completeness

27

使用 formal-language framework定義 complexity class P Complexity class: a set of languages, 是不是在其中由 algorithm 的 complexity

measure 決定 (ex. running time), 而此algorithm 是決定一個 string x 是否屬於 L.

使用這個方式 , 我們可以重新定義 P 這個complexity class:

𝑃={𝐿⊆ {0,1 }∗ :

Page 28: NP-Completeness

28

Theorem: . 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.

假設 L 是被某 polynomial-time algorithm A accept.

我們要利用 A 做成一個 algorithm A’ 可以decides L.

Page 29: NP-Completeness

29

因為 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.

Page 30: NP-Completeness

30

Algorithms that accepts/rejects/decides

L告訴你某個 instance 是不是有解 ( 在 L 裡面 )

Algorithms that verify L with a certificate

給你一個 certificate ( 可能是答案 ), 可以讓你檢查某個 instance 是不是有解 ( 在 L 裡面 )

給和一條 path p, 我們可以檢查 path 是不是真的是在 G 中 uv 的 path, 且長度是不是不超過 k. 此 p 是一個 certificate, 用來幫助algorithm 看此 instance 是不是屬於 PATH.

對 PATH 來說其實沒有太大差別 , 因為本來就可以在 polynomial time decide PATH. 但是對於其他問題可能有差別 !

Page 31: NP-Completeness

31

Hamiltonian cycles A Hamiltonian cycle of an undirected graph

G=(V,E) is a simple cycle that contains each vertex in V.

Not all graph is Hamiltonian ( 找不到Hamiltonian cycle)

HAM-CYCLE={: G is a Hamiltonian graph}

Page 32: NP-Completeness

32

Hamiltonian cycles 暴力法 ? 假設使用 adjacency matrix, n= 是 G 的

encoding 的長度 ( 也就是 ,m 是 G 中 vertex數 ) 檢查所有的 vertex permutation 需要 not

for any constant k. 目前還找不到 polynomial time algorithm

to decide/accept HAM-CYCLE

Page 33: NP-Completeness

33

Verify 會簡單一點嗎 ? 會 ! 假設告訴你某一個 graph G 是 Hamiltonian, 然後告訴你一個 vertex 的序列 (certificate)可以組成 Hamiltonian cycle. 則我們可以在 polynomial time 裡面檢查 :

這個 vertex 序列是不是真的是 G 裡面的vertex 的 permutation

vertex 序列的相鄰 vertices 之間是不是在 G 中有那個 edge

Page 34: NP-Completeness

34

Verification Algorithm Verification Algorithm: Algorithm A with two

arguments: Ordinary input string x Binary string y (certificate)

A verifies an input string x if there exists a certificate y such that A(x,y)=1.

The language verified by a verification algorithm A is

如果 x 在 L 裡面 , 則一定找得到 y. 如果 x 不在 L 裡面 , 則一定找不到 y.

Page 35: NP-Completeness

35

The complexity class NP Complexity class NP: the class of

languages that can be verified by a polynomial-time algorithm.

A language L belongs to NP if and only if there exist a two-input polynomial-time algorithm A and a constant c such thatL=

Then algorithm A verifies L in polynomial time.

Page 36: NP-Completeness

36

What is in NP? HAM-CYCLENP if , then . Why? 可以做出一個 algorithm 是完全不甩

certificate 的 , 就可以模擬出 verification algorithm 的效果

意思就是說 . 但 P=NP or not? ( 尚未得知 )

Page 37: NP-Completeness

37

Complexity class co-NP class NP is closed under complement?

( 尚未得知 ) 意思就是說的話 , 否 ? co-NP: all languages that satisfies

Page 38: NP-Completeness

38

NP-Complete languages “The hardest languages in NP” If NP-P is nonempty, then these in NP-

Complete are in NP-P (such as HAM-CYCLE)

Reducibility 解一個破全部 , 一箭千雕

Page 39: NP-Completeness

39

Reducibility 如果 Q 可以 reduce 成 Q’, 則表示任何一個 Q的 instance 都可以”換句話說”變成 Q’ 的一個 instance 一元一次方程式 : ax+b=0 可以視為一元二次方程式的特例 : , 解出來可以得到對應的一元一次方程式解 . 如果一個問題 Q 可以 reduce 成另外一個問題

Q’, 則 Q 不會比 Q’ 難解 .

Page 40: NP-Completeness

40

Reduction is polynomial-time reducible to , (寫成 )

if there exists a polynomial-time computable function f: such that for all , if and only if .

f: reduction function 用來計算 f 的 polynomial-time algorithm

F: reduction algorithm

Page 41: NP-Completeness

41