[SOLVED] CS compiler database algorithm Lecture 9:

$25

File Name: CS_compiler_database_algorithm_Lecture_9:.zip
File Size: 386.22 KB

5/5 - (1 vote)

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

Outline of todays 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: IfXP YandYP 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 vs Optimization vs Search
Decision problem:
Does there exist a matching of size 3 k? Output: Yes/No.
Optimization problem:
What is the size of the maximum matching? Output: Number.
Search problem:
Find a maximum matching. Output: Set of edges.
Theorem. Decision o P Optimization o P Search The University of Sydney
Page 22

Decision P Optimization P Search
Decision problem:
Does there exist a matching of size 3 k? Optimization problem:
What is the size of the maximum matching? Search problem:
Find a maximum matching.
Decision P Optimization
Proof: Run the optimization algorithm and check if its output 3 k Optimization P Search
Proof: Run the search algorithm and return size of its output The University of Sydney
Page 23

Decision P Optimization P Search
Decision problem:
Does there exist a matching of size 3 k? Optimization problem:
What is the size of the maximum matching? Search problem:
Find a maximum matching. Optimization P Decision
Size of maximum matching = largest k such that answer to decision problem is YES.
Binary search (O(log m) calls to decision algorithm) The University of Sydney
Page 24

Decision P Optimization P Search
Search P Optimization (uses technique called self-reducibility)
Proof:
Key observation: If removing edge e from G does not reduce size of max matching, then there exists a max matching not containing edge e.
Let OPT(G) denote size of max matching of G. Reduction:
For each edge e:
If OPT(G {e}) = OPT(G), remove e from G
Uses m calls to optimization algorithm. The University of Sydney
Page 25

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 26

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 27

Reduction Strategies
The University of Sydney
Page 28
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 I V such that |S| 3 k, and for each edge at most one of its endpoints is in S?
The University of Sydney Page 29
independent set

Independent Set
INDEPENDENT-SET: Given a graph G = (V, E) and an integer k, is there a subset of vertices S I V such that |S| 3 k, and for each edge at most one of its endpoints is in S?
Ex. Is there an independent set of size 3 6? Yes. Ex. Is there an independent set of size 3 7? No.
independent set
The University of Sydney Page 30

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

Vertex Cover
VERTEX-COVER: Given a graph G = (V, E) and an integer k, is there a subset of vertices S I V such that |S| k, and for each edge, at least one of its endpoints is in S?
Ex. Is there a vertex cover of size 4? Yes. Ex. Is there a vertex cover of size 3? No.
The University of Sydney
Page 32
vertex cover

Vertex Cover and Independent Set
Theorem: VERTEX-COVER oP INDEPENDENT-SET. (VC P IS and IS P VC)
The University of Sydney
Page 33

Vertex Cover and Independent Set
Theorem: VERTEX-COVER oP INDEPENDENT-SET. (VC P IS and IS P VC) Proof:
We claim S is an independent set iff VS is a vertex cover.
independent set vertex cover
The University of Sydney
Page 34

VERTEX-COVER oP INDEPENDENT-SET We claim S is an independent set iff VS is a vertex cover.
Given this claim, we can construct the following reductions:
VC P IS
VC instance (G, k) IS instance (G, n-k) Yes for VC instance iff Yes for IS instance
IS P VC
IS instance (G, k) VC instance (G, n-k) Yes for IS instance iff Yes for VC instance
Analysis:
1. Both transformations take O(n+m) time.
2. Both proofs of correctness follow from the claim as it implies:
There exists a VC of size k iff there exists an IS of size n-k.
The University of Sydney Page 35

Vertex Cover and Independent Set
Claim: S is an independent set iff VS is a vertex cover.
Proof: We show S is an independent set iff VS is a vertex cover.
independent set vertex cover
Let S be any independent set.
Consider an arbitrary edge (u, v).
SindependentuISorvIS uIVSorvIVS. Thus, VS covers (u, v) VS vertex cover.
uv uv
U Let VS be any vertex cover.
ConsidertwonodesuISandvIS.
Observe that (u, v) I E since VS is a vertex cover.
Thus, no two nodes in S are joined by an edge S independent set.
The University of Sydney Page 36
uv

Reduction Strategies
The University of Sydney
Page 37
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 I U of capabilities. Goal: achieve all n capabilities using fewest pieces of software.
Example:
U = { 1, 2, 3, 4, 5, 6, 7 } k=2
The University of Sydney
S1 ={3,7}
S2 ={3,4,5,6} S3 = {1}
S4 ={2,4}
S5 ={5}
S6 = {1, 2, 6, 7}
Page 38

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 I 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 39

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 ={eIE: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 40

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 ={eIE: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 41

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 ={eIE:eincidenttov}
Set-cover of size k iff vertex cover of size k.
VERTEX COVER
f
a b
e7 e2 e3 e4 e6
SET COVER
U = { 1, 2, 3, 4, 5, 6, 7 }
c
k=2
Sa = {3, 7}
Sc = {3, 4, 5, 6} Se = {1}
Sb = {2, 4}
Sd = {5}
Sf= {1, 2, 6, 7}
k=2
e1
e5
The University of Sydney
Page 42
ed

Reduction Strategies
The University of Sydney
Page 43
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 U x2 U x3
F= C1UC2UC3UC4 SAT: Given CNF formula F, does it have a satisfying truth assignment?
3-SAT: SAT where each clause contains exactly 3 literals.
The University of Sydney
Page 44
(xUx Ux )U(xUx Ux )U(x Ux Ux )U(xUx Ux ) 123123123123
Ex:
Yes: x1 = true, x2 = true x3 = false.

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 I V such that |S| 3 k, and for each edge at most one of its endpoints is in S?
The University of Sydney Page 45

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 46

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 U x2 U x3)U (x1 U x2 U x3) U (x1 U x2 U x4)
Page 47

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: U 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 U x2 U x3)U (x1 U x2 U x3) U (x1 U x2 U x4)
Page 48

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: U 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 U x2 U x3)U (x1 U x2 U x3) U (x1 U x2 U x4)
Page 49

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 50

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 51

3 Satisfiability Reduces to Clique
Example:
G=
E = (x U y U z) U (x U y U z) U ( y U z)
x y
z
x
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 52
z
y
z
y

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 53

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

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?
Prims
The University of Sydney Page 55

Definition of the class NP
Class NP: Decision problems for which YES-instances have a poly-time certifier (aka verifier).
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 56

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(vIU:v I 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 57

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 Ux2 Ux3)U(x1 Ux2 Ux3)U(x1 Ux2 Ux4)U(x1 Ux3 Ux4) instance s
Conclusion: SAT is in NP. The University of Sydney
Page 58
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 59

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 I NP.
The University of Sydney Page 61

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 I NP. Claim: NP I EXP.
The University of Sydney Page 62

The Main Question: P Versus NP
Is P = NP? [Cook 1971, Edmonds, Levin, Yablonski, Godel]
Is the search problem as easy as the certification problem?
One of the seven Millennium Prize problems: $1 million prize if solved.
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. Checking the correctness of a given solution is easier than finding a correct solution.
If P1NP
P=NP: Efficient algorithms for 3-COLOR, TSP, FACTOR, SAT,
would break RSA cryptography
The University of Sydney Page 63

The Simpsons: P = NP?
The University of Sydney
Page 64
Copyright 1990, Matt Groening

8.4 NP-Completeness
The University of Sydney Page 65

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 66

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:
U 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. SinceXp Y,wecansolveXin poly-time. This implies NP I P.
WealreadyknowP I NP.ThusP=NP.
The University of Sydney
Page 67

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
U U
UUU
CIRCUIT-SAT I NP
Yes: 101
The University of Sydney
Page 68
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 certificate
YES-instances are those for which there exists an input that makes the
circuit output 1.
Proof not part of the course.
The University of Sydney Page 69

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.
U independent set of size 2?
independent set?
both endpoints of some edge have been chosen?
U U
UUU
U U
UUU
n o hard-coded inputs (graph description) n inputs (nodes in independent sPeatg)e 70 ce 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,WP Y.
Hence Y is NP-complete. The University of Sydney
by definition of NP-complete
by assumption
Page 71

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: x2Ux3 , x2Ux3
x1 =x4 Ux5 add3clauses: x1Ux4, x1Ux5 , x1Ux4 U x5
x0=x1Ux2 add3clauses: x0Ux1, x0Ux2,x0Ux1Ux2
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 U U x1x2 x5 x4x3The University of SydneyPage 720?? 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 73 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 74SET 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 75 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 76 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 77 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 78 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 79 Many classes?https://complexityzoo.uwaterloo.ca/Complexity_Zoo The University of Sydney Page 80Taxonomy 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 81Subset-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 82 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 83 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 85 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 86i: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 87Vertex Cover Reduces to Subset SumClaim: G has vertex cover of size at most k iff (S, t) has a subset summing to t. Proof: U 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 888.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 89Hamiltonian 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 90 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 91 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 92 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.U 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 93 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 94 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 U set variable xi = 1.s x2x3 The University of SydneyPage 953k + 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 96tC2 =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 97tC2 =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 98tC2 =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 99×33-SAT Reduces to Directed Hamiltonian CycleClaim: F is satisfiable iff G has a Hamiltonian cycle.Proof: U 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 100 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 101 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 102 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 103 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 104 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 105 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)=ii1 if(u,v)IE i2 if(u,v)IEThe University of Sydney Page 106 NP-complete games and puzzles Battleship Candy Crush Saga Donkey Kong Eternity II (Generalized) FreeCell Lemmings Minesweeper Consistency Problem Pokemon SameGame (Generalized) Sudoku (generalized) Tetris Rush Hour Hex (Generalized) Super Mario BrosThe University of SydneyPage 107Polynomial-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 108partitioningnumerical3-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 109

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 9:
$25