Aaex7 group2(中英夾雜)

27
Advanced Algorithms Exercise 6 Group 2 陳右緯、楊翔雲、蔡宗衛、BINAYA KAR、林淑慧 2014/1/10 1 Q1 Q8

Transcript of Aaex7 group2(中英夾雜)

Page 1: Aaex7 group2(中英夾雜)

Advanced Algorithms

Exercise 6

Group 2

陳右緯、楊翔雲、蔡宗衛、BINAYA KAR、林淑慧

2014/1/10 1Q1 Q8

Page 2: Aaex7 group2(中英夾雜)

Q1

• Show that the class P, viewed as a set of languages is closed under union, intersection, concatenation, complement and Kleene star. That is, if L1, L2 ∈ P, then, L1 ∪ L2 ∈ P, etc.

2014/1/10 2Q1 Q8

Page 3: Aaex7 group2(中英夾雜)

Q1

• Union L1 ∪ L2 ∈ Pf(L) {

return f1(L) or f2(L);}

• Intersection L1 ∩ L2 ∈ Pf(L) {

return f1(L) and f2(L);}

2014/1/10 3Q1 Q8

Page 4: Aaex7 group2(中英夾雜)

Q1

• Concatenation L1 L2 ∈ Pf(L) {

for i = 0 to L.lengthL1 = L.substr(0, i)L2 = L.substr(i+1)if(f1(L1) and f2(L2))

return true;return false;

}2014/1/10 4Q1 Q8

Page 5: Aaex7 group2(中英夾雜)

Q1

• Complement ¬ L1 ∈ Pf(L) {

return ¬ f1(L);}

2014/1/10 5Q1 Q8

Page 6: Aaex7 group2(中英夾雜)

Q1

• Kleene star L*∈ Pf(L) {

for i = 0 to L.lengthL1 = L.substr(0, i)L’ = L.substr(i+1)if(f1(L1) and f(L’))

return true;return false;

}

2014/1/10 6Q1 Q8

Page 7: Aaex7 group2(中英夾雜)

Q1

• Kleene star L*∈ PIf we can use dynamic programming, state is that DP[i][j] whether a substring[i][j] deciding L∈ P.

• Space O(n2)

• Time O(n3)

2014/1/10 7Q1 Q8

Page 8: Aaex7 group2(中英夾雜)

Q2

• Show that if the decision version of the Hamiltonian cycle is polynomial-time solvable then so is the problem of finding a Hamiltonian cycle.

• 如果有一個演算法可以在多項式時間

內驗證漢米頓環道,就可以在多項式

時間內找到漢米頓環道。

2014/1/10 8Q1 Q8

Page 9: Aaex7 group2(中英夾雜)

Q2

• 假設 HAM-CYCLE ∈ P

• 挑出一個 v ∈ V,Ev 是 v 的所有邊,

e1, e2 ∈ Ev,挑 e1, e2 在多項式時間內。

得到 G’= (V, E – Ev ∪ {e1, e2})使用驗證的演算法決定是否 G’ 存有 HAM-CYCLE,是的話則遞歸下去。

2014/1/10 9Q1 Q8

Page 10: Aaex7 group2(中英夾雜)

Q2

• HAM-CYCLE(V, E) {v = choose one from V and |Ev| > 2if(v == null)

return DECIDE-HAM-CYCLE(V, E)for choose pair(e1, e2) from Ev

G’= (V, E – Ev ∪ {e1, e2}) if(DECIDE-HAM-CYCLE(G’.V, G’.E)

return HAM-CYCLE(G’.V, G’.E)return false

}

2014/1/10 10Q1 Q8

Page 11: Aaex7 group2(中英夾雜)

Q3

• Show that the class NP, viewed as a set of languages is closed under union, intersection, concatenation and Kleene star.

2014/1/10 11Q1 Q8

Page 12: Aaex7 group2(中英夾雜)

Q3

• Same as Q1 ?

2014/1/10 12Q1 Q8

Page 13: Aaex7 group2(中英夾雜)

Q4

• Prove that P ⊆ NP ∩ co-NP and if NP ≠ co-NP, then P ≠ NP.

• Problem NP ≠ co-NP → P ≠ NP⇒ P = NP → NP = co-NP

• Because class P is closed under complement(NOT), P = NP ⇒ ¬ P = ¬ NP

⇒ P = co-NP ⇒ NP = co-NP

2014/1/10 13Q1 Q8

Page 14: Aaex7 group2(中英夾雜)

Q4

• Prove that P ⊆ NP ∩ co-NP and if NP ≠ co-NP, then P ≠ NP.

• Problem NP ≠ co-NP → P ≠ NP⇒ P = NP → NP = co-NP

• Because class P is closed under complement(NOT), P = NP ⇒ ¬ P = ¬ NP

⇒ P = co-NP ⇒ NP = co-NP

2014/1/10 14Q1 Q8

Page 15: Aaex7 group2(中英夾雜)

Q5

• Show that 2-CNF-SAT is polynomial time solvable.

2014/1/10 15Q1 Q8

Page 16: Aaex7 group2(中英夾雜)

Q5

• Clause (x ∨ y)if x = false, y = true.if y = false, x = true.

• Build DAG.Each variable v has v and ¬ v // true and false.

• (x ∨ y)have two direct edge (¬ x, y) and (¬ y, x)// if x is false, y must true.// if y is false, x must true.

• (¬ x ∨ y)have two direct edge (¬ (¬ x), y) and (¬ y, ¬ x)

2014/1/10 16Q1 Q8

Page 17: Aaex7 group2(中英夾雜)

Q5

• Each variable v has v and ¬ v // true and false.

• 建造 SCC 強連通元件,同一個 SCC 表示可以互

相推論得到,如果 v 和 v’ 同時在同一個 SCC 中,

則表示怎麼推論都會矛盾,意即不滿足。

2014/1/10 17Q1 Q8

Page 18: Aaex7 group2(中英夾雜)

Q6

• The subgraph isomorphism problem takes two graphs G1 and G2 and asks whether G1 is isomorphic to a subgraph of G2. Show that this problem is NP-complete.

• HAM-CYCLE

≤p Subgraph-Isomorphism Problem

2014/1/10 18Q1 Q8

Page 19: Aaex7 group2(中英夾雜)

Q6

• HAM-CYCLE G(V, E)

Let G2 =G, G1 = cycle with v nodes.

藉由轉換 HAM-CYCLE 相當於子圖同構問題,

由於 HAM-CYCLE 是 NP-Complete,

因此子圖同構問題也是 NP-Complete。

• HAM-CYCLE

≤p Subgraph-Isomorphism Problem

2014/1/10 19Q1 Q8

Page 20: Aaex7 group2(中英夾雜)

Q7

• Given an integer m-by-n matrix A, and an integer m-vector b, the integer programming problem asks whether there is an integer n-vector x such that

Ax ≤ b.

• Prove that this problem is NP-complete.

• 3-CNF-SAT ≤p

0-1 integer-programming problem

2014/1/10 20Q1 Q8

Page 21: Aaex7 group2(中英夾雜)

Q7

• Given an integer m-by-n matrix A, and an integer m-vector b, the integer programming problem asks whether there is an integer n-vector x such that

Ax ≤ b.

• Prove that this problem is NP-complete.

• 3-CNF-SAT ≤p

0-1 integer-programming problem

• // 總覺得題目好像少給了什麼

2014/1/10 21Q1 Q8

Page 22: Aaex7 group2(中英夾雜)

Q7

• 3-CNF-SAT

Ex. (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ ¬ x3 ∨ ¬ x4)

• (x1 ∨ x2 ∨ x3) : x1 + x2 + x3 ≥ 1- x1 - x2 - x3 ≤ -1

• (x1 ∨ ¬ x3 ∨ ¬ x4) : x1 + (1-x3) + (1-x4) ≥ 1- x1 + x3 + x4 ≤ 1

• Ax ≤ b

• 以此類推,可以在多項式時間內轉換,得證。

0-1 integer-programming problem is NPC.2014/1/10 22Q1 Q8

1

1x

11

01-

01-

1-1-

Page 23: Aaex7 group2(中英夾雜)

Q8

• Given a set S of integers, determine whether there exists a subset A ⊆ S, such that

• sigma(x)|x ∈ A = sigma(y)| y ∈ S - AShow this problem is NP-complete.

2014/1/10 23Q1 Q8

Page 24: Aaex7 group2(中英夾雜)

Q8

• SUBSUM-SET(SOS) ≤p SET-PARTITION

• 令 K = 一半即可 ? 未解決

2014/1/10 24Q1 Q8

Page 25: Aaex7 group2(中英夾雜)

Q10

• Show that the Hamiltonian path problem is NP-complete.

• HAM-CYCLE ≤p HAM-PATH

2014/1/10 25Q1 Q8

Page 26: Aaex7 group2(中英夾雜)

Q10

• HAM-CYCLE ≤p HAM-PATH

2014/1/10 26Q1 Q8

Page 27: Aaex7 group2(中英夾雜)

Q10

• HAM-CYCLE ≤p HAM-PATH

• 將其中一個點拆成兩個(入點、出點),

並且多增加兩個點連到入點和出點。

• 如果 HAM-PATH 存在,只要將這兩個

點合併再一起即可(合併成一條路)

2014/1/10 27Q1 Q8