NP-Completeness
- This is from CLRS
- Most of the algorithms we have studied are polynomial time O(nk) where k is constant.
- Can all problems be solved in polynomial time?
- Clearly computing all permutations can not
- Some can't be done at all.
- The halting problem: Given a description of an arbitrary computer program, decide whether the program finishes running or continues to run forever.
- A creative proof
- So are there other classes of problems?
- Polynomial algorithms
- Class P
- as expressed above can be solved in O(nk) for any set of input.
- We will examine a class (or set) of problems called NP.
- Given a solution, the solution can be checked in polynomial time.
- Does P=NP?
- Unknown
- No one has been able to show this since the early 70s.
- Slight changes to problems may mean major changes in the complexity of finding the solution.
- The 0-1 knapsack problems asks what mix of items should be placed in a knapsack, of limited capacity, to maximize value.
- Each item has a different value and weight.
- This is in class NP
- Algorithm: Brute force, try everything.
- The fractional knapsack problem asks what mix of items should be placed in a knapsack, of limited capacity, to maximize value.
- Items may have different values.
- But all items are of the same size.
- This is in class P.
- Algorithm: Greedy take the most valuable items first.
- Given a directed graph G=(V,E).
- A Euler tour traverses each edge exactly once.
- Does an Euler tour exist?
- Fleury's Algorithm, (1883) solves this in O(|E|2), but better algorithms exist.
- So this problem is in class P.
- A Hamiltonian cycle visits each vertex (other than the first) exactly once.
- Determining the existence of a Hamiltonian cycle is in class NP.
- The difference between problems in class P and problems in class NP is verification.
- You can solve the Eulerian Path question for a given graph G in O(nk)
- You can not, as far as we know, solve the Hamiltonian Path question for a given graph G in O(nk)
- However, if you are given a path H, you can test to see if it is a Hamiltonian path in O(nk).
- Or you can verify a solution in polynomial time.
- Any problem in P is in NP.
- But is P⊆NP or is P⊂NP?
- NP-Complete
- This is the set of hardest problems in the class NP.
- A problem is in this set if EVERY OTHER PROBLEM in the set NP can be reduced to the problem in polynomial time.
- In other words:
- B is in NP-Complete if
- For every other problem A in the set NP
- Transform A to B in polynomial time.
- Solve B
- Transform the answer back from B to A in polynomial time.
- A solution to B provides a solution to A.
- If you can show that B is in P, then EVERYTHING in NP is in P, and P = NP
- On the other hand, if you can show that B is not in P, then EVERYTHING else in NP-Complete can not be in P, thus P ≠ NP.
- Read quote on 968
- Decision Problems
- Many hard problems are optimization problems.
- Like the knapsack problem.
- Much work in NP-Complete is with decision problems.
- Does a Hamiltonian path exist?
- Optimization problems can be cast as decision problems
- Can a solution be found with value k? (IE for 0-1 knapsack, can a value of k be loaded into the knapsack from the items?)
- Decision problems are easier than optimization problems.
- But if the decision problem is hard, the optimization problem is hard. (Otherwise, we would just optimize the question).
- And if the decision problem is easy, the optimization problem is probably easy as well.
- So the work we will do is in decision problems, not optimization problems.
- Reductions
- Or showing that a given problem is no more difficult than another problem.
- Consider only decision problems.