[SOLVED] CS代考程序代写 compiler database algorithm Lecture 11:

30 $

File Name: CS代考程序代写_compiler_database_algorithm_Lecture_11:.zip
File Size: 565.2 KB

SKU: 9407770167 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Lecture 11:
NP and Computational Intractability
The University of Sydney
Page 1

Outline of today’s lecture
• Reduction: polynomial time
• Reduction by simple equivalence.
• Reduction from special case to general case.
• Reduction by encoding with gadgets.
• Definition of P and NP • NP-completeness
The University of Sydney
Page 3

8.1 Polynomial-Time Reductions
The University of Sydney Page 4

Polynomial-Time Reduction
Reduction. Problem X polynomial reduces to problem Y, denoted X £ P Y, if arbitrary instances of problem X can be solved using:
– Polynomial number of standard computational steps, plus
– Polynomial number of calls to an oracle/black box that solves problem Y.
A reduction from X to Y is an algorithm for X of the following form:
Algorithm for X
f(I)
Instance Solution of Y for f(I)
Transform instance of X to instance of Y
Algorithm for Y
Transform solution for Y to a solution for X
Instance of X
I
Illustration: single call of black box The University of Sydney
Solution for I
Page 8

Polynomial-Time Reduction
Purpose. Classify problems according to relative difficulty.
1. Design algorithms. If X £ P Y and Y can be solved in polynomial-time, then X can also be solved in polynomial time.
2. Establish intractability. If X £ P Y and X cannot be solved in polynomial-time, then Y cannot be solved in polynomial time.
Transitivity: If X £P Y and Y £P Z, then X £P Z. Equivalence: IfX£P YandY£P X,thenXoPY.
The University of Sydney Page 20

Decision vs Optimization vs Search
Decision problem:
Does there exist an object satisfying some given properties? Output: Yes/No.
Example: Is there a path from s to t?
Optimization problem:
What is the size of the biggest/smallest such object? Output: Number.
Example: What is the length of the shortest s-t path?
Search problem:
Find a biggest/smallest such object
Output: Object.
Example: Find a shortest s-t path. The University of Sydney
Page 21

Decision o P Optimization o P Search
This holds true in general, not just for bipartite matching.
This justifies focusing on decision problems which are easier to construct and analyze reductions for.
The University of Sydney Page 22

Reduction Template for Decision Problems (aka Karp reduction)
Algorithm for X
Instance of Y
f(I)
Yes for f(I) No for f(I)
Transforms instance of X to instance of Y
Algorithm for Y
Instance of X
I
Yes for I No for I
Step 2
Step 1
Step 1: Construct a polynomial-time algorithm that transforms instance I of X to an instance f(I) of Y
Step 2: Prove correctness, which boils down to showing
Answer for I is Yes iff answer for f(I) is Yes
Note: Reduction is one-way but proof needs equivalence The University of Sydney
Page 23

Reduction Strategies
The University of Sydney
Page 24
1. Reduction by simple equivalence. (VC and IS)
2. Reduction from special case to general case.
3. Reduction by encoding with gadgets.

Independent Set
INDEPENDENT-SET: Given a graph G = (V, E) and an integer k, is there a subset of vertices S Í V such that |S| 3 k, and for each edge at most one of its endpoints is in S?
independent set
The University of Sydney Page 25

Vertex Cover
VERTEX-COVER: Given a graph G = (V, E) and an integer k, is there a subset of vertices S Í V such that |S| £ k, and for each edge, at least one of its endpoints is in S?
vertex cover
The University of Sydney
Page 26

Reduction Strategies
The University of Sydney
Page 27
1. Reduction by simple equivalence.
2. Reduction from special case to general case.
3. Reduction by encoding with gadgets.

Set Cover
SET-COVER: Given a set U of elements, a collection S1, S2, . . . , Sm of subsets of U, and an integer k, does there exist a collection of k of these sets whose union is equal to U?
Sample application.
– m available pieces of software.
– Set U of n capabilities that we would like our system to have.
– The ith piece of software provides the set Si Í U of capabilities. – Goal: achieve all n capabilities using fewest pieces of software.
Example:
U = { 1, 2, 3, 4, 5, 6, 7 } k=2
S1 ={3,7}
S2 ={3,4,5,6} S3 ={1}
S4 ={2,4}
S5 ={5}
S6 = {1,2,6,7}
The University of Sydney
Page 28

Set Cover
SET-COVER: Given a set U of elements, a collection S1, S2, . . . , Sm of subsets of U, and an integer k, does there exist a collection of k of these sets whose union is equal to U?
Sample application.
– m available pieces of software.
– Set U of n capabilities that we would like our system to have.
– The ith piece of software provides the set Si Í U of capabilities. – Goal: achieve all n capabilities using fewest pieces of software.
Example:
U = { 1, 2, 3, 4, 5, 6, 7 } k=2
S1 ={3,7}
S2 ={3,4,5,6}
S3 ={1}
S4 ={2,4}
S5 ={5}
S6 = {1,2,6,7}
The University of Sydney
Page 29

Vertex Cover Reduces to Set Cover
Theorem: VERTEX-COVER £P SET-COVER.
Proof: Given a VERTEX-COVER instance G = (V, E), k, we construct a set cover
instance whose size equals the size of the vertex cover instance.
Construction.
– Create SET-COVER instance:
• k=k, U=E, Sv ={eÎE:eincidenttov}
– Set-cover of size £ k iff vertex cover of size £ k. ▪
VERTEX COVER
ab
e7 e2 e3 e4
f e6 c
k=2
e1
e5
ed
The University of Sydney
Page 30

Vertex Cover Reduces to Set Cover
Theorem: VERTEX-COVER £P SET-COVER.
Proof: Given a VERTEX-COVER instance G = (V, E), k, we construct a set cover
instance whose size equals the size of the vertex cover instance.
Construction.
– Create SET-COVER instance:
• k=k, U=E, Sv ={eÎE:eincidenttov}
– Set-cover of size £ k iff vertex cover of size £ k. ▪
VERTEX COVER
ab
e7 e2 e3 e4
f e6 c
k=2
e1
e5
ed
SET COVER
U = { 1, 2, 3, 4, 5, 6, 7 }
k=2
Sa = {3, 7}
Sc = {3, 4, 5, 6} Se = {1}
Sb = {2, 4}
Sd = {5}
Sf= {1, 2, 6, 7}
The University of Sydney
Page 31

Vertex Cover Reduces to Set Cover
Theorem: VERTEX-COVER £P SET-COVER.
Proof: Given a VERTEX-COVER instance G = (V, E), k, we construct a set cover
instance whose size equals the size of the vertex cover instance.
Construction.
– Create SET-COVER instance:
• k=k, U=E, Sv ={eÎE:eincidenttov}
– Set-cover of size £ k iff vertex cover of size £ k. ▪
VERTEX COVER
ab
e7 e2 e3 e4
f e6 c
k=2
e1
e5
ed
SET COVER
U = { 1, 2, 3, 4, 5, 6, 7 }
k=2
Sa = {3, 7}
Sc = {3, 4, 5, 6} Se = {1}
Sb = {2, 4}
Sd = {5}
Sf= {1, 2, 6, 7}
The University of Sydney
Page 32

Reduction Strategies
The University of Sydney
Page 33
1. Reduction by simple equivalence.
2. Reduction from special case to general case.
3. Reduction by encoding with gadgets.

Satisfiability
Literal: A Boolean variable or its negation. Clause: A disjunction of literals.
Conjunctive normal form (CNF): A propositional formula F that is the conjunction of clauses.
xi or xi
Cj = x1 Ú x2 Ú x3
F= C1ÙC2ÙC3ÙC4 SAT: Given CNF formula F, does it have a satisfying truth assignment?
3-SAT: SAT where each clause contains exactly 3 literals.
(xÚx Úx )Ù(xÚx Úx )Ù(x Úx Úx )Ù(xÚx Úx ) 123123123123
Ex:
Yes: x1 = true, x2 = true x3 = false.
The University of Sydney Page 34

3 Satisfiability Reduces to Independent Set
Theorem: 3-SAT £P INDEPENDENT-SET.
INDEPENDENT-SET: Given a graph G = (V, E) and an integer k, is there a subset of vertices S Í V such that |S| 3 k, and for each edge at most one of its endpoints is in S?
The University of Sydney Page 35

3 Satisfiability Reduces to Independent Set
Theorem: 3-SAT £P INDEPENDENT-SET.
Proof: Given an instance F of 3-SAT, we construct an instance (G, k) of
INDEPENDENT-SET that has an independent set of size k iff F is satisfiable.
The University of Sydney Page 36

3 Satisfiability Reduces to Independent Set
Theorem: 3-SAT £P INDEPENDENT-SET.
Proof: Given an instance F of 3-SAT, we construct an instance (G, k) of
INDEPENDENT-SET that has an independent set of size k iff F is satisfiable. Construction.
– G contains 3 vertices for each of the k clauses, one for each literal. – Connect 3 literals in a clause in a triangle.
– Connect literal to each of its negations.
(G, k = 3)
x1 x2 x1
The University of Sydney
x2 x3 x1 x3 x2 x4 F = (x1 Ú x2 Ú x3)Ù (x1 Ú x2 Ú x3) Ù (x1 Ú x2 Ú x4)
Page 37

3 Satisfiability Reduces to Independent Set
Claim. G contains independent set of size k = |F| iff F is satisfiable.
Proof: Þ Let S be independent set of size k.
– S must contain exactly one vertex in each triangle.
– Set these literals to true.
– Truth assignment is consistent and all clauses are satisfied.
Proof: Ü Given satisfying assignment, select one true literal from each triangle. This is an independent set of size k. ▪
(G, k = 3)
x1 x2 x1
The University of Sydney
x2 x3 x1 x3 x2 x4 F = (x1 Ú x2 Ú x3)Ù (x1 Ú x2 Ú x3) Ù (x1 Ú x2 Ú x4)
Page 38

3 Satisfiability Reduces to Independent Set
Claim. G contains independent set of size k = |F| iff F is satisfiable.
Proof: Þ Let S be independent set of size k.
– S must contain exactly one vertex in each triangle.
– Set these literals to true.
– Truth assignment is consistent and all clauses are satisfied.
Proof: Ü Given satisfying assignment, select one true literal from each triangle. This is an independent set of size k. ▪
(G, k = 3)
x1 x2 x1
The University of Sydney
x2 x3 x1 x3 x2 x4 F = (x1 Ú x2 Ú x3)Ù (x1 Ú x2 Ú x3) Ù (x1 Ú x2 Ú x4)
Page 39

Clique
A clique of a graph G is a complete subgraph of G.
clique of size 4
clique of size 3
CLIQUE: Given a graph G=(V,E) and an integer k, does G=(V,E) contain a clique of size ≥ k?
The University of Sydney Page 40

3 Satisfiability Reduces to Clique
Theorem: 3-SAT £P CLIQUE.
Idea:
– Make “column” for each of the k clauses.
– No edge within a column.
– All other edges present except between x and x.
The University of Sydney
Page 41

3 Satisfiability Reduces to Clique
Example:
G=
E = (x Ú y Ú z) Ù (x Ú y Ú z) Ù ( y Ú z)
x y
z
x
y
z
y
z
Observation: G has a k-clique, if and only if E is satisfiable. Observation: G is the edge complement of the reduction from 3-SAT to IS
The University of Sydney Page 42

Review
Basic reduction strategies.
– Simple equivalence: INDEPENDENT-SET oP VERTEX-COVER.
– Special case to general case: VERTEX-COVER £P SET-COVER. – Encoding with gadgets: 3-SAT £P INDEPENDENT-SET.
3-SAT £P CLIQUE Transitivity. If X £P Y and Y £P Z, then X £P Z.
Proof idea: Compose the two algorithms.
Example: 3-SAT £P INDEPENDENT-SET £P VERTEX-COVER £P SET-COVER.
The University of Sydney
Page 43

8.3 Definition of NP
• Class P
• Class NP
• Class NP-complete
The University of Sydney
Page 44

Definition of the class P
Class P: Decision problems for which there is a deterministic poly-time algorithm.
Problem
Description
Algorithm
Yes
No
MULTIPLE
Is x a multiple of y?
Grade school division
51, 17
51, 16
RELPRIME
Are x and y relatively prime?
Euclid (300 BCE)
34, 39
34, 51
PRIMES
Is x prime?
AKS (2002)
53
51
RNA secondary structure
Is there an RNA secondary structure of weight at most 3?
Dynamic programming
accgguagu
aaaaggggg
MST
Is there a MST of weight at most 5?
Prim’s
The University of Sydney Page 45

Definition of the class NP
Class NP: Decision problems for which YES-instances have a poly-time certifier.
Certification algorithm intuition.
– Certifier views things from “managerial” viewpoint.
– Certifier does not solve the problem by its own;
rather, it checks if a proposed proof t is a valid solution.
Definition: Algorithm C(s,t) is a certifier for problem X if for every input instance s and proposed proof t, C(s, t) = `yes’ if and only if t is a valid solution to s.
“certificate” or “witness”
The University of Sydney
Page 46

Certifiers and Certificates: Set Cover
SET-COVER: Given a set U of elements, a collection S1, S2, . . . , Sm of subsets of U, and an integer k, does there exist a collection of k of these sets whose union is equal to U?
Certificate: t={Si1, Si2, …, Sik} Certifier:
boolean C(s,t) {
if the number of sets > k
return false elseif(“vÎU:v Î asetint)
return true
else
return false}
Example: U={1,2,3,4}, S1={1}, S2={2,3}, S3={1,4} and k=2 certificate t={S2,S3}
Conclusion: SET-COVER is in NP. The University of Sydney
Page 47

Certifiers and Certificates: 3-Satisfiability
SAT: Given a CNF formula F, is there a satisfying assignment? Certificate: An assignment of truth values to the n boolean variables. Certifier: Check that each clause in F has at least one true literal.
(x1 Úx2 Úx3)Ù(x1 Úx2 Úx3)Ù(x1 Úx2 Úx4)Ù(x1 Úx3 Úx4) instance s
Conclusion: SAT is in NP. The University of Sydney
Page 48
x1,x2,x4=true, x3=false certificate t

Certifiers and Certificates: Hamiltonian Cycle
HAM-CYCLE: Given an undirected graph G = (V, E), does there exist a simple cycle C that visits every node?
Certificate: t = a permutation of the n nodes.
Certifier: Check that the permutation contains each node in V exactly once, and that there is an edge between each pair of adjacent nodes in the permutation.
Conclusion: HAM-CYCLE is in NP.
instance s certificate t
The University of Sydney Page 49

P, NP
P: Decision problems for which there is a poly-time algorithm.
NP: Decision problems for which YES-instances have a poly-time certifier.
Claim: P Í NP.
The University of Sydney Page 51

P, NP, EXP
P: Decision problems for which there is a poly-time algorithm.
NP: Decision problems for which there is a poly-time certifier.
EXP: Decision problems for which there is an exponential-time algorithm.
Claim: P Í NP. Claim: NP Í EXP.
The University of Sydney Page 52

The Main Question: P Versus NP
Is P = NP? [Cook 1971, Edmonds, Levin, Yablonski, Gödel]
– Isthesearchproblemaseasyasthecertificationproblem?
– OneofthesevenMillenniumPrizeproblems:$1millionprizeifsolved.
EXP
P NP
EXP
P = NP
If P=NP
P 1 NP: No efficient algorithms possible for 3-COLOR, TSP, SAT, … Consensus opinion on P = NP? Probably no.
Intuition: Appreciating good music is vastly easier than making it. The University of Sydney
If P1NP
P=NP: Efficient algorithms for 3-COLOR, TSP, FACTOR, SAT, …
would break RSA cryptography
Page 53

The Simpson’s: P = NP?
The University of Sydney
Page 54
Copyright © 1990, Matt Groening

8.4 NP-Completeness
The University of Sydney Page 55

Polynomial Transformation
Definition: Problem X polynomial reduces (Cook) to problem Y if arbitrary instances of problem X can be solved using:
– Polynomialnumberofstandardcomputationalsteps,plus – PolynomialnumberofcallstooraclethatsolvesproblemY.
Definition: Problem X polynomial transforms (Karp) to problem Y if given any input x to X, we can construct an input y such that x is a yes instance of X iff y is a yes instance of Y.
Note. Polynomial transformation is polynomial reduction with just one call to oracle for Y, exactly at the end of the algorithm for X. Almost all previous reductions were of this form.
Open question. Are these two concepts the same?
we abuse notation £ p and blur distinction
The University of Sydney
Page 56

Class NP-Complete
NP-complete: A problem Y in NP with the property that for every problem X in NP, X£ pY.
Theorem: Suppose Y is an NP-complete problem. Then Y is solvable in poly-time iff P = NP.
Proof:
Ü If P = NP then Y can be solved in poly-time since Y is in NP=P. Þ Suppose Y can be solved in poly-time.
– LetXbeanyprobleminNP. SinceX£p Y,wecansolveXin poly-time. This implies NP Í P.
– WealreadyknowP Í NP.ThusP=NP. ▪
The University of Sydney
Page 57

Circuit Satisfiability
CIRCUIT-SAT. Given a combinational circuit built out of AND, OR, and NOT gates, is there a way to set the circuit inputs so that the output is 1?
output
Ù ¬Ù
ÙÚÚ
CIRCUIT-SAT Î NP
Yes: 101
The University of Sydney
Page 58
10??? hard-coded inputs inputs

The Mother of NP-Complete Problems
Theorem: CIRCUIT-SAT is NP-complete. [Cook 1971, Levin 1973] Proof: (main idea)
– Any algorithm that takes a fixed number of bits n as input and produces a yes/no answer can be represented by such a circuit. Moreover, if algorithm takes poly-time, then circuit is of poly-size.
– Represent certifier as a circuit whose input is proposed proof
– YES-instances are those for which there exists a proof that makes the
circuit output 1.
Proof not part of the course.
The University of Sydney Page 59

Example
Construction below creates a circuit K whose inputs can be set so that K outputs true iff graph G has an independent set of size 2.
Ù independent set of size 2?
independent set? ¬
both endpoints of some edge have been chosen?
Ú Ú
ÙÙÙ
Ú Ú
ÙÙÙ
æ n ö hard-coded inputs (graph description) n inputs (nodes in independent sPeatg)e 60 çè 2 ÷ø
set of size 2?
u
vw
G = (V,E) The University of Sydney
uvw
u-v u-w v-w 101???

Establishing NP-Completeness
Remark: Once we establish first “natural” NP-complete problem, others fall like dominoes.
Recipe to establish NP-completeness of problem Y. – Step1. ShowthatYisinNP.
– Step 2. Choose an NP-complete problem X. – Step 3. Prove that X £ p Y.
Justification: If X is an NP-complete problem, and Y is a problem in NP with the property that X £ P Y then Y is NP-complete.
Proof: LetWbeanyprobleminNP. ThenW £P X £P Y. – Bytransitivity,W£P Y.
– Hence Y is NP-complete. ▪ The University of Sydney
by definition of NP-complete
by assumption
Page 61

3-SAT is NP-Complete
Theorem. 3-SAT is NP-complete.
Proof: Suffices to show that CIRCUIT-SAT £ P 3-SAT since 3-SAT is in NP.
– Let K be any circuit.
– Create a 3-SAT variable xi for each circuit element i.
– Make circuit compute correct values at each node:
•x2=¬x3 Þadd2clauses: x2Úx3 , x2Úx3
• x1 =x4 Úx5 Þ add3clauses: x1Úx4, x1Úx5 , x1Úx4 Ú x5
•x0=x1Ùx2 Þadd3clauses: x0Úx1, x0Úx2,x0Úx1Úx2
– Hard-coded input values and output value. • x5 =0 Þ add1clause: x5
• x0 =1 Þ add1clause: x0
– Final step: turn clauses of length < 3 into clauses of length exactly 3. ▪outputx0 Ù Ú¬ x1x2 x5 x4x3The University of SydneyPage 620?? Using transitivity• 3-SAT is NP-complete• 3-SAT £P INDEPENDENT-SET £P VERTEX-COVER £P SET-COVERCorollary:INDEPENDENT-SET, VERTEX-COVER and SET-COVER are NP-complete.The University of SydneyPage 63 NP-CompletenessAll problems below are NP-complete and polynomial reduce to one another!CIRCUIT-SAT3-SATby definition of NP-completeness INDEPENDENT SETVERTEX COVERDIR-HAM-CYCLEHAM-CYCLEGRAPH 3-COLORPLANAR 3-COLORSUBSET-SUMSCHEDULINGThe University of SydneyPage 64SET COVERTSP3-SAT reduces to INDEPENDENT SET Some NP-Complete ProblemsSix basic genres of NP-complete problems and paradigmatic examples.– Constraint satisfaction problems: SAT, 3-SAT.– Packing problems: SET-PACKING, INDEPENDENT SET. – Covering problems: SET-COVER, VERTEX-COVER.– Sequencing problems: HAMILTONIAN-CYCLE, TSP. – Partitioning problems: 3D-MATCHING 3-COLOR.– Numerical problems: SUBSET-SUM, KNAPSACK.The University of SydneyPage 65 Extent and Impact of NP-Completeness– Extent of NP-completeness. [Papadimitriou 1995] – Prime intellectual export of CS to other disciplines.– 6,000 citations per year (title, abstract, keywords).• more than “compiler”, “operating system”, “database” – Broad applicability and classification power.The University of SydneyPage 66 More NP-Hard Computational Problems– Aerospace engineering: optimal mesh partitioning for finite elements.– Biology: protein folding.– Chemical engineering: heat exchanger network synthesis.– Civil engineering: equilibrium of urban traffic flow.– Economics: computation of arbitrage in financial markets with friction.– Electrical engineering: VLSI layout.– Environmental engineering: optimal placement of contaminant sensors.– Financial engineering: find minimum risk portfolio of given return.– Game theory: find Nash equilibrium that maximizes social welfare.– Genomics: phylogeny reconstruction.– Mechanical engineering: structure of turbulence in sheared flows.– Medicine: reconstructing 3-D shape from biplane angiocardiogram.– Operations research: optimal resource allocation.– Physics: partition function of 3-D Ising model in statistical mechanics.– Politics: Shapley-Shubik voting power.– Pop culture: Minesweeper consistency.– Statistics: optimal experimental design.The University of SydneyPage 67 GamesThe Eternity II puzzle, is a puzzle competition which was released in 2007.A $2 million prize was offered for the first complete solution.The Eternity II puzzle is an edge-matching puzzle which involves placing 256 square puzzle pieces into a 16 by 16 grid, constrained by the requirement to match adjacent edges.The problem is NP-complete.The competition ended at noon on 31 December 2010, with no solution being found. The University of SydneyPage 68 Class NP-hardClass NP-complete: A problem in NP such that every problem in NP polynomial reduces to it.Class NP-hard:A decision problem such that every problem in NP reduces to it. not necessarily in NP The University of Sydney Page 69 Many classes?https://complexityzoo.uwaterloo.ca/Complexity_Zoo The University of Sydney Page 70Taxonomy of NP-Complete Problems Six Basic genres§ Constraint satisfaction problems: SAT, 3-SAT.§ Packing problems: SET-PACKING, INDEPENDENT SET. § Covering problems: SET-COVER, VERTEX-COVER.§ Sequencing problems: HAMILTONIAN-CYCLE, TSP.3-SAT £P DIR HAMILTONIAN CYCLE £P HAMILTONIAN CYCLE £P TSP § Partitioning problems: 3D-MATCHING, 3-COLOR.§ Numerical problems: SUBSET-SUM, KNAPSACK. The University of SydneyPage 71Subset-SumGiven a set S of n integers v1, …, vn, and a target value t, is there a subset of S that sum to exactly t?Example: 3, 6, 7, 2, 4, 3, t = 10. YesThe University of Sydney Page 72 Vertex Cover Reduces to Subset SumTheorem: VERTEX-COVER £P SUBSET-SUM.Proof: Given an instance (G, k) of VERTEX-COVER, construct an instance (S, t) of SUBSET-SUM that has a subset of S summing to t iff G has a vertex cover of size at least k.The University of Sydney Page 73 Vertex Cover Reduces to Subset SumProof: Given an instance (G, k) of VERTEX-COVER, construct an instance (S, t) of SUBSET-SUM that has a subset of S summing to t iff G has a vertex cover of size at least k.Number edges from 1 to |E|. Set S of integers:– For the i-th edge, add an integer bi– For each vertex v, add an integer avbi = 4iav = 4|E| + X 4ii:i-th edge is incident to v |EX|1t = k · 4|E| + 2 · 4i The University of Sydney i=0Page 75 Vertex Cover Reduces to Subset SumProof: Given an instance (G, k) of VERTEX-COVER, construct an instance (S, t) of SUBSET-SUM that has a subset of S summing to t iff G has a vertex cover ofsize at least k.Number edges from 0 to |E|-1. Set S of integers:– For the i-th edge, add an integer bi– For each vertex v, add an integer avbi = 4iav = 4|E| + X 4i0 xyz1 t = k · 4|E| +The University of Sydney i=02 · 4iPage 76i:i-th edge is incident to vaz = 1104 ay = 1114ax = 1014|EX|1t = 1224k=1b0 = 0014b1 = 0104 Vertex Cover Reduces to Subset SumClaim: G has vertex cover of size at most k iff (S, t) has a subset summing to t. Proof: Þ Let C be a vertex cover of size exactly k.– Consider the subset of SX={av :v2C}[{bi :edgeiiscoveredbyexactlyonevertexinC}– The most significant digit is exactly k – The i-th digit is exactly 2.– Therefore sum of X is exactly tbi = 4iav = 4|E| + X 4ii:i-th edge is incident to v |EX|1t = k · 4|E| + 2 · 4i The University of Sydney i=0Page 77Vertex Cover Reduces to Subset SumClaim: G has vertex cover of size at most k iff (S, t) has a subset summing to t. Proof: Ü Let X be a subset of S summing to t– Then there exists subsets V’ and E’ such thatX av + X bi = k · 4|E| + X 2 · 4i|E|1 v2V 0 i2E0 i=0– No carries in the first |E| digits– Each edge number bi contributes at most 1 to the i-th digit of the sum – So, at least one of its endpoints must be in V’– Thus, V’ is a vertex coverbi = 4iav = 4|E| + X 4i i:i-th edge is incident to vThe University of SydneyPage 788.5 Sequencing Problems Six Basic genres§ Packing problems: SET-PACKING, INDEPENDENT SET. § Covering problems: SET-COVER, VERTEX-COVER.§ Constraint satisfaction problems: SAT, 3-SAT.§ Sequencing problems: HAMILTONIAN-CYCLE, TSP.3-SAT £P DIR HAMILTONIAN CYCLE £P HAMILTONIAN CYCLE £P TSP § Partitioning problems: 3D-MATCHING, 3-COLOR.§ Numerical problems: SUBSET-SUM, KNAPSACK. The University of SydneyPage 79Hamiltonian CycleHAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle G that contains every node in V. The University of Sydney YES: vertices and faces of a dodecahedron. Page 80 Hamiltonian CycleHAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle G that contains every node in V.The University of Sydney1 1’2 2’3 3’4 4’5NO: bipartite graph with odd number of nodes.Page 81 Directed Hamiltonian CycleDIR-HAM-CYCLE: Given a directed graph G = (V, E), does there exists a simple directed cycle G that contains every node in V?Theorem: DIR-HAM-CYCLE £ P HAM-CYCLE.Proof idea: Given a directed graph G = (V, E), construct an undirected graphG’ with 3n vertices.abv cGaout ddinein ebout coutvin v voutG’ The University of SydneyPage 82 Directed Hamiltonian CycleClaim: G has a Hamiltonian cycle iff G’ does.Proof:Þ –– Then G’ has an undirected Hamiltonian cycle (same order).Suppose G has a directed Hamiltonian cycle G.Ü –– G’ must visit nodes in G’ using one of two orders:Suppose G’ has an undirected Hamiltonian cycle G’…., B, G, R, B, G, R, B, G, R, B, ……, B, R, G, B, R, G, B, R, G, B, …– Blue nodes in G’ make up directed Hamiltonian cycle G in G, or reverseof one. ▪ aoutbout vin coutdineind dout v vout G’The University of SydneyPage 83 3-SAT Reduces to Directed Hamiltonian CycleTheorem: 3-SAT £ P DIR-HAM-CYCLE.Proof: Given an instance F of 3-SAT, we construct an instance of DIR-HAM-CYCLE that has a Hamiltonian cycle iff F is satisfiable.Construction. First, create graph that has 2n Hamiltonian cycles whichcorrespond in a natural way to 2n possible truth assignments.The University of SydneyPage 84 3-SAT Reduces to Directed Hamiltonian CycleConstruction: Given a 3-SAT instance F with n variables xi and k clauses. – Construct G to have 2n Hamiltonian cycles.– Intuition: Traverse path i from left to right Û set variable xi = 1.s x2x3 The University of SydneyPage 853k + 3tx13-SAT Reduces to Directed Hamiltonian Cycle– Construction. Given 3-SAT instance F with n variables xi and k clauses. – For each clause: add a node and 6 edges.C1 =x1 Vx2 Vx3clause nodeclause node sThe University of SydneyPage 86tC2 =x1 Vx2 Vx3 x1x2x3 3-SAT Reduces to Directed Hamiltonian Cycle– Construction. Given 3-SAT instance F with n variables xi and k clauses. – For each clause: add a node and 6 edges. C1 =x1 Vx2 Vx3clause nodeclause nodesThe University of SydneyPage 87tC2 =x1 Vx2 Vx3x1x2 x3 3-SAT Reduces to Directed Hamiltonian Cycle– Construction. Given 3-SAT instance F with n variables xi and k clauses. – For each clause: add a node and 6 edges. C1 =x1 Vx2 Vx3clause nodeclause nodesThe University of SydneyPage 88tC2 =x1 Vx2 Vx3x1x2 x3 3-SAT Reduces to Directed Hamiltonian CycleClaim: F is satisfiable iff G has a Hamiltonian cycle.Proof: Þ– Suppose 3-SAT instance has satisfying assignment x*. – Then, define Hamiltonian cycle in G as follows:• if x*i = 1, traverse row i from left to right• if x*i = 0, traverse row i from right to left• for each clause Cj , there will be at least one row i in which we are going in “correct” direction to splice node Cj into tours x1 x2 The University of Sydney t Page 89×33-SAT Reduces to Directed Hamiltonian CycleClaim: F is satisfiable iff G has a Hamiltonian cycle.Proof: Ü– Suppose G has a Hamiltonian cycle G.– If G enters clause node Cj , it must depart on mate edge.• thus, nodes immediately before and after Cj are connected by an edge e in G• removing Cj from cycle, and replacing it with edge e yields HamiltoniancycleonG{Cj }– Continuing in this way, we are left with Hamiltonian cycle G’ in G-{C1,C2, …,Ck}.– Set x*i = 1 iff G’ traverses row i left to right.– Since G visits each clause node Cj , at least one of the paths is traversedin “correct” direction, and each clause is satisfied. ▪ The University of SydneyPage 90 Longest PathSHORTEST-PATH: Given a digraph G = (V, E), does there exists a simple path of length at most k edges?LONGEST-PATH: Given a digraph G = (V, E), does there exists a simple path of length at least k edges?Theorem: 3-SAT £ P LONGEST-PATH.Proof: Redo the proof for DIR-HAM-CYCLE, ignoring back-edge from t to s. Corollary: Deciding who wins in Catan and Ticket to Ride is NP-hard.The University of Sydney Page 91 Travelling Salesperson ProblemTSP: Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length £ D?All 13,509 cities in US with a population of at least 500 Reference: http://www.tsp.gatech.edu The University of SydneyPage 92 Travelling Salesperson ProblemTSP: Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length £ D?Optimal TSP tourReference: http://www.tsp.gatech.edu The University of SydneyPage 93 Travelling Salesperson ProblemTSP: Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length £ D?11,849 holes to drill in a programmed logic array Reference: http://www.tsp.gatech.edu The University of SydneyPage 94 Travelling Salesperson ProblemTSP: Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length £ D?Optimal TSP tourReference: http://www.tsp.gatech.edu The University of SydneyPage 95 Travelling Salesperson ProblemTSP: Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length £ D?HAM-CYCLE: given a graph G = (V, E), does there exists a simple cycle that contains every node in V?Theorem: HAM-CYCLE £ P TSP. Proof:– Given instance G = (V, E) of HAM-CYCLE, create n cities with distancefunction– TSP instance has tour of length £ n iff G is Hamiltonian. ▪d(u,v)=ìí1 if(u,v)ÎE î2 if(u,v)ÏEThe University of Sydney Page 96 NP-complete games and puzzles– Battleship– Candy Crush Saga– Donkey Kong– Eternity II– (Generalized) FreeCell– Lemmings– Minesweeper Consistency Problem– Pokémon– SameGame– (Generalized) Sudoku– (generalized) Tetris– Rush Hour– Hex– (Generalized) Super Mario BrosThe University of SydneyPage 97Polynomial-Time Reductions constraint satisfaction3-SATDick Karp (1972) 1985 Turing AwardSUBSET-SUMSCHEDULINGINDEPENDENT SETVERTEX COVERSET COVERpacking and coveringDIR-HAM-CYCLEHAM-CYCLETSPsequencingGRAPH 3-COLORPLANAR 3-COLORThe University of SydneyPage 98partitioningnumerical3-SAT reduces to INDEPENDENT SET Summary§ Polynomial time reductions3-SAT £P DIR HAMILTONIAN CYCLE £P HAMILTONIAN CYCLE £P TSP 3-SAT £P INDEPENDENT-SET £P VERTEX-COVER £P SET-COVER§ Complexity classes:P: Decision problems for which there is a poly-time algorithm. NP: Decision problems for which there is a poly-time certifier.NP-complete: A problem in NP such that every problem in NP polynomial reduces to it.NP-hard: A problem such that every problem in NP polynomial reduces to it.§ Lots of problems are NP-completeSee https://www.nada.kth.se/~viggo/wwwcompendium/The University of SydneyPage 99

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考程序代写 compiler database algorithm Lecture 11:
30 $