Outline
- The class `NP`
- Examples
- Quiz
- `NP`-completeness
The class `NP` - Some Intuitions
- Last Wednesday, we looked at the class `P` which consisted of those decision problems which could be decided in polynomial time.
- It happens that there are problems about which, if we knew some additional information, then we could decide them in polynomial time.
- For instance, given a graph `G` and a number `k`. It might be hard to determine if the graph `G` has a clique of size `k`.
- However, if instead, somebody gave us a subset of `k` nodes of `G`, and asked us if these form a clique in `G`, we could check it in polynomial time.
- It is interesting to try to formalize those problems for which, when given a certificate, we can efficiently verify this certificate's correctness.
- This class is called `NP`. On the next slide we will show how to formalize it.
The Definition of `NP`
Definition. A language `L subseteq {0, 1}^star` is in `NP` if there exists a polynomial `p: NN -> NN` and a polynomial time TM `M` (called the verifier for `L`)
such that for every `x in {0, 1}^star`,
`x in L iff exists u in {0, 1}^(p(|x|)) mbox( s. t. ) M(x,u) =1`
If `x in L` we call a `u in {0, 1}^(p(|x|))` such that `M(x,u) =1` a certificate.
Some examples
- INDEPENDENT SET - Given a graph `G` and a number `k`, can we find a subset of `k` nodes of `G` no two of which share an edge? It is in `NP` because we can guess a subset of `k` nodes (the exists quantifier in the definition of `NP` will correspond to the `k` nodes. These nodes can be represented by a string which is polynomial in the length of our representation of `G` and `k`) and then check in polynomial time if the nodes shares edges.
- TRAVELING SALESPERSON - Given a weighted graph `G` with nodes which we imagine are cities and edge weights which we imagine are the distances between cities, and a number `k`. Is there a path in the graph with the same start and end point which visits each node exactly once and which has total weight less than `k`? It is in `NP` because we can guess a path and then in polynomial time check if it works.
- SUBSET SUM - Given a list of `n` numbers: `A_1, A_2, ..., A_n` and a number `T`, decide if there is a subset of the numbers that sums to `T`. This is in `NP` because we can guess a subset of numbers and then verify in polynomial time that they sum to `T`.
- LINEAR PROGRAMMING - Given a list of `m` linear inequalities with rational coefficients over `n` variables `u_1, ... u_n` (i.e., `m` inequalities of the form `a_1u_1 + a_2u_2 + cdots +a_n u_n leq b` where the `a_i` and `b` are fraction `p/q` for some integers `p` and `q`), decide if there is an asssignment of rational numbers to the variables that satisfies all the inequalities. The certificate in this case is a guess of the values of the `u_i`'s. You might think a minute to try to see this could be polynomially bounded. This problem is actually known to be in `P` by the ellipsoid algorithm of Khachiyan.
More Examples
- 0/1 INTEGER PROGRAMMING - Given a list of `m` inequalities with rational coefficients over `n` variables `u_1`, ..`u_n`, find out if there is a 0-1 assignment to the variables that satisfies all the inequalities. Again, given a 0-1 assignment we can check polynomial time if it works.
- GRAPH ISOMORPHISM - Given two `n times n` adjacency matrices `M_1, M_2` decide if `M_1` and `M_2` define the same graph, up to renaming of vertices. The certificate is a permutation of `n` to `n` in this case.
- COMPOSITE NUMBERS - Given a number `N` decide if `N` is a composite (non-prime). A certificate would be two factors that multiply to be the number. This problem was shown in 2004 to be in `P`.
- FACTORING - Given three numbers `N`, `L`, `U` decide if `N` has a prime factor `p` in the in the interval `[L, U]`. The certificate is such a factor.
- CONNECTIVITY - Given a graph `G` and two vertices `s,t` in `G`, decide if `s` is connected to `t` in `G`. The certificate is just a path from `s` to `t`. In this case the problem is known to be in `P`.
Quiz
Which of the following statements is true?
- If `f(x), g(y)` are a primitive recursive functions, then `g(f(x))` will be a primitive recursive function.
- The r.e. sets are all decidable.
- Our `O(T log T)` universal simulation uses as alphabet `{\Delta, \square, 0, 1 }`.
The Relationship Between `P` and `NP`
- We do know some simple relationships between the class `P` and `NP`.
- In particular, let `mbox(EXP) := cup_(c > 1) DTIME(2^(n^c))`. We will show at some point that `P ne mbox(EXP)`.
- We also have:
Claim. `P subseteq NP subseteq EXP`.
Proof. (`P subseteq NP`) Suppose `L in P` is decided in polynomial-time by a TM `N`. Then `L in NP`, since we can take `N` as the machine `M` from the definition of `NP` and we can take our polynomial `p` from that definition to be the zero polynomial.
(`NP subseteq EXP`) If `L in NP` and `M`, `p()` are as in our definition for `NP`, and `x` is an input to `L` then we can enumerate in exponential time each of the `2^(O(p(|x|)))` strings `u` of length `p(|x|)` and use `M` to check whether `u` is a valid certificate for `x`. This `EXP` machine accepts iff such a `u` is ever found.
Nondeterministic Turing Machines
- The certificate definition of `NP` was not the original definition of the class `NP`.
- Instead, when `NP` was first defined, it was defined as the class of languages accepted by nondeterministic TMs (NDTM) in polynomial time.
- An NDTM is like a TM except that it has two transition functions `delta_0` and `delta_1`, and a special state `q_(a\c\cept)`.
- When an NDTM `M` computes, we imagine at each computational step it makes an arbitrary choice of which of these two transition functions to use.
- For every input `x` we say that `M(x)=1` if there exists some sequence of these choices (which we can nondeterministic choices of `M`) that would make `M` reach state `q_(a\c\cept)` on input `x`.
- Otherwise, if on every sequence of choices `M` on input `x`, `M` halts without ever entering state `q_(a\c\cept)`, we say `M(x) = 0`.
- We say that `M` runs in `T(n)` time if for every input `x in {0,1}^star` and every sequence of nondeterministic choices, `M` reaches the halting state or `q_(a\c\cept)` in fewer than `T(|x|)` steps.
Definition. For every function `T: NN -> NN` and `L subseteq {0,1}^star`, we say that `L in NTIME(T(n))` if there is a constant `c > 0` and a `c cdot T(n)`-time NDTM `M` such that for every `x in {0, 1}^star`, `x in L iff M(x) = 1`.
The Definitions Coincide
Theorem. `NP = cup_(c in NN)NTIME(n^c)`.
Proof. The main idea is that the sequence of nondeterministic choices made by an accepting computation of an NDTM can be viewed a certificate that the input is in the language, and vice-versa.
Suppose `p: NN -> NN` is a polynomial and `L` is decided by NDTM `N` that runs in time `p(n)`. For every `x in L`, there is a sequence of nondeterministic choices that make `N` reach `q_(a\c\cept)` on input `x`. We can use this sequence as a string `u` in `{0, 1}^(p(|x|))`. This certificate could be used by a deterministic polynomial time machine which simulates the actions of `N` using these choices and verifies that it would have entered `q_(a\c\cept)` after using the choices. Thus, `L in NP`.
Conversely, if `L in NP`, we can come up with an NDTM that decides `L` in the following manner: On input `x`, it uses its ability to make nondeterministic choices to write down on one of its work tapes a string `u` of length `p(|x|)`. Thereafter it runs the deterministic algorithm of the verifier `M` that was used on in the definition of `L in NP`, to check if this is a valid certificate on input `x`. If it is, it enters the state `q_(a\c\cept)`.
Reducibility and NP-completeness
- It turns out that you can show some problems in `NP` are at least as hard as any other problems in `NP`.
- INDEPENDENT SET is an example of such a problem.
- We now explore this property which can be defined using the notion of reduction.
Definition. A language `L in {0,1}^star` is polynomial-time Karp reducible to a language `L' subseteq {0, 1}^star`, denoted by `L le_(p) L'`, if there is a polynomial time computable function `f:{0,1}^star -> {0, 1}^star` such that for every `x in {0, 1}^star`, `x in L` iff `f(x) in L'`.
We say that `L'` is `NP`-hard if `L le_(p) L'` for every `L in NP`. We say that `L'` is `NP`-complete if `L'` is in `NP` and is `NP`-hard.
- Notice if `L'` is in `P` and `L \leq_p L'` then `L` is in `P`.
Properties of Reducibility
Theorem.
- If `L \leq_p L'` and `L' \leq_p L''`, then `L \leq_p L''`.
- If a language `L` is `NP`-hard and `L in P`, then `P = NP`.
- If a language `L` is `NP`-complete, then `L in P` iff `P =NP`.
Proof. (1) Follows because the runtime of the composition of two polynomial time function can be bounded by a polynomial. (2) and (3) Follow from the observation of the last slide.