Top Banner
NP-Hard Nattee Niparnan
49

Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.

Jan 12, 2016

Download

Documents

Harold Brooks
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

NP-Complete

NP-HardNattee NiparnanEasy & Hard ProblemWhat is difficulty of problem?Difficult for computer scientist to derive algorithm for the problem?Difficult for computer to solve (run the derived algorithm) the problem?Basic IntuitionEasy problem = Anything we can solve within O( T(x) ) where T(x) is polynomialHard problem = Anything else (maybe)

More questionsIs there something unsolvable?How to know whether the problem is hard?Unsolvable ProblemUnsolvableFormally, its called undecidableBut lets say unsolvable for nowSomething that we cant have algorithm for it

Example:Halting ProblemHalting ProblemInput: Given a program P and its input SOutput: Yes when P finishes No when P loops forever

To have an algorithm for halting problemThe algorithm must be able to correctly answer this question for every P and SHalting is undecidableLet us assume that there is an algorithm for the problemLets say bool A(P,S) is a function that solve this problemWe construct another functionbool Kaboom(x) { if (A(x,x)) { while (true) do ; } else { printf(wow.); }}kb.cppkb.cppAXXXloops foreveryesnoKaboomWhat is the result of Kaboom(kb.cpp) ?P and NPHard vs EasyWhich problem is hard?Which problem is easy?Given problem A and B, which one is easier?

This revolves around the concept of reducabilityReductionProblem reduction: solve problem A by transform it into BExample:Finding kth smallest element can be solved by simply sort the inputHence, kth smallest element transformed into sorting problemMaximal Bipartite Matching can be solved by network flowPolynomially ReducableLet X be an instance of problem ALet f(X) be a function that transform the instance x of problem A into an instance of problem BIf f(X) uses polynomial time to the size of x, we say that

A is polynomially reducible to BComparing hardness of problemGiven an instance of problem AIf that instance of A can be transformed into an instance of problem BWhich one is harder?A or B?

P and NPClass of problemsP set of problems that we have polynomial time algorithm or betterNPInformal: exponent time; set of problems that we have exponential time algorithm or betterMore formal: polynomially verifiable; set of problems that we can verify whether its answer is correct in polynomial time (given right evidence)Actual: non-deterministically provable; set of problems that can be solved by non-deterministic turing machinei.e., every problem we have seen so farExamplePMSS, Sorting, Shortest Path, MSTNPMSS, Sorting, Shortest Path, MST is also NPTSP, 01-knapsack, graph coloring, longest pathAnd much more

NPPMore ExampleShortest PathGiven a weighted graph G and two vertices u,v, find shortest path from u to vInput: a graph G and two vertices u and vOutput: a path Is in P, Dijkstras algorithm runs in P Is in NPgiven a graph and a path, we can verify that the part is the shortest pathBy running Dijkstra ourselves and compare the length with the given pathMore ExampleGraph isomorphismGiven two graphs, decides whether they are isomorphicInput: two graphsOutput: YES or NOIs in NPCan be verify if a mapping is givenHard vs Easy againP contains solely easy problemsNP has easy problems + something elseBelieve to be hard problemsHard = NP?No, something in NP is easyNo, something hard is not in NP

Try graph non-isomorphism

The verifiable definition for NP is when the answer is YESReductionDecision ProblemWe consider only decision problemFor simplicity

Decision problemLimiting output to only YES and NOEx,Given a graph G, does it has Euler circuit?Given a list of integers, is their GCD 1?Given a list of 3D boxes, do they intersect?Functional and Optimization ProblemFunction ProblemOutput is a functionOptimization ProblemIs a function problemOutput is the best instance of the given functionEx:MSS, Shortest Path,

Equivalence to Decision ProblemAll function problem can be reduced to decision problemFor polynomial outputUsing polynomial timeExampleTSPFunction: Ask for the minimal pathDecision: Ask whether there exist a Hamilton path with sum weight less than or equal to XDo binary search on the value of XEventually, we know the minimal X and hence the minimal path

Finally, the NP-HardMore definitionNP-HardA problem such that all problems in NP is polynomially reducible toNP-CompleteAn NP-Hard that is in NP

NP-CThere is, effectively, only one NP-CSince it is NP-HardEverything in NP can be reduced to itIncluding any other NP-C

Reduction ExampleBoolean expression in CNF

clause

literalVariable : x y zcompliment: x , not x SAT Problem

A decision problem

Given a Boolean expression in CNF (and of or-clause), can it be evaluated as true by assigning some value to the variableCooks TheoremSAT problem is NP completeIt is in NP, because given assignment, we can check whether it is true in P timeAll problem in NP can be reduced to SATBecause, essentially, all Turing machines can be described by a Boolean expression

ReductionHamiltonian Path Hamiltonian CycleHamiltonian Cycle ProblemGiven a graph GIs there exists a Hamiltonian cycleHamiltonian Path ProblemGiven a graph G and two of its vertices s and tIs there exists a path starting at s and ends at t that contains all vertices of G?

Reduction

CorrectnessLet G be the reduced instance of Hamiltonian cycleWhen G has solutionSince x has only two neighbors, s and tJust cut the cycle at xWhen G does not has solutionShow instead that when G has soltuion, G must has solutionDoes reduction use polynomial time?yes

SAT 3SAT3SAT = SAT that each clause does not has more than 3 literals (variables + constants)A stricter version of SATSubset of SATSeems to be easier than SAT?ReductionRewrite SAT as 3SATSimply convert every clause having more than 3 lieteral to something else (that is 3SAT)Assume that there is a clausewhere k > 3

Change it to

Add new variables y1,yk-3CorrectnessWhen I be the instance of 3SAT while I be the original intance of SATWhen I can be made true, I must can be made trueWhen the right side evaluate to true, at least one of ai is trueWhen I cannt be true, I mustnt can be made true Conversely, When I can be made true, I must can be made trueWhen I can be made true, at least one of ai is true, we must set y such that the entire is trueSimply set y1,,yi-2 as true and the rest as false3SAT INDEPENDENT SETIndependent SetGiven a graph G and a number gIs there exists a set of g vertices that is not adjacent (pairwisely)

Drastically differs from 3SAT

ReductionAssume that we have 3SAT instance called S

Convert it into a graph GEach literal is a vertexThere is an edge connecting Every vertex from the same clauseEvery pair of a literal and its complementSolve the independent set Use g as the number of clause

Example

CorrectnessIf G has solution, S must be satisfiableSince each clause is maximally connected, not more than one vertex per corresponding clause is selectedSince g equals to the number of clause, it is not possible for any clause not to have its corresponding vertex selectedSince it is not possible for x and not x to be selected at the same time, the assigment is consistentIf G has no solution, S must not be satisfiableContrapositive again, if S can be satisfied, G has solutionVery simple

SAT CliqueCliqueGiven a graph GIs there exists a subgraph of size k that is complete

ReductionGiven an instance of SAT, SConstruct a graph CVertex: There is a vertex for every literal in every clauseEdge:Vertices in the same clause is not adjacentVertices from different clauses are always adjacentExcept for any pair of vertex of a literal and its complimentAlmost the inverse of 3SAT independent setDraw them in columnsSolve the clique of Cuse K = number of clauses in SExampleS =

C

xy-z-x-yz-zyCorrectnessIf C has solution, S must be satisfiableThe clique cannot be larger than kThe clique must contain exactly one vertex in each columnSimply assign the associated variable as trueIf some variable does not appear in the clique, just assign any valueIf C has no solution, S mustnt be satisfiableAgain, use contrapositive, if S is satisfiable, C has solutionSimply choose a vertex corresponding to the one that is true in each clauseThe selected vertices forms clique, since the only case when they wont have an edge is when they are complimentMore detail on all problems to SATWe first do CIRCUIT SAT SATCIRCUIT SAT (CSAT)Input: a boolean expression chained togetherOutput: YES / NO whether the expression can be satisfied

ReductionConvert CSAT to SAT

Is this correct?

Final StepEvery problem is simply a turing machineSimply a logic circuitHence, everything is circuit sat satYour TurnIndependent Set cliqueIndependent Set = set that vertices does not adjacentClique = set that vertices always adjacentIndependent Set vertex coverIndependent Set = largest set that vertices does not adjacentVertex coverGiven a graph and a number kIs there exists a set of k vertices to which every edge in the graph incident