NP-Completeness
This note is part of my learning notes on Data Structures & Algorithms.
Classes of Problems
Polynomial Time (P)
The class P consists of those problems that are solvable in polynomial time.
More specifically, they are problems that can be solved in time for some constant , where is the size of the input to the problem.
Nondeterministic Polynomial Time (NP)
NP is the class of decision problems for which a given solution can be verified as correct or incorrect in polynomial time by a deterministic Turing machine.
A decision problem is in NP if there exists a polynomial-time verifier such that for every instance , there exists a certificate (with size polynomial in the size of ) for which .
Any problem in P is also in NP, since if a problem is in P then we can solve it in polynomial time without even being supplied a certificate.
NP-Complete
NP-Complete (NPC) problems are the hardest problems in NP in the sense that every problem in NP can be reduced to them in polynomial time. If an NP-Complete problem can be solved in polynomial time, then every problem in NP can also be solved in polynomial time.
A decision problem is NP-Complete if
- For every problem , there exists a polynomial time reduction from to
NP-Hard
NP-Hard problems are at least as hard as the hardest problems in NP. An NP-Hard problem does not have to be in NP (i.e., it does not have to be a decision problem).
A decision problem is NP-Hard if
- For every problem , there exists a polynomial time reduction from to
Strongly NP-hard
A problem is strongly NP-hard if it remains NP-hard even when all the numerical parameters are bounded by a polynomial in the length of the input. Essentially, even small, compact instances of the problem are difficult to solve.
Weakly NP-hard
A problem is weakly NP-hard if it is NP-hard in general but may be solvable in polynomial time when its numerical parameters are bounded by a polynomial in the length of the input.
Relationships
- NP NP-Hard: Every problem in NP is reducible to every problem in NP-Hard.
- NP-Complete NP-Hard: Every NP-Complete problem is also NP-Hard.
- NP-Complete NP: Every NP-Complete problem is also in NP.
- P NP: Every problem that can be solved in polynomial time (P) can also be verified in polynomial time (NP).
- P ≠ NP (conjectured): It’s an open question in computer science whether every problem whose solution can be verified in polynomial time can also be solved in polynomial time.
Examples
- P: Merge Sort, Quick Sort, Dijkstra’s problem
- NP: Hamiltonian Path, Subset Sum, Sudoku
- NP-Complete: Traveling Salesman Problem
- Strongly NP-Hard: 3SAT (Boolean satisfiability) problem
- Weakly NP-Hard: Knapsack problem