# Chapter 7: Time Complexity

## Chapter 7.3, The Class NP

### Definitions

• A verifier for a language A is an algorithm V, where A = {w | V accepts <w, c> for some string c}. We measure the time of a verifier only in terms of the length of w, so a polynomial time verifier runs in polynomial time in the length of w. A language A is polynomially verifiable if it has a polynomial time verifier.
• NP is the class of languages that have polynomial time verifiers.
• NTIME(t(n)) = {L | L is a language decided by an O(t(n)) time nondeterministic Turing Machine}. Thus, NP = ∪k NTIME(nk).

### Examples of NP Problems

• HAMPATH = {<G, s, t> | G is a directed graph with a Hamiltonian path from s to t}.
• CLIQUE = {<G, k> | G is an undirected graph with a k-clique}.
• SUBSET-SUM = {<S, t> | S = {x1, ... xk} and for some {y1, ... ym} ⊆ {x1, ... xk} we have Σ yi = t}.

### Proof that SUBSET-SUM is in NP

```  N = "On input <S, t>:
1. Nondeterministically select a subset c of the numbers in S.
2. Test whether c is a collection of numbers that sum to t.
3. If the test passes, accept; otherwise, reject."

OR

V = "On input <<S, t>, c>:
1. Test whether c is a collection of numbers that sum to t.
2. Test whether S contains all the numbers in c.
3. If both pass, accept; otherwise, reject."
```

### Active Learning

• Consider 3COLOR = {<G> | G is colorable with 3 colors}.
• Prove that 3COLOR is in NP.