np, karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_co_2020.pdf · the...

16
NP, Karp reduction László Papp BME 9th of March, 2020

Upload: others

Post on 04-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

NP, Karp reduction

László Papp

BME

9th of March, 2020

Page 2: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Vertex coverDefinition: In a graph G, T ⊆ V (G) is a vertex cover if forevery edge {u, v}, either u ∈ T or v ∈ T or both.

T

Notations: Let G be a graph. We use the following notations:I ν(G) is the size of a maximum matching of GI τ(G) is the size of a minimum vertex cover of G

ClaimIn any graph G: ν(G) ≤ τ(G).Proof: A vertex can cover only one edge of a matching.

Konig’s theoremIf G is a bipartite graph, then ν(G) = τ(G).

Page 3: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

The use of vertex cover in matching theory

Assume that somebody give us a matching M of size k , and avertex cover C of size k . In this case we can conclude that M isa maximum matching and C is a minim vertex cover, because|M| ≤ ν(G) ≤ τ(G) ≤ |C| = |M|.

In such a way we can prove that a matching is maximumwithout using the augmenting algorithm. We just need a vertexcover of the same size.

If the graph is bipartite, then by Konig’s theorem there is alwayssuch a vertex cover if the matching is maximum.

Page 4: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Concept of fast verification by using a witness

We have seen that we can easily verify whether a matching ismaximum if somebody give us a vertex cover of he same size.In that case we can say that such a vertex cover is a witnesswhich proves that the given matching is maximum.Furthermore in a bipartite graph we always have such awitness if the matching is maximum.

In practice we like problems where we can easily confirm thecorrectness of a solution. For example we can easily persuadeour boss that our solution is right. This leads to an importantcomplexity class.

Page 5: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

The NP complexity class

Definition: Let π be a decision problem. We say that π is inclass NP if the following criteria hold:

1. For each input I, if the answer for I is YES, then there is awitness WI .

2. The size of WI is polynomial in the size of I.3. We can verify the YES answer for I by a polynomial time

algorithm, whose input is I and WI .

Example: PERFECT MATCHING ∈ NP.The witness WG is the encoding of a complete matching. Sincea complete matching is a subgraph of G its size is not biggerthan the size of G. The verification algorithm checks whetherWG is a matching of G and it covers each vertex. It can bedone in polynomial time.

Page 6: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

HAMILTONIAN is in NP

Problem HAMILTONIANInput: A graph GQuestion: Does G havea Hamiltonian cycle?

C

A B

D

WG =A,B,D,C

The witness WG is an encoding of the Hamiltonian cycle. It is alist of the vertices in a proper order: Vertices which areadjacent in the list are adjacent in G. The first and the lastvertices of the list are also adjacent in G. The verificationalgorithm checks these adjacency conditions and whether eachvertices of G is contained exactly once in WG.The verification can be done in O(n2) time, where n is thenumber of vertices of G.

Remark: Most mathematicians and computer scientist believethat HAMILTONIAN is not in P.

Page 7: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

The decision version of an optimization problem is usually in NP

Remainder: An optimization problem is the following: A is theset of solutions, f : A→ R is the objective function. Find anx ∈ A which minimizes (or maximizes) f (x)!

Decision version:Input: A transcription of A, f and a number k .Question: Is there a solution x ∈ A which satisfies thatf (x) ≤ k (f (x) ≥ k in case of maximization)?

ClaimIf the function f (x) can be calculated in polynomial time for anyx ∈ A and x ∈ A can be verified in polynomial time, then thedecision version of the optimization problem is in NP.Proof: The withness is a solution x which satisfies that f (x) ≤ k(f (x) ≥ k in case of maximization). The verification algorithmchecks that x ∈ A, then it calculates f (x) and compare it with k .

Page 8: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

The decision version of the TSP is in NP

Decision version of the TSP:Input: A complete graph, a weightfunction w over its edge set and anumber k .Question: Is there a Hamiltoniancycle whose weight is at most k?

A

19

2

3

3

2

B

C D

This problem is in NP, because if the answer is YES, then aproper witness is a proper transcription of the Hamiltonian cyclewhose weight is not more than k . The verification algorithmchecks whether it is a Hamiltonian cycle and it sums its edgeweights and compare to k .

Example: If the input is the graph above and k = 11, then theanswer is yes and the witness is A,B,C,D which encodes theblue Hamiltonian cycle.

Page 9: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Not all decision problems are in NP

There are many decision problems for which we know (it isproved) that they are not contained in NP. Unfortunately theyare complicated. Therefore we consider a problem which isprobably not contained in NP.

Complement problem of TSPInput: A complete graph, a weightfunction w over its edge set and anumber k .Question: Is it true that there is noHamiltonian cycle in the graph whoseweight is at most k?

A2

2

1

3

3

9

B

C D

The conjecture that this problem is not in NP is widely believedby Computer Scientists and Mathematicians.

Page 10: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

SAT is in NP

Problem SAT:Input: A Boolean formula ΦQuestion: Can we assign values 0 and 1 to the variables of Φin such a way that Φ evaluates to 1?Example:Φ(x1, x2, x3, x4) = (x1∨x2∨¬x3∨x4)∧(¬x1∨x4)∧(x1∨x3)∧¬x3Φ(1,1,0,1) = 1. So for this input the answer is YES.

1 and 0 are usually interpreted as TRUE and FALSE,respectively. We say that φ is satisfiable if there is anassignment which gives TRUE.

SAT is in NP, the witness is an assignment of the variableswhich makes Φ be True (1). The verification algorithmevaluates this assignment. It can be done in polynomial time.

Page 11: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Relation between P and NP

ClaimP⊆NPProof: If π is in P, then the witness WI can be anything. We canverify the YES answer in polynomial time for input I simply bycalculating the answer for I by the polynomial time algorithmwhich solves π.

There are many problems which are known to be contained inNP but we believe that they are not in P. However no one couldprove that P 6= NP. The holy grail of the area is the followingopen question:

Open question:Does P 6=NP?There is a bounty of one million dollars on this problem. So ifyou solve it, you will be rich. Furthermore you receive a PhD incomputer science immediately.

Page 12: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Using the same tool to handle different problems

In real life, if a tool works well in an area then we usually try touse it somewhere else. Sometimes we found pretty goodapplications elsewhere. For example Teflon(Polytetrafluoroethylene), the material which coats pans is firstused to make gaskets.

In the area of algorithms and optimization methods, we do thesame. If an algorithm works well for a problem α, then we try touse it for problem β.

Page 13: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Polynomial-time reductionA polynomial-time reduction (Karp reduction) is a method howto transform a problem to an another one.Definition: We say that the mapping F is a Karp reductionfrom decision problem α to decision problem β, if:I F maps all inputs of α to inputs of β.I F can be calculated in polynomial time, so exist a real k ,

such that F (I) can be calculated in O(|I|k ) for any input I.I Answer for I is YES if and only if the answer for F (I) is

YES.Yes answerYes answer

No answer No answer

F

Inputs of βInputs of α

Page 14: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

A Karp reduction from HAMILTONIAN to TSP

F maps an n vertex input graph G to Kn with a weight functionw : E(Kn)→ R given below and set k to n.

w(e) =

{1 if e is an edge of Gn + 1 if e is not an edge of G

G 1

1

11

55

FInput of TSP

Input ofHAMILTONIAN

Correctness of the reduction: If G has a hamiltonian cycle,then its weight in the created Kn is n, so the answer for the TSPis YES. If G does not have a hamiltonian cycle, then everyhamiltonian cycle in the created graph contains an edge ofweight n + 1, therefore the answer for TSP is NO.F (G) can be calculated in O(n3) time, so in polynomial time.

Page 15: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Karp reductions and class P

Notation: If we have have a Karp reduction from α to β, thenwe write, that α ≺ β.

ClaimIf α ≺ β and β ∈ P, then α ∈ P.Proof: We have an algorithm B which solves β in polynomialtime, so there is a number kB such that any input IB of β issolved in O(|IB|kb ) time.Let F be the mapping of the Karp reduction. F can becalculated in polynomial time. Therefore there is a kF such thatfor any input IA of α F (IA) can be calculated in in O(|IA|kF ) time.Hence |F (IA)| ∈ O(|IA|kF ).Let A be the following algorithm: It calculates F (IA),then it runsalgorithm B. A solves problem α correctly.The running time of A is O(

(|iA|kF

)kB ) = O(|iA|kF kB ), hence itruns in polynomial time.

Page 16: NP, Karp reductioncs.bme.hu › ~lazsa › combopt2020spring › fifth_lecture_CO_2020.pdf · The use of vertex cover in matching theory Assume that somebody give us a matching M

Directed Hamiltonian problem

Definition: Let ~G be a directed graph. A directed Hamiltoniancycle of ~G is a directed cycle containing all the vertices of ~G.

Problem DIRECTED HAMILTONIANInput: A directed graph ~GQuestion: Does ~G have a directed Hamiltonian cycle?