430 likes | 532 Views
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:
E N D
CSCI 4325 / 6339Theory of Computation Zhixiang Chen
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: • For any input x, the computation of M on x ends in no more p(|x|)+1 steps.
Polynomially Decidable Languages • Definition. A language is called polynomially decidable is there is a polynomially bounded TM that decides it.
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?
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.
Theorem • Theorem 6.1.1. The class P is closed under complement. • Proof. (Prove in class.)
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
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.
Some Coments • Comments on polynomial time bounded decidability • Practically feasible? • It’s based on worst-case performance analysis • How about average-case performance analysis?
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!
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.
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
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
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?
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.
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.
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?
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?
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?
Integer Partition Problem • Given a set of n nonnegative integers represented in binary, is there a subset such that • Ex’s?
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)
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.
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???????
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.
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
Examples • Let • Clauses: • CNF:
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?
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?
2-SAT Problem • Theorem. 2-SAT is in P.
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.
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.
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.
The NP Class • Definition. The class NP is the set of all languages that are decided by ploynomially bounded NTM’s
Tree depth p(|w|) ……………… Poly-Bounded Computation Trees
Problems in NP • Problems in NP: • SAT • Hamilton Cycle Problem • TSP • Independent Set Problem • Clique Problem • Covering Problem • Partition Problem
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.
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.
The Class EXP • Definition. The class EXP is the set of all problems that are decidable by exponentially-bounded TM’s.
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.
NP EXP P The New World