2. Complexity Classes
Complexity Class is a set of problems with related complexity. These classes
help scientists in classifying difficulties according to the amount of time and
space needed to solve problems and verify the solutions.
TYPES OF COMPLEXITY CLASSES
P Class
NP Class
NP-hard
NP-complete
3. P Class
The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic
machine (our computers) in polynomial time.
Features
The solution to P problems is easy to find.
P is often a class of computational problems that are solvable and tractable. Tractable
means that the problems can be solved in theory as well as in practice. But the
problems that can be solved in theory but not in practice are known as intractable.
Example:
Merge sort
Finding the maximum matching.
Calculating the greatest common divisor.
4. NP Class
The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of decision
problems that can be solved by a non-deterministic machine (note that our computers are
deterministic) in polynomial time.
Features:
The solutions of the NP class might be hard to find since they are being solved by a non-deterministic
machine but the solutions are easy to verify.
Problems of NP can be verified by a deterministic machine in polynomial time.
Example:
Boolean Satisfiability Problem (SAT).
Hamiltonian Path Problem.
Graph coloring.
5. NP-Hard
An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of problems such
that every problem in NP reduces to NP-hard.
Features:
All NP-hard problems are not in NP.
It takes a long time to check them. This means if a solution for an NP-hard problem is given then it
takes a long time to check whether it is right or not.
A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-time reduction from L
to A.
Example:
Halting problem.
Qualified Boolean formulas.
No Hamiltonian cycle.
6. NP-Complete
NP-complete problems are a subset of the larger class of NP (nondeterministic polynomial time)
problems. NP problems are a class of computational problems that can be solved in polynomial time
by a non-deterministic machine and can be verified in polynomial time by a deterministic Machine. A
problem L in NP is NP-complete if all other problems in NP can be reduced to L in polynomial time. If
any NP-complete problem can be solved in polynomial time, then every problem in NP can be solved
in polynomial time.
Example:
Hamiltonian Cycle.
Satisfiability.
Vertex cover