NP-complete problems are a subset of the larger class of NP 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.
NP-complete problems are the hardest problems in the NP set.
A decision problem L is NP-complete if it follow the below two properties:
L is in NP (Any solution to NP-complete problems can be checked quickly, but no efficient solution is known).
Every problem in NP is reducible to L in polynomial time (Reduction is defined below).
A problem is NP-Hard if it obeys Property 2 above and need not obey Property 1. Therefore, a problem is NP-complete if it is both NP and NP-hard.
Decision vs Optimization Problems
NP-Completeness is defined for decision problems because their difficulty is easier to compare. In many cases, solving the decision version efficiently also helps solve the corresponding optimization problem using a polynomial number of calls.
NP-completeness is defined for decision problems.
Decision problems are easier to compare than optimization problems.
Polynomial-time solutions to decision problems can help solve optimization problems.
Optimization problems can be reduced to decision problems using multiple queries.
Hence, the complexity of decision problems reflects the complexity of optimization problems.
What is Reduction?
Let L1 and L2 be two decision problems. Suppose algorithm A2 solves L2. That is, if y is an input for L2 then algorithm A2 will answer Yes or No depending upon whether y belongs to L2 or not. The idea is to find a transformation from L1 to L2 so that algorithm A2 can be part of algorithm A1 to solve L1.
Learning reductions helps solve new problems using already solved ones.
Reductions save time and effort by reusing existing algorithms and library functions.
A new problem can be transformed into a known problem instead of writing new code.
Using taking the logarithm of edge weights the problem is reduced to a shortest path problem.
Dijkstra’s algorithm can then be used instead of developing a new solution.
How to prove that a given problem is NP-complete?
From the definition of NP-Complete, it seems difficult to prove that a problem L is NP-Complete.
By definition, we would need to show that every problem in NP can be reduced to L in polynomial time.
Fortunately, there is an easier method to prove NP-Completeness.
We take a known NP-Complete problem and reduce it to L.
If this reduction can be done in polynomial time, then L is NP-Complete.
This works due to the transitivity property of reduction.
If an NP-Complete problem reduces to L, then all NP problems can also be reduced to L in polynomial time.
What was the first problem proved as NP-Complete?
There must be some first NP-Complete problem proved by the definition of NP-Complete problems. SAT (Boolean satisfiability problem) is the first NP-Complete problem proved by Cook (See CLRS book for proof).
It is always useful to know about NP-Completeness even for engineers. Suppose you are asked to write an efficient algorithm to solve an extremely important problem for your company. After a lot of thinking, you can only come up exponential time approach which is impractical. If you don't know about NP-Completeness, you can only say that I could not come up with an efficient algorithm. If you know about NP-Completeness and prove that the problem is NP-complete, you can proudly say that the polynomial-time solution is unlikely to exist. If there is a polynomial-time solution possible, then that solution solves a big problem of computer science many scientists have been trying for years.
NP-Complete problems and their proof for NP-Completeness.