NPComplete Problems NP and P What is NP
NP-Complete Problems
NP and P • What is NP? • NP is the set of all decision problems (question with yes-or-no answer) for which the 'yes'-answers can be verified in polynomial time (O(n^k) where n is the problem size, and k is a constant) by a deterministic Turing machine. Polynomial time is sometimes used as the definition of fast or quickly. • What is P? • P is the set of all decision problems which can be solved in polynomial time by a deterministic Turing machine. Since it can solve in polynomial time, it can also be verified in polynomial time. Therefore P is a subset of NP.
• Class of “P” Problems Class P consists of (decision) problems that are solvable in polynomial time • Polynomial-time algorithms o Worst-case running time is O(nk), for some constant k • Examples of polynomial time: o O(n 2), O(n 3), O(1), O(n lg n) • Examples of non-polynomial time: o O(2 n), O(n!) 3
• Class of “NP” Problems Class NP consists of problems that could be solved by NP algorithms o i. e. , verifiable in polynomial time • If we were given a “certificate” of a solution, we could verify that the certificate is correct in time polynomial to the size of the input • Warning: NP does not mean “non-polynomial” 4
NP-Complete • What is NP-Complete? • A problem x that is in NP is also in NP-Complete if and only if every other problem in NP can be quickly (ie. in polynomial time) transformed into x. In other words: • x is in NP, and • Every problem in NP is reducible to x • So what makes NP-Complete so interesting is that if any one of the NP-Complete problems was to be solved quickly then all NP problems can be solved quickly
NP-Hard • What is NP-Hard? • NP-Hard are problems that are at least as hard as the hardest problems in NP. Note that NP-Complete problems are also NP-hard. However not all NP-hard problems are NP (or even a decision problem), despite having 'NP' as a prefix. That is the NP in NP-hard does not mean 'non-deterministic polynomial time'. Yes this is confusing but its usage is entrenched and unlikely to change.
Tractable/Intractable Problems • Problems in P are also called tractable • Problems not in P are intractable or unsolvable o Can be solved in reasonable time only for small inputs o Or, can not be solved at all • Are non-polynomial algorithms always worst than polynomial algorithms? - n 1, 000 is technically tractable, but really impossible - nlog log n is technically intractable, but easy 7
Reductions • Reduction is a way of saying that one problem is “easier” than another. • We say that problem A is easier than problem B, (i. e. , we write “A B”) if we can solve A using the algorithm that solves B. • Idea: transform the inputs of A to inputs of B f Problem A 8 Problem B yes no
Polynomial Reductions • Given two problems A, B, we say that A is polynomially reducible to B (A p B) if: 1. There exists a function f that converts the input of A to inputs of B in polynomial time 2. 9 A(i) = YES B(f(i)) = YES
NP-Complete Problems
Traveling Salesman
5 -Clique
Hamiltonian Path
Map Coloring
Vertex Cover (VC) • Given a graph and an integer k, is there a collection of k vertices such that each edge is connected to one of the vertices in the collection?
- Slides: 15