140 likes | 412 Views
Introduction to NP-Completeness. Tahir Azim. The Downside of Computers. Many problems can be solved in linear time or polynomial time But there are also problems that can’t be solved so easily… Moral: know thy problem!. P vs NP. P = Problems that can be solved in polynomial time
E N D
Introduction to NP-Completeness Tahir Azim
The Downside of Computers • Many problems can be solved in linear time or polynomial time • But there are also problems that can’t be solved so easily… • Moral: know thy problem!
P vs NP • P = Problems that can be solved in polynomial time • NP = Problems for which you can test the correctness of a solution in polynomial time • Example? • Solutions in P are also in NP • But not necessarily vice versa • Undecidable Problems: Cannot be solved by a computer. Picture Courtesy: Wikipedia
Examples of hard problems • Long simple paths: Given a graph G, vertices s and t, and a number k, does there exist a path from s to t with at least k edges and no cycles? • In NP. Why? • In P? No! • RSA: In NP, but not in P! • Chess-Playing: In NP, but not in P! • Halting Problem
yes if Q(Q) halts no otherwise run forever if Q(Q) halts halt if Q(Q) runs forever Unsolvability of the halting problem • Suppose P solves variant of halting problem • On input Q, assume P(Q) = • Build program D • D(Q) = • Does this make sense? What can D(D) do? • If D(D) halts, then D(D) runs forever. • If D(D) runs forever, then D(D) halts. • CONTRADICTION: program P must not exist.
How to solve such problems? • Heuristics • Approximation • Use the exponential time solution anyway • Add more assumptions to simplify it
Is P=NP? • If it's always easy to check a solution, should it also be easy to find the solution? • Most famous open problem in theoretical CS • Most expect it to be false, but there is no proof
NP-Complete Problems (NPC) • The hardest of all problems in NP • NP-hard: A problem that is at least as hard as any problem in NP • Does not necessarily have to be in NP, e.g. the Halting Problem • A problem is said to be NP-complete if it is • (i) in NP • and (ii), it is NP-hard
How to prove if a problem Y is NP-hard • By showing that an instance X of an NP-hard problem can be reduced to Y in polynomial time • Informally, a problem A is reducible to B if A can be solved by using B as a sub-routine • i.e. if B returns “yes”, then A also returns yes. • The idea is the following: • If Y was not NP-hard, then X could be solved “easily” by using Y • Therefore, X would no longer be a hard problem • X is NP-hard • Therefore, Y is NP-hard.
More common method (slightly different) • Generally, a slightly different approach is used • A problem Y is said to be NP-complete if it is • (i) in NP • and, (ii) an instance of an NP-complete problem can be reduced to Y in polynomial time • Notation: X <p Y, Ǝ X Ɛ NPC • Where did the first NP-complete problem come from? • Stephen Cook (1971) showed that SAT is an NP-complete problem from first principles
Examples of various NP-complete problems and their reductions • Additional Problems: • Graph Coloring • Karp's 21 NP-complete problems (1972) Picture Courtesy: Wikipedia
More of the good stuff… • If you can prove one NP-complete problem to be solvable in polynomial time, you can prove that all others are also solvable in polynomial time • One way to prove P=NP! • Follow up: • Wikipedia, of course But check your sources! Don’t trust Wikipedia!