NP-completeness Ch.34
The Holly Grail Three classes of problems: Class P: problems solvable in polynomial time Class NP: problems verifiable in polynomial time (i.e. “give me a solution and I can verify that it is correct”) Class NPC (NP-complete): problems that are NP and as “hard” as any problem in NP If any NPC problem can be solved in polynomial time, then they all can; but so far nobody found any solution …. There are many NPC problems that look very simple on surface NPC problems are rather common
Nature of NP-problems NP-complete problems are decision problems (i.e. the answer is “yes/no”) But usually optimization problems can be converted into decision problems
Examples of NP-complete problems Finding longest path between any two vertices in a graph Circuit satisfiability: given a boolean circuit of AND, OR and NOT gates, is it satisfiable 3-CNF satisfiability: Find out if there is a solution to a Boolean formula in conjuctive normal form that has 3 distinct “elements” for each OR e.g. (x1 or x2’ or x3) AND (x1 or x2 or x3) AND (x4 or x1 or x3’)
Example problems, cntd. Find clique of max size in a graph (clique is a subset of vertices, and each pair is connected by an edge) Find a hamiltonian cycle in a graph (a cycle that contains each vertex) Traveling salesman problem: find a hamiltonian cycle which ends at the starting vertex (i.e. visit all nodes exactly once and finish at the node you started from)
Practical Consequences If a problem is proven to be NP-complete, do NOT bother writing an algorithm to solve it exactly, because you will not be able to find the solution, most likely (nobody did so far, and people have been trying for hundreds of years; so if you do, you will be a very very famous person); or if you want an exact solution, it will be a naïve check of all possibilities and will run much longer than polynomial time…. Instead, solve the problem by approximations, or solve a special case that is tractable.