SlideShare a Scribd company logo
Advanced Algorithms
Exercise 6

Group 2
陳右緯、楊翔雲、蔡宗衛、BINAYA KAR、林淑慧
2014/1/10

Q1 Q8

1
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

Q1 Q8

2
Q1
• Union L1 ∪ L2 ∈ P
f(L) {
return f1(L) or f2(L);
}
• Intersection L1 ∩ L2 ∈ P
f(L) {
return f1(L) and f2(L);
}
2014/1/10

Q1 Q8

3
Q1
• Concatenation L1 L2 ∈ P
f(L) {
for i = 0 to L.length
L1 = L.substr(0, i)
L2 = L.substr(i+1)
if(f1(L1) and f2(L2))
return true;
return false;
}

2014/1/10

Q1 Q8

4
Q1
• Complement ¬ L1 ∈ P
f(L) {
return ¬ f1(L);
}

2014/1/10

Q1 Q8

5
Q1
• Kleene star L* ∈ P
f(L) {
for i = 0 to L.length
L1 = L.substr(0, i)
L’ = L.substr(i+1)
if(f1(L1) and f(L’))
return true;
return false;
}
2014/1/10

Q1 Q8

6
Q1
• Kleene star L* ∈ P
If 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

Q1 Q8

7
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

Q1 Q8

8
Q2
• 假設 HAM-CYCLE ∈ P
• 挑出一個 v ∈ V,Ev 是 v 的所有邊,
e1, e2 ∈ Ev,挑 e1, e2 在多項式時間內。
得到 G’= (V, E – Ev ∪ {e1, e2})
使用驗證的演算法決定是否 G’ 存有 HAMCYCLE,是的話則遞歸下去。

2014/1/10

Q1 Q8

9
Q2
• HAM-CYCLE(V, E) {
v = choose one from V and |Ev| > 2
if(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

Q1 Q8

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

2014/1/10

Q1 Q8

11
Q3
• Same as Q1 ?

2014/1/10

Q1 Q8

12
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

Q1 Q8

13
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

Q1 Q8

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

2014/1/10

Q1 Q8

15
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

Q1 Q8

16
Q5
• Each variable v has v and ¬ v // true and false.
• 建造 SCC 強連通元件,同一個 SCC 表示可以互
相推論得到,如果 v 和 v’ 同時在同一個 SCC 中,
則表示怎麼推論都會矛盾,意即不滿足。

2014/1/10

Q1 Q8

17
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 NPcomplete.

• HAM-CYCLE
≤p Subgraph-Isomorphism Problem

2014/1/10

Q1 Q8

18
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

Q1 Q8

19
Q7
• Given an integer m-by-n matrix A, and an integer mvector 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

Q1 Q8

20
Q7
• Given an integer m-by-n matrix A, and an integer mvector 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

Q1 Q8

21
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 + x 3 + x 4 ≤ 1
1
• Ax ≤ b - 1 - 1 - 1 0 x
-1

0

1

1

1

• 以此類推,可以在多項式時間內轉換,得證。
0-1 integer-programming problem is NPC.
2014/1/10
Q1 Q8

22
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 - A
Show this problem is NP-complete.

2014/1/10

Q1 Q8

23
Q8
• SUBSUM-SET(SOS) ≤p SET-PARTITION
• 令 K = 一半即可 ? 未解決

2014/1/10

Q1 Q8

24
Q10
• Show that the Hamiltonian path problem
is NP-complete.
• HAM-CYCLE ≤p HAM-PATH

2014/1/10

Q1 Q8

25
Q10
• HAM-CYCLE ≤p HAM-PATH

2014/1/10

Q1 Q8

26
Q10
• HAM-CYCLE ≤p HAM-PATH
• 將其中一個點拆成兩個(入點、出點),
並且多增加兩個點連到入點和出點。
• 如果 HAM-PATH 存在,只要將這兩個
點合併再一起即可(合併成一條路)

2014/1/10

Q1 Q8

27

More Related Content

PPTX
Aaex4 group2(中英夾雜)
PPTX
Aaex5 group2(中英夾雜)
DOC
Time and space complexity
PPTX
Aaex3 group2
PPT
asymptotic notations i
DOC
Algorithms Question bank
PDF
How to design a linear control system
PDF
Asymptotic notation
Aaex4 group2(中英夾雜)
Aaex5 group2(中英夾雜)
Time and space complexity
Aaex3 group2
asymptotic notations i
Algorithms Question bank
How to design a linear control system
Asymptotic notation

What's hot (20)

PPT
Asymptotic notations
PDF
A study of the worst case ratio of a simple algorithm for simple assembly lin...
PDF
Elliptic Curve Cryptography
PDF
20110319 parameterized algorithms_fomin_lecture01-02
PPTX
Elliptic Curve Cryptography
PPTX
Theory of automata and formal languages Unit 4
PPT
1524 elliptic curve cryptography
PPTX
Asymptotic notations
PDF
Conditional neural processes
PDF
14 - 08 Feb - Dynamic Programming
PDF
Csr2011 june18 12_00_nguyen
PPTX
Data Structures- Hashing
PDF
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
PPT
Asymptotic analysis
PPTX
Asymptotics 140510003721-phpapp02
PDF
Scribed lec8
PPTX
Signals Processing Homework Help
PPTX
Digital Signal Processing Assignment Help
Asymptotic notations
A study of the worst case ratio of a simple algorithm for simple assembly lin...
Elliptic Curve Cryptography
20110319 parameterized algorithms_fomin_lecture01-02
Elliptic Curve Cryptography
Theory of automata and formal languages Unit 4
1524 elliptic curve cryptography
Asymptotic notations
Conditional neural processes
14 - 08 Feb - Dynamic Programming
Csr2011 june18 12_00_nguyen
Data Structures- Hashing
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
Asymptotic analysis
Asymptotics 140510003721-phpapp02
Scribed lec8
Signals Processing Homework Help
Digital Signal Processing Assignment Help
Ad

Similar to Aaex7 group2(中英夾雜) (20)

PPT
Np completeness
PPTX
Algorithm_NP-Completeness Proof
PPT
Np completeness h4
PPTX
P, NP and NP-Complete, Theory of NP-Completeness V2
PDF
NP Problems in design and analysis of alogorithm
PDF
PPTX
Ads unit 3 ppt
PPTX
PNP.pptx
PPTX
PPTX
Discrete mathematics suraj ppt
PDF
Reductions
PDF
Efficient Edge-Skeleton Computation for Polytopes Defined by Oracles
PDF
Polynomials.pdf
PDF
Sep logic slide
PDF
practice-final-soln.pdf
PDF
Process Algebras and Petri Nets are Discrete Dynamical Systems
PDF
np hard, np complete, polynomial and non polynomial
PPT
class23.ppt
PPT
lecture 30
PPT
lecture 29
Np completeness
Algorithm_NP-Completeness Proof
Np completeness h4
P, NP and NP-Complete, Theory of NP-Completeness V2
NP Problems in design and analysis of alogorithm
Ads unit 3 ppt
PNP.pptx
Discrete mathematics suraj ppt
Reductions
Efficient Edge-Skeleton Computation for Polytopes Defined by Oracles
Polynomials.pdf
Sep logic slide
practice-final-soln.pdf
Process Algebras and Petri Nets are Discrete Dynamical Systems
np hard, np complete, polynomial and non polynomial
class23.ppt
lecture 30
lecture 29
Ad

More from Shiang-Yun Yang (14)

PPTX
User interface
PPTX
Polarity analysis for sentiment classification
PPTX
文明的進程第十組
PPTX
計算幾何論文報告 Minimum local disk cover sets
PPTX
N grams as linguistic features
PDF
軍事報告 電磁砲
PDF
第二十組福斯汽車
PPTX
敏捷簡報
PDF
計算型智慧論文報告 Building optimal regression tree ...
PPTX
Rpg 角色扮演遊戲 – 初探
PPTX
Aaex6 group2(中英夾雜)
PPTX
通識報告
PPTX
Aaex2 group2
PDF
Alex1 group2
User interface
Polarity analysis for sentiment classification
文明的進程第十組
計算幾何論文報告 Minimum local disk cover sets
N grams as linguistic features
軍事報告 電磁砲
第二十組福斯汽車
敏捷簡報
計算型智慧論文報告 Building optimal regression tree ...
Rpg 角色扮演遊戲 – 初探
Aaex6 group2(中英夾雜)
通識報告
Aaex2 group2
Alex1 group2

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
1. Introduction to Computer Programming.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine Learning_overview_presentation.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Assigned Numbers - 2025 - Bluetooth® Document
SOPHOS-XG Firewall Administrator PPT.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.
1. Introduction to Computer Programming.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Aaex7 group2(中英夾雜)

  • 1. Advanced Algorithms Exercise 6 Group 2 陳右緯、楊翔雲、蔡宗衛、BINAYA KAR、林淑慧 2014/1/10 Q1 Q8 1
  • 2. 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 Q1 Q8 2
  • 3. Q1 • Union L1 ∪ L2 ∈ P f(L) { return f1(L) or f2(L); } • Intersection L1 ∩ L2 ∈ P f(L) { return f1(L) and f2(L); } 2014/1/10 Q1 Q8 3
  • 4. Q1 • Concatenation L1 L2 ∈ P f(L) { for i = 0 to L.length L1 = L.substr(0, i) L2 = L.substr(i+1) if(f1(L1) and f2(L2)) return true; return false; } 2014/1/10 Q1 Q8 4
  • 5. Q1 • Complement ¬ L1 ∈ P f(L) { return ¬ f1(L); } 2014/1/10 Q1 Q8 5
  • 6. Q1 • Kleene star L* ∈ P f(L) { for i = 0 to L.length L1 = L.substr(0, i) L’ = L.substr(i+1) if(f1(L1) and f(L’)) return true; return false; } 2014/1/10 Q1 Q8 6
  • 7. Q1 • Kleene star L* ∈ P If 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 Q1 Q8 7
  • 8. 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 Q1 Q8 8
  • 9. Q2 • 假設 HAM-CYCLE ∈ P • 挑出一個 v ∈ V,Ev 是 v 的所有邊, e1, e2 ∈ Ev,挑 e1, e2 在多項式時間內。 得到 G’= (V, E – Ev ∪ {e1, e2}) 使用驗證的演算法決定是否 G’ 存有 HAMCYCLE,是的話則遞歸下去。 2014/1/10 Q1 Q8 9
  • 10. Q2 • HAM-CYCLE(V, E) { v = choose one from V and |Ev| > 2 if(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 Q1 Q8 10
  • 11. Q3 • Show that the class NP, viewed as a set of languages is closed under union, intersection, concatenation and Kleene star. 2014/1/10 Q1 Q8 11
  • 12. Q3 • Same as Q1 ? 2014/1/10 Q1 Q8 12
  • 13. 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 Q1 Q8 13
  • 14. 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 Q1 Q8 14
  • 15. Q5 • Show that 2-CNF-SAT is polynomial time solvable. 2014/1/10 Q1 Q8 15
  • 16. 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 Q1 Q8 16
  • 17. Q5 • Each variable v has v and ¬ v // true and false. • 建造 SCC 強連通元件,同一個 SCC 表示可以互 相推論得到,如果 v 和 v’ 同時在同一個 SCC 中, 則表示怎麼推論都會矛盾,意即不滿足。 2014/1/10 Q1 Q8 17
  • 18. 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 NPcomplete. • HAM-CYCLE ≤p Subgraph-Isomorphism Problem 2014/1/10 Q1 Q8 18
  • 19. 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 Q1 Q8 19
  • 20. Q7 • Given an integer m-by-n matrix A, and an integer mvector 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 Q1 Q8 20
  • 21. Q7 • Given an integer m-by-n matrix A, and an integer mvector 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 Q1 Q8 21
  • 22. 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 + x 3 + x 4 ≤ 1 1 • Ax ≤ b - 1 - 1 - 1 0 x -1 0 1 1 1 • 以此類推,可以在多項式時間內轉換,得證。 0-1 integer-programming problem is NPC. 2014/1/10 Q1 Q8 22
  • 23. 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 - A Show this problem is NP-complete. 2014/1/10 Q1 Q8 23
  • 24. Q8 • SUBSUM-SET(SOS) ≤p SET-PARTITION • 令 K = 一半即可 ? 未解決 2014/1/10 Q1 Q8 24
  • 25. Q10 • Show that the Hamiltonian path problem is NP-complete. • HAM-CYCLE ≤p HAM-PATH 2014/1/10 Q1 Q8 25
  • 26. Q10 • HAM-CYCLE ≤p HAM-PATH 2014/1/10 Q1 Q8 26
  • 27. Q10 • HAM-CYCLE ≤p HAM-PATH • 將其中一個點拆成兩個(入點、出點), 並且多增加兩個點連到入點和出點。 • 如果 HAM-PATH 存在,只要將這兩個 點合併再一起即可(合併成一條路) 2014/1/10 Q1 Q8 27