49
Part VI NP-Hardness

Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Embed Size (px)

Citation preview

Page 1: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Part VI

NP-Hardness

Page 2: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Lecture 23

What’s NP?

Page 3: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Hard Problems

y?efficientl problem covering- vertexand problem,

cyclen Hamiltonia problem,salesman travelingsolve Can we

:question a have weNow,

etc. matching, maximum tree,spanning minimum path,shortest

assuch problems,many for solutionsefficient find to

g)programminlinear flow,network g,programmin dynamic

strategy,(greedy es techniquseveral learned have We

Page 4: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Answer

hard.-NPor complete-NP are they because

far so foundbeen hassolution efficient nobut know,t don' We

What is NP-complete?What is NP-hard?First, what is NP?

Page 5: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Answer 1

".computable time-polynomialnot " means NP

Wrong!

Did you take computer science before ?

Page 6: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Answer 2

is.it whether time-

polynomialin check can wesolution, possible agiven i.e.,

checkable, time-polynomial

are solutionsr that theiproblemsdecision of class a is

:saidprofessor My

NP

Still wrong!But, almost true.I can give you a counterexample!

Page 7: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Integer Programming

integer.an is

0

s.t.

max

i

T

x

x

bAx

xc

Page 8: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Decision version of Integer Programming

.0

and

satisfy vector

integeran thereis , and ,,Given

0

0

x

bAx

cxc

x

cbAc

T

Page 9: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

. tobelonging

gprogrammininteger ofersion decision v

for proof legal anot is thisHowever,

.|| respect to with time

polynomialin esinequaliti osesatisfy th

ether verify wheasy to isit ,Given

NP

x

xx

Page 10: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

How to prove a decision problem belonging to NP?

How to design a polynomial-time nondeterministic algorithm?

Page 11: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

we need to study computation model-Turing Machine.

To answer,

Page 12: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Deterministic Turing Machine (DTM)

Finite Control

tape

head

Page 13: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

The tape has the left end but infinite to the right. It is divided into cells. Each cell contains a symbol in an alphabet Γ. There exists a special symbol B which represents the empty cell.

a l p h a B e

Page 14: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• The head scans at a cell on the tape and can read, erase, and write a symbol on the cell. In each move, the head can move to the right cell or to the left cell (or stay in the same cell).

a

Page 15: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• The finite control has finitely many states which form a set Q. For each move, the state is changed according to the evaluation of a transition function

δ : Q x Γ → Q x Γ x {R, L}.

Page 16: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• δ(q, a) = (p, b, L) means that if the head reads symbol a and the finite control is in the state q, then the next state should be p, the symbol a should be changed to b, and the head moves one cell to the left.

q

a b

p

Page 17: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• δ(q, a) = (p, b, R) means that if the head reads symbol a and the finite control is in the state q, then the next state should be p, the symbol a should be changed to b, and the head moves one cell to the right.

pq

a b

Page 18: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• There are some special states: an initial state s and an final states h.

• Initially, the DTM is in the initial state and the head scans the leftmost cell. The tape holds an input string.

s

Page 19: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• When the DTM is in the final state, the DTM stops. An input string x is accepted by the DTM if the DTM reaches the final state h.

• Otherwise, the input string is rejected.

h

x

Page 20: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Multi-tape DTM

Input tape(read only)

Storage tapes

Output tape

(possibly, write only)

Page 21: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Nondeterministic Turing Machine (NTM)

Finite Control

tape

head

Page 22: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

The tape has the left end but infinite to the right. It is divided into cells. Each cell contains a symbol in an alphabet Γ. There exists a special symbol B which represents the empty cell.

a l p h a B e

Page 23: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

• The finite control has finitely many states which form a set Q. For each move, the state is changed according to the evaluation of a transition function

δ : Q x Γ → 2^{Q x Γ x {R, L}}.

Page 24: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Nondeterministic TM (NTM)

• There are multiple choices for each transition.

• For each input x, the NTM may have more than one computation paths.

• An input x is accepted if at least one computation path leads to the final state.

• L(M) is the set of all accepted inputs.

Page 25: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Time of DTM

• TimeM (x) = # of moves that DTM M takes on input x.

• TimeM(x) < infinity iff x ε L(M).

Page 26: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Space

• SpaceM(x) = maximum # of cells that M visits on each work (storage) tapes during the computation on input x.

• If M is a multitape DTM, then the work tapes do not include the input tape and the write-only output tape.

Page 27: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

What’s P?

• P is a class of decision problems that each can be solved by deterministic TM in polynomial time.

Page 28: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

What’s NP?

• NP is a class of decision problems that each can be solved by a nondeterministic TM in polynomial time.

• NP is a class of decision problems that each can be solved by a polynomial-time nondeterministic algorithm.

Page 29: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

What’s PSPACE?

• PSPACE is a class of decision problems that each can be solved by TM in polynomial space.

• Why didn’t specify Deterministic or Nondeterministic?

It doesn’t matter due to Savitch’s Theorem.

Page 30: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

P = ? NP = ? PSPACE

• They are central problems in computational complexity.

Page 31: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

If P = NP, then

NP-completeP

Page 32: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Ladner Theorem

• If NP ≠ P, then there exists a set A lying -between P and NP-complete class, i.e., A is in NP, but not in P and not being NP-compete.

Page 33: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

How to prove a decision problem belonging to NP?

How to design a polynomial-time nondeterministic algorithm?

Page 34: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Hamiltonian Cycle

• Given a graph G, does G contain a Hamiltonian cycle?

• Hamiltonian cycle is a cycle passing every vertex exactly once.

Page 35: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Nondeterministic Algorithm

• Guess a permutation of all vertices.

• Check whether this permutation gives a cycle. If yes, then algorithm halts.

What is the running time?

Page 36: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Guessing Time

• Each guess can choose one from a constant number of choices.

• This is because that in NTM, the number of choices for each move is independent from input size.

• Guessing a permutation of n vertices needs

(n long n) time.

Page 37: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Minimum Spanning Tree

• Given an edge-weighted graph G, find a spanning tree with minimum total weight.

• Decision Version: Given an edge-weighted graph G and a positive integer k, does G contains a spanning tree with total weight < k.

Page 38: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Nondeterministic Algorithm

• Guess a spanning tree T.

• Check whether the total weight of T < k.

This is not clear!

Page 39: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

How to guess a spanning tree?

• Guess n-1 edges where n is the number of vertices of G.

• Check whether those n-1 edges form a connected spanning subgraph, i.e., there is a path between every pair of vertices.

Page 40: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Co-decision version of MST

• Given an edge-weighted graph G and a positive integer k, does G contain no spanning tree with total weight < k?

Page 41: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Algorithm

• Computer a minimum spanning tree.

• Check whether its weight < k. If yes, the algorithm halts.

Page 42: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

co-NP

• co-NP = {A | Σ* - A ε NP}

Page 43: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

NP ∩ co-NP

So far, no natural problem has been found in NP ∩ co-NP, but not in P.

P

NP

co-NP

Page 44: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Linear Programming

• Decision version: Given a system of linear inequality, does the system have a solution?

• It was first proved in NP ∩ co-NP and later found in P (1979).

Page 45: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Primality Test

• Given a natural number n, is n a prime?

• It was first proved in NP ∩ co-NP and later found in P (2004).

Page 46: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Therefore

• A natural problem belonging to NP ∩ co-NP is a big sign for the problem belonging to P.

Page 47: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Proving a problem in NP

• In many cases, it is not hard.

• In a few cases, it is not easy.

Page 48: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Polynomial-time verification with polynomial-size certificate

time.-polynomialin

verifiedbecan which ecertificat size-polynomial a hasIt

tobelongs problemany Actually,

time.-polynomialin done becan not or of ecertificat a is

guessed a whether verifingand ,lg size has which

cycle Hamitonian a e,certificat size-polynomail a has

cycle Hamitonian a has a has

n Hamiltonia is graph A

NP

G

CnnC

G

G

G

Page 49: Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems

Integer Programming

• Decision version: Given A and b, does Ax > b contains an integer solution?

• The difficulty is that the domain of “guess” is too large, that is, it is not easy to know the existence of polynomial-size certificate.