330 likes | 588 Views
Algorithms. Chapter 34 NP-Completeness Ming-Te Chi. Outline. Tractable / Intractable P and NP NP-complete, NP-hard. Almost all algorithms we have studied thus far have been polynomial-time algorithms. Time Complexity. Polynomial-time :
E N D
Algorithms Chapter 34 NP-Completeness Ming-Te Chi NP Completeness
Outline • Tractable / Intractable • P and NP • NP-complete, NP-hard NP Completeness
Almost all algorithms we have studied thus far have been polynomial-time algorithms. NP Completeness
Time Complexity • Polynomial-time: • On inputs of size n, their worst-case running time is O(nk). • It is natural to wonder whether all problems can be solved in polynomial time. • No. • For example, the Turing’s Halting Problem can NOT be solved by any computer, no matter how much time is provided. NP Completeness
Time complexity • Super Polynomial time • ), , k>2 • Recursive solution for Fibonacci number • 0/1 knapsack • … NP Completeness
Generally, we think of problems that are solvable by polynomial-time algorithms are being tractable, and problems that requires superpolynomial time are being intractable. There are some undecidable problem. Ex: Halting problem NP Completeness
Problem category • Optimization problems • Each feasible solution has an associated value, and we wish to find a feasible solution with the best value. • Decision Problems • the answer is simply “yes” or “no” NP Completeness
Class P • Class P is a class of decision problems that can be solved in polynomial time by (deterministic) algorithms • Deterministic algorithms • an algorithm which, in informal terms, behaves predictably NP Completeness
Nondeterministic algorithms • Two-stage procedure • Nondeterministic (guessing) stage • Guess all arbitrary candidate solution S • Deterministic (verification) stage • Verify the candidate solution S • Nondeterministic polynomial • If the time efficiency of its verification stage is polynomial NP Completeness
Class NP • Class NP is the class of decision problems that can be solved by nondeterministic polynomial algorithms. • 0-1 Knapsack Problem • Traveling salesman • … NP Completeness
Traveling salesman problem • The most efficient (i.e., least total distance) Hamiltonian cycle a salesman can take through each of n cities. In Pursuit of the Traveling Salesman: Mathematics at the Limits of Computation William J. Cook NP Completeness
P and NP NP Completeness
P = NP ? • Status unknown • No polynomial-time algorithm has yet been discovered for an NP-complete problem • Nor has anyone yet been able to prove that no polynomial-time algorithm can exist for any one of them NP Completeness
The NP-complete problems • A decision problem L is NP-complete if • 1) it belongs to class NP. • 2) every problem L' in NP is polynomially reducible to L (L' L). NP Completeness
Polynomially reduction NP Completeness
NP-hard • A decision problem L is NP-hard if • 1) every problem L' in NP is polynomially reducible to L (L' L). • 2) but L not necessarily belongs to class NP. NP Completeness
P: the class of problems which can be solved by a deterministic polynomial algorithm. • NP: the class of decision problem which can be solved by a non-deterministic polynomial algorithm. • NP-hard: the class of problems to which every NP problem reduces. (as hard as any problem in NP) • NP-complete (NPC): the class of problems which are NP-hard and belong to NP. NP Completeness
The difference between these problems • Shortest vs. longest simple paths: • Euler tour vs. hamiltonian cycle: • 2-CNF satisfiability vs. 3-CNF satisfiablility • NP-completeness and the classes P and NP • Overview of showing problems to be NP-complete • Decision problems vs. optimization problems NP Completeness
Shortest vs. longest simple paths • Ch 24: • Even with negative edge weight, single source shortest path in directed graph can be found in O(VE). • Longest simple path between two vertices is NP-complete. • It is NP-complete even if all edge weight = 1. NP Completeness
Euler tour vs. Hamiltonian cycle • Euler tour of a connected, directed graph G is a cycle that traverses each edge of G exactly once. • (It may visit a vertex more than once.) • O(E) algorithm exist. • Hamiltonian cycle of a directed graph G is a simple cycle that contains each vertex of G. • Determine whether a directed graph has a Hamiltonian cycle is NP-complete. • Determine whether a undirected graph has a Hamiltonian cycle is NP-complete. NP Completeness
2-CNF satisfiability vs. 3-CNF satisfiablility • A boolean formula contains variables whose values are 0 or 1. • Boolean operators: ٨(AND); ٧(OR); ¬(NOT) • A boolean formula is satisfiable if there is some assignment of the values 0 and 1 to its variables that causes it to evaluate to 1. • k-conjunctive normal form (k-CNF): the formula is the AND of clauses of Ors of exactly k variables or their negations. NP Completeness
2-CNF every clause has exactly 2 variables • 3-CNF: every clause has exactly 3 variables • 2-CNF satisfiability: polynomial time algorithm exists • 3-CNF satisfiablility: NP-complete NP Completeness
The satisfiability problem --the first NPC problem ever found x (OR) + (AND) - (NOT) • The satisfiability problem • The logical formula : the assignment : x1 ← F , x2 ← F , x3 ← T will make the above formula true . NP Completeness
If there is at least one assignment which satisfies a formula, then we say that this formula is satisfiable; otherwise, it is unsatisfiable. • An unsatisfiable formula: NP Completeness
Cook’s theorem 1971 • SAT is NP-complete. • It is the first NP-complete problem. • Every NP problem reduces to SAT. • NP = P iff the satisfiability problem is a P problem. NP Completeness
SAT is NP-complete (1) SAT is an NP algorithm. (2) SAT is NP-hard: • Every NP algorithm can be transformed in polynomial time to SAT [Horowitz 1998] such that SAT is satisfiable if and only if the answer for the original NP problem is “YES”. • That is, every NP problem SAT . • By (1) and (2), SAT is NP-complete. NP Completeness
Proof of NP-Completeness • To show that L’ is NP-complete (I)Prove that L’ is an NP problem. (II)Prove that L NPC, L' in NP is polynomialy reducible to L NP Completeness
x (OR) + (AND) - (NOT) Conjunctive Normal Form • Conjunctive Normal Form • Disjunctive Normal Form • 3-CNF • Each clause has exactly three distinct literal NP Completeness
3-CNF-SAT problem • 3-CNF-SAT is NPC problem? • Proof it is a NP problem • Proof SAT 3-CNF-SAT NP Completeness
NPC family NP Completeness
References • NPC http://en.wikipedia.org/wiki/NP_complete • List of NPC problems http://en.wikipedia.org/wiki/List_of_NP-complete_problems NP Completeness