Download presentation
Presentation is loading. Please wait.
1
Trevor Brown trevor.brown@uwaterloo.ca DC 2338, Office hour M3-4pm
CS 341: Algorithms Trevor Brown DC 2338, Office hour M3-4pm
2
This time Proving NP-completeness for several problems 3-SAT Clique
Vertex Cover Subset Sum (partially)
3
Polynomial transformation the most convenient definition
Recall from last time Let Π 1 and Π 2 be decision problems Π 1 ≤ 𝑃 Π 2 iff there exists 𝑓 :ℐ Π 1 →ℐ( Π 2 ) such that: 𝑓(𝐼) is computable in poly-time, for all 𝐼∈ℐ( Π 1 ) 𝐼∈ ℐ 𝑦𝑒𝑠 ( Π 1 ) iff 𝑓 𝐼 ∈ ℐ 𝑦𝑒𝑠 ( Π 2 )
4
Recall from last time 3-SAT 2-SAT
5
Reducing SAT to 3-SAT (Proving SAT ≤ 𝑃 3-SAT)
6
Is sat harder than 3-sat? Not really…
Recall from last time Let’s prove this is a polynomial transformation Complexity? Correctness?
10
Recall from last time: SAT is NP-complete
Every problem in NP reduces to reduces to Since SAT is NP-complete, so is 3-SAT! Let’s show 3-SAT also reduces to some other problem in NP… This will prove the other problem is NP-complete
11
Reducing 3-SAT to Clique
(Proving 3-SAT ≤ 𝑃 Clique)
12
Showing 3-SAT ≤ 𝑃 Clique Complexity? Correctness?
Let 𝐼 be an instance of 3-SAT with 𝑛 variables 𝑥 1 … 𝑥 𝑛 and 𝑚 clauses 𝐶 1 … 𝐶 𝑚 E.g., 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 2 ∨ 𝑥 3 ∨ 𝑥 5 ∧( 𝑥 3 ∨ 𝑥 4 ∨ 𝑥 5 ) [𝑛=5,𝑚=4] We construct Clique input 𝒇 𝑰 =(𝑮,𝒌) Node 𝑣 𝑡 𝑐 for each term 1≤𝑡≤3 in each clause 1≤𝑐≤𝑚 (so V =3𝑚) Edges between all non-contradictory pairs of nodes (no 𝑥 𝑖 ∧ 𝑥 𝑖 ) in different clauses 𝑘=𝑚 (sub-problem is to find an 𝒎-clique) Must prove this is a polynomial transformation 𝐶 1 : 𝑣 1 1 𝑥 1 𝑣 2 1 𝑥 2 𝑣 3 1 𝑥 3 𝐶 2 : 𝑣 1 2 𝑥 1 𝑣 2 2 𝑥 2 𝑣 3 2 𝑥 3 𝑣 1 3 𝑥 2 𝑣 2 3 𝑥 3 𝑣 3 3 𝑥 5 𝑣 1 4 𝑥 3 𝑣 2 3 𝑥 4 𝑣 3 3 𝑥 5 Complexity? Correctness?
13
Showing 3-SAT ≤ 𝑃 Clique Let 𝐼 be an instance of 3-SAT with 𝑛 variables 𝑥 1 … 𝑥 𝑛 and 𝑚 clauses 𝐶 1 … 𝐶 𝑚 E.g., 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 2 ∨ 𝑥 3 ∨ 𝑥 5 ∧( 𝑥 3 ∨ 𝑥 4 ∨ 𝑥 5 ) Case 1: Suppose 𝐼 is a yes-instance of 3-SAT, and show 𝒇 𝑰 is a yes-instance of 𝒎-clique Since 𝐼 is a yes-instance, ∃ a satisfying assignment E.g., 𝑥 1 =1, 𝑥 2 =1, 𝑥 3 =1, 𝑥 4 =1, 𝑥 5 =0 Select one true term 𝑻 𝒊 from each clause 𝑪 𝒊 E.g., 𝑇 1 = 𝑥 1 , 𝑇 2 = 𝑥 2 , 𝑇 3 = 𝑥 3 , 𝑇 4 = 𝑥 5 Claim: the corresponding nodes form an 𝒎-clique There are 𝑚 of these nodes, each in a different clause None of them have contradictory truth assignments So, there are edges between all pairs of them they form an 𝑚-clique 𝒗 𝟏 𝟏 𝑣 1 1 𝒙 𝟏 𝑥 1 𝑥 1 𝑣 2 1 𝑥 2 𝑣 3 1 𝑥 3 𝑣 1 2 𝑥 1 𝒗 𝟐 𝟐 𝑣 2 2 𝒙 𝟐 𝑥 2 𝑥 2 𝑣 3 2 𝑥 3 𝑣 1 3 𝑥 2 𝒗 𝟐 𝟑 𝑣 2 3 𝒙 𝟑 𝑥 3 𝑥 3 𝑣 3 3 𝑥 5 𝑣 1 4 𝑥 3 𝑣 2 3 𝑥 4 𝒗 𝟑 𝟑 𝑣 3 3 𝒙 𝟓 𝑥 5 𝑥 5
14
Showing 3-SAT ≤ 𝑃 Clique Let 𝐼 be an instance of 3-SAT with 𝑛 variables 𝑥 1 … 𝑥 𝑛 and 𝑚 clauses 𝐶 1 … 𝐶 𝑚 E.g., 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 1 ∨ 𝑥 2 ∨ 𝑥 3 ∧ 𝑥 2 ∨ 𝑥 3 ∨ 𝑥 5 ∧( 𝑥 3 ∨ 𝑥 4 ∨ 𝑥 5 ) Case 2: Suppose 𝒇(𝑰) is a yes-instance of 𝑚-clique, and show 𝐼 is a yes-instance of 3-SAT Since 𝑓(𝐼) is a yes-instance, it contains an 𝑚-clique Clique contains edges between all pairs of nodes There are no edges between nodes in same clause, so clique contains one node from each clause Set the corresponding terms to be true Clique contains no edges between contradictory terms (i.e., no edge connects 𝑥 𝑖 and 𝑥 𝑖 for any 𝑖) So, truth assignment is consistent and satisfies each clause (and the formula) 𝒗 𝟏 𝟏 𝑣 1 1 𝒙 𝟏 𝑥 1 𝑥 1 𝑣 2 1 𝑥 2 𝑣 3 1 𝑥 3 𝑣 1 2 𝑥 1 𝒗 𝟐 𝟐 𝑣 2 2 𝒙 𝟐 𝑥 2 𝑥 2 𝑣 3 2 𝑥 3 𝑣 1 3 𝑥 2 𝒗 𝟐 𝟑 𝑣 2 3 𝒙 𝟑 𝑥 3 𝑥 3 𝑣 3 3 𝑥 5 𝑣 1 4 𝑥 3 𝑣 2 3 𝑥 4 𝒗 𝟑 𝟑 𝑣 3 3 𝒙 𝟓 𝑥 5 𝑥 5
15
Every problem in NP reduces to reduces to
16
Recall: Vertex Cover problem
𝒌 2-vertex cover Can I find 𝒌 nodes that touch every edge in the graph?
17
This additional polynomial transformation was proved last class!
Every problem in NP reduces to reduces to This additional polynomial transformation was proved last class! Let’s reduce vertex cover to some other problem…
18
Reducing Vertex-Cover to Subset-Sum
(Proving Vertex-Cover ≤ 𝑃 Subset-Sum)
19
Subset-Sum (slightly different from before)
Earlier, we defined Subset-Sum with a target sum of 0 Here we generalize slightly to target sum T Goal: transform instance 𝐼 of VC into instance 𝑓 𝐼 of SS (in poly time) such that 𝐼 is a yes-instance of VC iff 𝑓(𝐼) is a yes-instance of SS Idea: turn nodes and edges into a list of “sizes” and a target sum. Target sum should be achievable IFF there is a k-vertex cover. Somehow want each node size to encode which edges are covered by the node, and target sum to encode that each edge is covered (by some node)
20
Give a unique size of 10 𝑗 to each edge 𝑒 𝑗
Input to Vertex Cover Sort of like an adjacency matrix, but instead of storing which node-pairs are adjacent, store which edges are incident to each node Why twice? If both endpoints of 𝑒 𝑗 are in the vertex cover, it is counted twice. Otherwise once, and can add 𝑏 𝑗 . Give a size to each node equal to ( 10 𝑚 + sizes of all edges incident to the node) This target weight asks for 𝒌 nodes and for all edges to be included twice Give a unique size of 10 𝑗 to each edge 𝑒 𝑗
21
Example Node 𝑣 2 is not incident to edge 𝑒 0 All 5 edges counted twice
Looking for 2 nodes All 5 edges counted twice Edge 𝑒 0 Edge 𝑒 1 Edge 𝑒 4 Node 𝑣 2 is incident to edge 𝑒 1 # encodes info about incident edges Node 𝑣 1 edge Is there a 2-VC? Use subset sum to search for 𝑊=𝟐22222 # looks the same as the incidence matrix! Node 𝑣 2 We find 𝑊= 𝒂 𝟐 + 𝒂 𝟑 + 𝑏 0 + 𝑏 1 + 𝑏 3 + 𝑏 4 node Sum of edge sizes incident to 𝑣 1 Vertex cover is 𝑉 ′ ={ 𝑣 2 , 𝑣 3 }. 𝑒 2 has both endpoints in 𝑉 ′ , so 𝑎 2 + 𝑎 3 contributes 𝟐×𝒔𝒊𝒛𝒆( 𝒆 𝟐 ) to 𝑊 Node 𝑣 5 = Note: no “carrying” can occur even if we sum everything explain one endpoint vs both endpoints in VC Every other edge 𝑒 ℓ has only one endpoint in 𝑉′, so 𝑎 2 + 𝑎 3 contributes only 𝟏×𝒔𝒊𝒛𝒆 𝒆 ℓ to 𝑊. So a second 𝑠𝑖𝑧𝑒( 𝑒 ℓ ) is added by 𝑏 ℓ (for each 𝑒 ℓ ). First digit of 𝑊 accurately captures # of nodes in the sum Other digits can be between 0 and 3. An edge is definitely covered if its digit is 2.
22
We stopped here
23
Case 1: Suppose 𝐼 is a yes-instance of Vertex-Cover.
one endpoint in 𝑉 ′ both endpoints in 𝑉 ′ Contains edge sizes Contains node sizes 𝑒 𝑗 has one endpoint in 𝑉 ′ , so nodes in 𝑉 ′ contribute 𝟏×𝒔𝒊𝒛𝒆( 𝒆 𝒋 ) to 𝑊 𝑒 𝑗 has both endpoints in 𝑉 ′ , so nodes in 𝑉 ′ contribute 𝟐×𝒔𝒊𝒛𝒆( 𝒆 𝒋 ) to 𝑊 Add another 𝟏×𝒔𝒊𝒛𝒆( 𝒆 𝒋 ) to 𝑊 for each 𝑒 𝑗 with one endpoint in 𝑉 ′ In future it would be nice to rename A’ -> N’, B’ -> E’, or *something* more memorable than A and B. something that encodes the fact that A’ contains node sizes, and B’ contains edge sizes. To get 2×𝑠𝑖𝑧𝑒( 𝑒 𝑗 ) for all 𝑒 𝑗 , plus 10 𝑚 for each node
24
Case 2: Suppose 𝑓(𝐼) is a yes-instance of Subset Sum.
We show 𝐼 is a yes-instance of Vertex-Cover Since 𝑓(𝐼) is a yes-instance, there exists 𝐴 ′ ∪ 𝐵 ′ that sums to 𝑊 where 𝐴′ contains node sizes and 𝐵′ contains edge sizes Define 𝑉 ′ = 𝑣 𝑖 : 𝑎 𝑖 ∈ 𝐴 ′ . We claim 𝑉′ is a vertex cover of size 𝑘. We must have 𝑉 ′ =𝑘 to get the coefficient of 10 𝑚 to be 𝑘 The coefficient of every other term 10 𝑗 (𝑗≤𝑚−1) must be 2 Suppose (for contra.) 𝑉′ does not cover some edge 𝑒 𝑗 =(𝑢,𝑣) Then the coefficient of 10 𝑗 is zero for every 𝑎 𝑖 ∈ 𝐴 ′ But the coefficient of 10 𝑗 is 2, so a subset of 𝐵′ must sum to 2× 10 𝑗 But this is impossible (so 𝑒 𝑗 is covered, so all edges are covered)
25
Complexity of the transformation
Assume adjacency matrix and unit cost model for simplicity Complexity of the transformation Compute 𝐶 with trivial algorithm in 𝑂(𝑛𝑚) time Compute 𝑎 𝑖 by visiting all incident edges. Trivial algorithm yields 𝑂(𝑚) time for each 𝑎 𝑖 , totaling 𝑂(𝑛+𝑚) over all 𝑖 Trivial to compute all 𝑏 𝑗 in 𝑂(𝑚) time Trivial to compute 𝑊 in 𝑂(𝑚) time Total 𝑂(𝑛𝑚) time. This is polynomial in the input graph size!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.