comp 382 - rice universitysc40/comp382/lectures/unit10.pdf · comp 382 unit 10: np-completeness....
TRANSCRIPT
![Page 1: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/1.jpg)
COMP 382Unit 10: NP-Completeness
![Page 2: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/2.jpg)
Time complexitynn
2n
n3
n2
nlog n
1
![Page 3: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/3.jpg)
Space complexitynn
2n
n3
n2
nlog n
1
![Page 4: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/4.jpg)
Complexity theory
Focus on decidability (yes/no) problems
![Page 5: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/5.jpg)
What is P?
Deterministic, Sequential, Polynomial Time
![Page 6: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/6.jpg)
Example problems in P
• Is 𝑥 a multiple of 𝑦?
• Is 𝑥 prime?
• Are 𝑥 and 𝑦 relatively prime?
• Is the edit distance between 𝑥 and 𝑦 less than 5?
• Is there a path between 𝑢 and 𝑣 of length less than 10?
Most problems mentioned so far in class.
![Page 7: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/7.jpg)
Understanding non-determinism:Guess & checkdefine SubsetSum(input: set of integer,
value: integer)
returns boolean
subset = Guess()
return sum(subset) == value
Two views of semantics:
• “Oracle” makes correct guesses
• Guess forks for all possibilities at once. Search succeeds if check succeeds for any guess.
![Page 8: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/8.jpg)
Understanding non-determinism:Given a certificate, check it
define SubsetSum_Certifier
(input: set of integer, value: integer,
witness: set of integer)
returns boolean
return subset(witness, input) &&
sum(witness) == value
Only needs to verify inputs on which SubetSum would return True.
Original inputs
Proof / Certificate / Witness
![Page 9: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/9.jpg)
Can simulate non-determinism
• Previously discussed ND TMs – non-deterministic choice of transition
• Simulate guess & check:• Generate all possible guesses one at a time
• Check
• Backtrack
![Page 10: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/10.jpg)
What is NP?
• Non-deterministic, Sequential, Polynomial Time• ND TM is polynomial time
• Check phase is polynomial time
• Includes all of P
• Includes lots not known to be in P
![Page 11: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/11.jpg)
Example problems in NP: SAT
Given a Boolean formula, is there a satisfying value assignment?𝑎 ∧ 𝑏 ∨ ¬ 𝑏 ∨ 𝑑 ∧ ¬𝑐 ∧ ¬𝑏 ∨ 𝑐
• Deterministic algorithm to solve?
• Deterministic algorithm to check? What is appropriate certificate?
![Page 12: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/12.jpg)
Example problems in NP: Directed Hamiltonian CycleGiven a directed graph, does it have a simple cycle through everyvertex?
• Deterministic algorithm to solve?
• Deterministic algorithm to check? What is appropriate certificate?
A
F
E
D
C
B
![Page 13: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/13.jpg)
Example Problems in NP: Composite
Given an integer, is it composite?
• Deterministic algorithm to solve?
• Deterministic algorithm to check? What is appropriate certificate?
![Page 14: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/14.jpg)
Many open questions
• L=P?
• P=BPP?
• P=NP?
• P=PSPACE?
• NP=co-NP?
• BPP=NEXP?
![Page 15: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/15.jpg)
If P=NP
• Many “hard” problems would actually be in P. We’d have a path to finding polynomial algorithms for them.
• Many other complexity open questions would be answered.
• Someone wins $1M from Clay Math. Institute and becomes famous.
If P = NP, then the world would be a profoundly different place than we usually assume it to be. There would be no special value in “creative leaps”, no fundamental gap between solving a problem and recognizing the solution once it's found. -- Scott Aaronson
![Page 16: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/16.jpg)
𝐴 reduces to 𝐵 in polynomial time: 𝐴 ≤𝑃 𝐵
Map instance of one problem to instance(s) of another in P-time.
Prove correctness: Problem A says “yes” exactly when this implementation of A says “yes”.
define A(args):
// Polynomial calls to subroutine B(), plus
// Polynomial other steps.
return …
![Page 17: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/17.jpg)
𝐴 reduces to 𝐵 in polynomial time: 𝐴 ≤𝑃 𝐵
Typical: Map instance of one problem to instance of another in P-time.
Prove correctness: Problem A says “yes” exactly when problem B says “yes” on its constructed inputs.
define A(a_args):
b_args = … // Polynomial steps.
return B(b_args)
![Page 18: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/18.jpg)
Using P-reductions: Which is true?
A. If 𝐵 ∈ 𝑃 and 𝐴 ≤𝑃 𝐵, then 𝐴 ∈ 𝑃.
B. If 𝐴 ∈ 𝑃 and 𝐴 ≤𝑃 𝐵, then 𝐵 ∈ 𝑃.
![Page 19: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/19.jpg)
Using P-reductions: Which is true?
A. If 𝐵 ∉ 𝑃 and 𝐴 ≤𝑃 𝐵, then 𝐴 ∉ 𝑃.
B. If 𝐴 ∉ 𝑃 and 𝐴 ≤𝑃 𝐵, then 𝐵 ∉ 𝑃.
![Page 20: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/20.jpg)
NP-Complete
A problem 𝑌 ∈ NP is NPC if for all problems 𝑋 in NP, 𝑋 ≤𝑃 𝑌.
Theorem: If Y is NPC, then 𝑌 ∈ 𝑃, iff P=NP.
Proof:
• () By assumption, 𝑌 ∈ NP. If P=NP, then 𝑌 ∈ P.
• () Suppose 𝑌 ∈ P. Let 𝑋 be any problem in NP. Since 𝑋 ≤𝑃 𝑌, then 𝑋 ∈ P. So, NPP. Since we already know PNP, then P=NP.
𝑌 is NP-Hard
![Page 21: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/21.jpg)
![Page 22: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/22.jpg)
First NPC problem – Circuit-SAT
Previously said the equivalent Boolean-formula version is in NP.
![Page 23: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/23.jpg)
First NPC problem – Circuit-SAT
For all problems 𝑋 in NP, 𝑋 ≤𝑃 Circuit−SAT:
𝑋 solvable by a ND TM in 𝑂 𝑓 𝑛 steps, where 𝑓 is polynomial.
Goal: Given input 𝑥, produce a circuit that is satisfiable iff 𝑥 ∈ 𝑋.
Circuit’s inputs:• Hardcoded 𝑥
• Unknown certificate c, of 𝑓 𝑥 bits
![Page 24: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/24.jpg)
First NPC problem – Circuit-SAT:Example constructed circuit
![Page 25: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/25.jpg)
General NPC Proof Strategy
• Show 𝑌 ∈ NP.
• Pick some NPC problem 𝑋.
• Prove 𝑋 ≤𝑃 𝑌.
In theory, the choice of 𝑋 is irrelevant.In practice, it is very important.
![Page 26: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/26.jpg)
3-CNF SAT is NPC
Given a Boolean formula in 3-CNF, is there a satisfying value assignment?
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑐 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑
In NP – Just a special case of SAT.
![Page 27: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/27.jpg)
Which do we need to show?
A. Circuit−SAT ≤𝑃 3−CNF−SAT
B. 3−CNF−SAT ≤𝑃 Circuit−SAT
![Page 28: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/28.jpg)
Circuit−SAT ≤𝑃 3−CNF−SAT
Given a circuit, construct an equivalent 3-CNF formula:1. Label wires.
2. Construct 3-CNF clauses for each gate.
3. AND all the pieces together.
𝑎
𝑏
𝑐
𝑐 = 𝑎 ∨ 𝑏≡
𝑎 ∨ 𝑏 ∨ 𝑐 ∧
𝑎 ∨ 𝑏 ∨ 𝑐 ∧
𝑎 ∨ 𝑏 ∨ 𝑐 ∧
𝑎 ∨ 𝑏 ∨ 𝑐
𝒂 𝒃 𝒄 𝒂 ∨ 𝒃 = 𝒄
F F F T
F F T F
F T F F
F T T T
T F F F
T F T T
T T F F
T T T T
![Page 29: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/29.jpg)
Independent set is NPC
Given an undirected graph and integer 𝑘, does the graph have a subset of 𝑘 vertices which are not adjacent to each other?
• Deterministic algorithm to check? What is appropriate certificate?
![Page 30: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/30.jpg)
3−CNF−SAT ≤𝑃 IndependentSet
Given 3-CNF formula, construct a graph with a 𝑘-independent set iffthe formula is satisfiable.
1. Form a triangle for each clause.
2. Link complementary nodes.
3. Let 𝑘 = the number of clauses.
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑏 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑 ∧ 𝑎 ∨ 𝑑 ∨ 𝑒
𝑎
𝑏 𝑐
𝑎
𝑏 𝑑
𝑏
𝑐 𝑑
𝑎
𝑑 𝑒
![Page 31: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/31.jpg)
Vertex cover is NPC
Given a graph and an integer 𝑘, is there a set 𝑆 of vertices, such that 𝑆 ≤ 𝑘 and every edge has an endpoint in 𝑆.
• Deterministic algorithm to check? What is appropriate certificate?
![Page 32: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/32.jpg)
IndependentSet ≤𝑃 VertexCover
Given graph 𝐺, use the same 𝐺.
Claim: 𝑆 is an independent set of 𝐺 iff 𝑉 ∖ 𝑆 is a vertex cover for 𝐺.
![Page 33: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/33.jpg)
IndependentSet ≤𝑃 VertexCover: Proof
Claim: 𝑆 is an independent set of 𝐺 iff 𝑉 ∖ 𝑆 is a vertex cover for 𝐺.
Let 𝑆 be any independent set.
Consider arbitrary edge 𝑢, 𝑣 .• 𝑢 ∉ 𝑆 or 𝑣 ∉ 𝑆
• 𝑢 ∈ 𝑉 ∖ 𝑆 or 𝑣 ∈ 𝑉 ∖ 𝑆
• 𝑉 ∖ 𝑆 covers 𝑢, 𝑣
![Page 34: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/34.jpg)
IndependentSet ≤𝑃 VertexCover: Proof
Claim: 𝑆 is an independent set of 𝐺 iff 𝑉 ∖ 𝑆 is a vertex cover for 𝐺.
Let 𝑉 ∖ 𝑆 be any vertex cover.
Consider arbitrary 𝑢 ∈ 𝑆 and 𝑣 ∈ 𝑆.• 𝑢, 𝑣 ∉ 𝐸
Thus, no two nodes in 𝑆 are linked by an edge.
So, 𝑆 is an independent set.
![Page 35: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/35.jpg)
Set cover is NPC
Given a set 𝑈 of elements, a collection of subsets of 𝑈, and an integer 𝑘, does there exist a collection of at most 𝑘 of these subsets whose union is 𝑈?
![Page 36: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/36.jpg)
Set cover example
𝑈 = 1,2,3,4,5,6,7 , 𝑘 = 2
• 𝑆1 = 3,7
• 𝑆2 = 3,4,5,6
• 𝑆3 = 1
• 𝑆4 = 2,4
• 𝑆5 = 5
• 𝑆6 = 1,2,6,7
What is a set cover?
![Page 37: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/37.jpg)
VertexCover ≤𝑃 SetCover
Given graph and 𝑘, construct 𝑈, a collection of subsets, and 𝑘′ that have a set cover iff the graph has a vertex cover.
• 𝑈 = 𝐸, Subsets = 𝑒 ∈ 𝐸: 𝑒 is incident to 𝑣 , 𝑘′ = 𝑘
𝑈 = 1,2,3,4,5,6,7 , 𝑘′ = 2
𝑆𝑎 = 3,7 , 𝑆𝑏 = 2,4𝑆𝑐 = 3,4,5,6 , 𝑆𝑑 = 5𝑆𝑒 = 1 , 𝑆𝑓 = 1,2,6,7
𝑎 𝑏
𝑒 𝑑
𝑓 𝑐
𝑒7𝑒3 𝑒2
𝑒6
𝑒4
𝑒1 𝑒5
![Page 38: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/38.jpg)
Directed Hamiltonian cycle is NPC
Given a directed graph, does it have a simple cycle through everyvertex?
Previously saw in NP.
A
F
E
D
C
B
![Page 39: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/39.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle
Given a 3-CNF formula, construct a directed graph that has a HamCycleiff the formula is satisfiable.
![Page 40: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/40.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle: Step 1
…
…
…
𝑥1
𝑥2
𝑥3
One per variable
2𝑛 Ham. cycles
![Page 41: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/41.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle: Step 2
One pair per clause
2𝑘 + 2 nodes
![Page 42: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/42.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle: Step 3
𝑥1
𝑥2
𝑥3
𝑥1 ∨ 𝑥2 ∨ 𝑥3One per clausePositive literal: left-to-right
Negative literal: right-to-left
![Page 43: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/43.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle: Proof
Claim: Formula is satisfiable iff graph has Hamiltonian cycle.
Suppose formula has satisfying assignment 𝑥∗.
Define Hamiltonian cycle:• If 𝑥𝑖
∗ = 1, traverse row 𝑖 from left to right.
• If 𝑥𝑖∗ = 0, traverse row 𝑖 from right to left.
For each clause 𝑗, there will be at least one row 𝑖 in which the cycle goes in the “correct” direction to splice clause node 𝑗 into the cycle.
![Page 44: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/44.jpg)
3−CNF−SAT ≤𝑃 DirHamCycle: Proof
Claim: Formula is satisfiable iff graph has Hamiltonian cycle.
Assume constructed graph 𝐺 has Hamiltonian cycle.
Cycle must traverse each row 𝑖.• Set 𝑥𝑖
∗ = 1 iff this cycle traverses row 𝑖 left to right.
Cycle must use each clause node 𝑗.• Must enter and leave via a pair of edges to/from same row.
• This pair of edges must go in same direction that cycle traverses the row.
• So each clause is satisfied by the truth assignment.
![Page 45: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/45.jpg)
3-Coloring is NPC
Given an undirected graph, does there exist a way of coloring the nodes with three colors, so that no two adjacent nodes have the same color?
• Deterministic algorithm to check? What is appropriate certificate?
![Page 46: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/46.jpg)
3−CNF−SAT ≤𝑃 3−Color
Given 3-CNF formula, create a graph that is 3-colorable iff the formula is satisfiable.
![Page 47: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/47.jpg)
3−CNF−SAT ≤𝑃 3−Color: Step 1
T F
B
…𝑥1 𝑥1 𝑥2 𝑥2 𝑥3 𝑥3 𝑥𝑛 𝑥𝑛
One pair per variable
Ensures each variable has one literal colored like T, one like F.
![Page 48: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/48.jpg)
3−CNF−SAT ≤𝑃 3−Color: Step 2
𝑥1 ∨ 𝑥2 ∨ 𝑥3
For each clause:
T F
B
𝑥1 𝑥2 𝑥3
Ensures each clause has at least one literal colored like T.
![Page 49: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/49.jpg)
3−CNF−SAT ≤𝑃 3−Color: Gadget cases 0T F
B
Not 3-colorable
![Page 50: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/50.jpg)
3−CNF−SAT ≤𝑃 3−Color: Gadget cases 1
T F
B
T F
B
T F
B
![Page 51: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/51.jpg)
3−CNF−SAT ≤𝑃 3−Color: Gadget cases 2
T F
B
T F
B
T F
B
T F
B
T F
B
T F
B
T F
B
T F
B
T F
B
![Page 52: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/52.jpg)
3−CNF−SAT ≤𝑃 3−Color: Gadget cases 3
T F
B
T F
B
T F
B
T F
B
![Page 53: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/53.jpg)
Subset sum is NPC
Given a set of natural numbers and a number 𝑆, is there a subset that adds up to 𝑆?
Note: Reduction must be polynomial in the encoding size.
• Deterministic algorithm to check? What is appropriate certificate?
𝑈 = −9,−2,3,6,7,8,12,35𝑆 = 16
![Page 54: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/54.jpg)
3−CNF−SAT ≤𝑃 SubsetSum
Given 3-CNF formula, create a set and total that has a subset sum iffthe formula is satisfiable.
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑏 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑
𝑎 𝑏 𝑐 𝒅 𝑪𝟏 𝑪𝟐 𝑪𝟑 Set:
𝒂 1 1 1 1,000,110
𝒂 1 1,000,000
𝒃 1 1 100,010
𝒃 1 1 1 100,101
𝒄 1 1 10,100
𝒄 1 1 10,001
𝒅 1 1 1,001
𝒅 1 1 1,010
1 100
2 200
1 10
2 20
1 1
2 2
𝑺 1 1 1 1 4 4 4 1,111,444
![Page 55: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/55.jpg)
3−CNF−SAT ≤𝑃 SubsetSum
Given 3-CNF formula, create a set and total that has a subset sum iffthe formula is satisfiable.
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑏 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑
𝑎 𝑏 𝑐 𝒅 𝑪𝟏 𝑪𝟐 𝑪𝟑 Set:
𝒂 1 1 1 1,000,110
𝒂 1 1,000,000
𝒃 1 1 100,010
𝒃 1 1 1 100,101
𝒄 1 1 10,100
𝒄 1 1 10,001
𝒅 1 1 1,001
𝒅 1 1 1,010
1 100
2 200
1 10
2 20
1 1
2 2
𝑺 1 1 1 1 4 4 4 1,111,444
Exactly one literal picked for each variable.Exactly one number of each pair picked for sum.
![Page 56: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/56.jpg)
3−CNF−SAT ≤𝑃 SubsetSum
Given 3-CNF formula, create a set and total that has a subset sum iffthe formula is satisfiable.
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑏 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑
𝑎 𝑏 𝑐 𝒅 𝑪𝟏 𝑪𝟐 𝑪𝟑 Set:
𝒂 1 1 1 1,000,110
𝒂 1 1,000,000
𝒃 1 1 100,010
𝒃 1 1 1 100,101
𝒄 1 1 10,100
𝒄 1 1 10,001
𝒅 1 1 1,001
𝒅 1 1 1,010
1 100
2 200
1 10
2 20
1 1
2 2
𝑺 1 1 1 1 4 4 4 1,111,444
Picking literal satisfies corresponding clauses.
![Page 57: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/57.jpg)
3−CNF−SAT ≤𝑃 SubsetSum
Given 3-CNF formula, create a set and total that has a subset sum iffthe formula is satisfiable.
𝑎 ∨ 𝑏 ∨ 𝑐 ∧ 𝑎 ∨ 𝑏 ∨ 𝑑 ∧ 𝑏 ∨ 𝑐 ∨ 𝑑
𝑎 𝑏 𝑐 𝒅 𝑪𝟏 𝑪𝟐 𝑪𝟑 Set:
𝒂 1 1 1 1,000,110
𝒂 1 1,000,000
𝒃 1 1 100,010
𝒃 1 1 1 100,101
𝒄 1 1 10,100
𝒄 1 1 10,001
𝒅 1 1 1,001
𝒅 1 1 1,010
1 100
2 200
1 10
2 20
1 1
2 2
𝑺 1 1 1 1 4 4 4 1,111,444
Must pick at least one row/number to satisfy each clause. 𝐶𝑖’s total from the top is 1, 2, or 3 – the bottom rows/numbers take up the slack but aren’t sufficient alone.
![Page 58: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/58.jpg)
Common Reduction Strategies
• Simple mapping/equivalence• IndependentSet ≤𝑃 VertexCover
• Special to general case• VertexCover ≤𝑃 SetCover
• Complicated encodings• Circuit−SAT ≤𝑃 3−CNF−SAT (general to special case)
• 3−CNF−SAT ≤𝑃 IndependentSet
• 3−CNF−SAT ≤𝑃 DirHamCycle
• 3−CNF−SAT ≤𝑃 3−Color
• 3−CNF−SAT ≤𝑃 SubsetSum
![Page 59: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/59.jpg)
![Page 60: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/60.jpg)
Exercise: Hitting set is NPC
Given a set 𝑈 of elements, a collection of subsets, and integer 𝑘, does there exist a subset of 𝑈 of size ≤ 𝑘 that overlaps with all the given subsets?
![Page 61: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/61.jpg)
Exercise: Efficient recruiting is NPC
Suppose you are helping organize a summer camp. The camp is supposed to have at least one counselor who is skilled at each of the 𝑛sports covered by the camp (baseball, volleyball, …).
They have received job applicants from 𝑚 potential counselors.
For each of the 𝑛 sports, there is a subset of the 𝑚 applicants qualified in that sport.
The question: For a given number 𝑘 < 𝑚, is it possible to hire at most 𝑘 counselors and have at least one counselor qualified in each sport?
![Page 62: COMP 382 - Rice Universitysc40/COMP382/Lectures/unit10.pdf · COMP 382 Unit 10: NP-Completeness. Time complexity nn 2n n3 n2 n log n 1. Space complexity nn 2n n3 n2 n log n 1. Complexity](https://reader034.vdocument.in/reader034/viewer/2022042711/5f7035928ec7264d4901b712/html5/thumbnails/62.jpg)
Exercise: Zero-weight cycle is NPC
Given a directed graph with weighted edges, is there a simple cycle of total weight 0?