Complexity Classes
P
P refers to Polynomial, the complexity class of problems that are deemed to be tractable i.e. solved in worst-case polynomial time of or less. A P-class problem can be verified in polynomial time as well.
A P-Class problem will have the following Big-O time complexities:
- - Linear
- - Log
- - Loglinear
- - Polynomial
Examples
Link to source
- Determining whether a number is prime
- All searches and sorts
- Matrix Multiplication
NP
NP refers to Non-Deterministic Polynomial, the class of problems that are intractable to solve but can be verified reasonably. These set of problems have a worst-case time that is great than polynomial time i.e.
An NP-Class problem will have the following Big-O time complexities:
Examples
#todo List NP Problems that are neither NP-Complete nor NP-Hard
Link to source
NP-Complete
NP-Complete problems are an intersection of NP and NP-Hard problems. Therefore they must be verifiable in polynomial time (to be in NP) and is at least as hard as the hardest problem in NP (NP-Hard definition). All NP-Complete problems are related, and they can all become the same problem
Examples
Link to source
- TSP Decision Problem
- Knapsack Problem:
- Tower Of Hanoi:
- Determining whether a graph has Hamiltonian cycles or paths (subset of TSP):
- N-Queens Problem
NP-Hard
NP-Hard is a set of problems that cannot be solved in polynomial time and may or may not be verifiable in polynomial time. If an NP-Hard problem is solved, it can be used to solve every other NP problem.
Examples
Link to source
- The Optimal TSP problem
- Obtaining the chromatic number of a graph i.e Optimisation Graph Colouring
- The Halting Problem (NP-Hard ONLY)