CSCI 4325 / 6339 Theory of Computation

43
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen

description

CSCI 4325 / 6339 Theory of Computation. Zhixiang Chen. Chapter 6 Computational Complexity. NP. NP-complete. P. The New World. Polynomially Bounded TM’s. Definition. A TM M=(K, ∑, δ ,s,H) is said to be polynomially bounded if there is polynomial p(n) such that the following is true: - PowerPoint PPT Presentation

Transcript of CSCI 4325 / 6339 Theory of Computation

Page 1: CSCI 4325 / 6339 Theory of Computation

CSCI 4325 / 6339Theory of Computation

Zhixiang Chen

Page 2: CSCI 4325 / 6339 Theory of Computation

Chapter 6 Computational Complexity

Page 3: CSCI 4325 / 6339 Theory of Computation

The New World

P

NP

NP-complete

Page 4: CSCI 4325 / 6339 Theory of Computation

Polynomially Bounded TM’s

Definition. A TM M=(K,∑,δ,s,H) is said to be polynomially bounded if there is polynomial p(n) such that the following is true: For any input x, the computation of M on x ends in

no more p(|x|)+1 steps.

Page 5: CSCI 4325 / 6339 Theory of Computation

Polynomially Decidable Languages Definition. A language is called polynomially

decidable is there is a polynomially bounded TM that decides it.

Page 6: CSCI 4325 / 6339 Theory of Computation

The Class P

Definition. The class P is the set of all polynomially decidable languages.

Examples. The set of even integers The set of connected graphs Other examples?

Page 7: CSCI 4325 / 6339 Theory of Computation

Quantitative Refinement of the Church-Turing Thesis Any problem which is intuitively feasibly

solvable is solvable by a polynomially bounded TM.

Any problem which is solvable by a polynomially bounded TM is intuitively feasibly solvable.

Page 8: CSCI 4325 / 6339 Theory of Computation

Theorem

Theorem 6.1.1. The class P is closed under complement.

Proof. (Prove in class.)

Page 9: CSCI 4325 / 6339 Theory of Computation

Something not in P

Definition. Define E={encode(M)encode(w):

M accepts w in but steps}

Theorem. Proof. By contradiction. Consider a special case of E:

M accepts encode(M) but

steps}

Prove

1||2 w

||2 w

.PE

:)({1 MencodeE ||2 w

1||2 w

.1 PE

Page 10: CSCI 4325 / 6339 Theory of Computation

New Notations

For simplicity We use “M” to denote the encode(M) of a TM M We also use “w” to denote the encode(w) of a

string w.

Page 11: CSCI 4325 / 6339 Theory of Computation

Some Coments

Comments on polynomial time bounded decidability Practically feasible? It’s based on worst-case performance analysis How about average-case performance analysis?

Page 12: CSCI 4325 / 6339 Theory of Computation

Problems vs. Languages

Given any TM M and any input w, will M halts on w? This is a problem.

Define This is a language.

The fact The problem and the language are equivalent!

}:"""{" wonhaltsMwMH

Page 13: CSCI 4325 / 6339 Theory of Computation

Problems vs. Languages

Given any string w, will w have property P? This is a problem.

Define This is a language.

The fact again The problem and the language are equivalent!

Conclusion: A problem is a language. A language is a problem.

}:{ PpropertyhaswwH

Page 14: CSCI 4325 / 6339 Theory of Computation

Eulerian Graphs

Euler Cycle Problem: Given a graph G, is there a closed path in G that uses each edge exactly once?

A graph that has a Euler cycle is called Eulerian.

Ex’s

Page 15: CSCI 4325 / 6339 Theory of Computation

Eulerian Graphs

Euler Cycle Problem is in P. That is,

is in P.

Proof. By Euler Theorem: Euler Theorem. A graph G is Eulerian iff the following two

conditions are true: For any pair of nodes u, v in G, there is a path from u to v. All nodes have equal numbers of incoming and outgoing

edges

}:)({ EulerianisGGL

Page 16: CSCI 4325 / 6339 Theory of Computation

Hamiltonian Graphs

Hamilton Cycle Problem: Given a graph G, is there a cycle that passes through each node of G exactly once?

A graph with a Hamilton cycle is called Hamiltonian

Is Hamilton Cycle Problem in P? Do you know the answer? Do you have an algorithm for solving Hamilton

Cycle Problem? What is the complexity of your algorithm?

Page 17: CSCI 4325 / 6339 Theory of Computation

Yes/No Problems

A yes/no problem is a problem with a yes or no answer.

Euler Cycle Problem and Hamilton Cycle Problem are yes/no problems.

Page 18: CSCI 4325 / 6339 Theory of Computation

Optimization Problems

Traveling Salesman Problem. Given a weighted graph G, find a shortest path touring all nodes in a graph.

Translate Optimization Problem to Yes/No Problem: Given an integer and an distance matrix and

an integer find a Hamiltonian cycle with distance

The above optimization problem and the yes/no problem are “equivalent”.

In general, any optimization problem can translated to an “equivalent” yes/no problem.

nn

.B

,2n ,ijd

,0B

Page 19: CSCI 4325 / 6339 Theory of Computation

Independent Set Problem

Given an undirected graph G=(V,E) and an integer

is there a subset C of V with

such that for all there is no edge between and

Ex’s?

KC ||

Vvu ji ,

,2K

iu ?jv

Page 20: CSCI 4325 / 6339 Theory of Computation

Clique Problem

Given an undirected graph G=(V,E) and an integer

is there a subset C of V with

such that for all there is an edge between and

Ex’s?

KC ||Cvu ji ,

,2K

iu ?jv

Page 21: CSCI 4325 / 6339 Theory of Computation

Node Cover Problem

Given an undirected graph G=(V,E) and an integer

is there a subset C of V with

such that C covers all edges of G?

Note: C covers an edge if it contains at least on endpoint of the edge.

Ex’s?

BC ||,2B

Page 22: CSCI 4325 / 6339 Theory of Computation

Integer Partition Problem

Given a set of n nonnegative integers

represented in binary, is there a subset

such that

Ex’s?

},,2,1{ nP

?

Pi

iPi

i aa

naaa ,,, 21

Page 23: CSCI 4325 / 6339 Theory of Computation

Solution to Integer Partition Problem Compute If H is not an integer then stop and say no Otherwise compute B(i) for

b is the sum of some subset of }

Algorithm for computing B(i): B(0)={0} For do

For do

If then add to B(i)

:{)( HbiB },,{ 1 iaa

n

iiaH

12

1

)1()( iBiB

ni ,,2,1

Haaaj iii ,,2,1, )1( iBaj i

j

Page 24: CSCI 4325 / 6339 Theory of Computation

Example

Work on the following set of integers to determine the answer to the partition problem.

H = 151 B(0) = {0} B(1) = {0, 38} B(2) = {0, 17, 38, 55} B(3) = {0, 17, 38, 52, 55, 69, 90, 107} B(4) = {0, 17, 38, 52, 55, 61, 69, 78, 90, 107, 113, 116, 130, 151} … B(7) = {…, 151} Answer: yes.

.25,88,21

,61,52,17,38

765

4321

aaa

aaaa

Page 25: CSCI 4325 / 6339 Theory of Computation

Complexity of the Algorithm for Computing B(i) The complexity if O(nH)

Outer loop runs n times Inner loop runs H times

So, it the Partition Problem in P? Just from O(nH), it seems the problem in P. What is wrong???????

Page 26: CSCI 4325 / 6339 Theory of Computation

Boolean Satisfiability Problem Definition.

Let be a finite set of Boolean variables, and let be the set of negations of variables in X.

Call elements in as literals

Negations of variables are called negative literals.

},,,{ 21 nxxxX

},,,{ 21 nxxxX

XX

Page 27: CSCI 4325 / 6339 Theory of Computation

Boolean Satisfiability Problem Definition.

Clause: A clause C is a nonempty set of literals, i.e.

Boolean formula in CNF: A Boolean CNF is a set of clauses

.XXC

Page 28: CSCI 4325 / 6339 Theory of Computation

Examples

Let

Clauses:

CNF:

},,,{},,,{ 321321 xxxXxxxX

},,{},,,{ 321321 xxxxxx

}},,{},,,{},,{{ 32132121 xxxxxxxx

Page 29: CSCI 4325 / 6339 Theory of Computation

Boolean Satisfiability Problem Truth Assignment:

a map from X to {0,1} 0 means false 1 means true

A clause is true under an assignment if that assignment make at least of its literals true.

A CNF is true under an assignment if that assignment makes all clauses true.

A CNF is satisfiable, if there is an assignment making it true.

Ex’s?

.XXC

Page 30: CSCI 4325 / 6339 Theory of Computation

Boolean Satisfiability Problem The SAT Problem: Given a Boolean CNF F,

is F satisfiable? The 2-SAT Problem: Given a Boolean CNF F

such that each clause in F has at most two literals, is F satisfiable?

The 3-SAT Problem: Given a Boolean CNF F such that each clause in F has at most three literals, is F satisfiable?

Page 31: CSCI 4325 / 6339 Theory of Computation

2-SAT Problem

Theorem. 2-SAT is in P.

Page 32: CSCI 4325 / 6339 Theory of Computation

2-SAT Problem Algorithm solving 2-SAT

Phase 1. Purge Process Repeat

Scan clause in the input CNF F to find a single literal x Set x to be true. And remove all clauses with x from F, and

remove negative x from these clause containing negative x Fail if an empty clause is generated, and stop and say no.

Until no more single clause in F. Phase 2. Try Two Values Process

Repeat Choose a literal x in the remained F

Set x to be true, and do “Purge Process” Set x to be false and do “purge Process”

If both processes fail, then stop and say no. Until no more literal left.

Phase 3. Final Checking Say true, if no fail occurs in Phase 2.

Page 33: CSCI 4325 / 6339 Theory of Computation

2-SAT Problem

The complexity of previous algorithm Let n be the number of distinct variables in F Let m be the number of clauses in F Phase 1 Time

Phase 2 time

Total time

Conclusion. 2-Sat is in P.

)( 2mnO

)( 2mnO

)(nmO

Page 34: CSCI 4325 / 6339 Theory of Computation

Nondeterministic Ploynomially Bounded TM’s Definition. A NTM M=(K,∑,Δ,s,H) is said to

be polynomially bounded is there is polynomial p(n) such that the following is true: For any input x, all possible computations of M on

x ends in no more p(|x|)+1 steps. In other words, the depth of the computation tree

of M on x is no more than p(|x|)+1.

Page 35: CSCI 4325 / 6339 Theory of Computation

The NP Class

Definition. The class NP is the set of all languages that are decided by ploynomially bounded NTM’s

Page 36: CSCI 4325 / 6339 Theory of Computation

Poly-Bounded Computation Trees )_,( s

),( vauh

………………Tree depth p(|w|)

Page 37: CSCI 4325 / 6339 Theory of Computation

Problems in NP

Problems in NP: SAT Hamilton Cycle Problem TSP Independent Set Problem Clique Problem Covering Problem Partition Problem

Page 38: CSCI 4325 / 6339 Theory of Computation

Proving a Problem in NP

Two steps: Nondeterministically guess an answer in poly-time Deterministically verify the guessed answer is

indeed an answer in poly-time

Show proof examples in class.

Page 39: CSCI 4325 / 6339 Theory of Computation

Exponentially Bounded Deterministic TM’s Definition. A TM M=(K,∑,δ,s,H) is said to be

exponentially bounded is there is polynomial p(n) such that the following is true: For any input x, the computation of M on x ends in no

more than steps.|)(|2 xp

Page 40: CSCI 4325 / 6339 Theory of Computation

The Class EXP

Definition. The class EXP is the set of all problems that are decidable by exponentially-bounded TM’s.

Page 41: CSCI 4325 / 6339 Theory of Computation

P, NP, vs. EXP

Theorem. If L is in NP, then L is in EXP. Proof. A poly-bounded computation tree can be

simulated an exponentially bounded computation.

Theorem. Proof. Consider the exponentially bounded version

of H.

.EXPP

Page 42: CSCI 4325 / 6339 Theory of Computation

The New World

P

NP

EXP

Page 43: CSCI 4325 / 6339 Theory of Computation

Open Questions

EXPNP

NPP

?

?