In this chapter, we'll first clarify the definitions of these terms: NP, NP-hard, NP-complete, co-NP, P vs NP.
Before encountering this knowledge, I always thought these terms were very advanced and profound. Today, let's explore them together.
Review: P problems are the set of problems that can be solved in poly-time complexity.
Whether a problem belongs to NP is not about whether the problem is difficult to solve, but about verifying it! ** The core of NP is:
Given a candidate solution, can you "verify" its correctness in polynomial time?
This is the key point; we don't care whether it's easy to solve.
NP = Nondeterministic Polynomial-time.
Formal definition: A problem is NP if and only if
Every YES instance has a polynomial-length certificate, and this certificate can be verified in poly-time.
Def. In a graph
, we say that a set of nodes is an independent set if no two nodes in are joined by an edge.
That is: a subset of nodes in a graph G where no two nodes are joined by an edge.
Solving this problem is NP-complete (we will discuss this in more detail later; we won't concern ourselves with that now).
However, if someone gives you a set of points (candidates with k vertices), I can verify whether this set is IS in polytime.
Therefore, the Independent Set Problem is NP-complete.
Definition of a Clause:
Given n boolean variables
, a clause is a disjunction of terms , where
Essentially, it's just a bunch of variables that are ORed with 0 or 1.
The SAT Problem is defined as follows:
Given clauses
In essence, it asks whether it's possible to find an assignment that satisfies all clauses.
Clearly, this problem can also be verified in poly-time.
Therefore: NP = the set of all problems that can "verify YES instances" in polynomial time.
Solving may be difficult, but verification must be fast.
Problem
Given a graph, can we find k nodes that are connected in pairs?
certificate = a set of k vertices
certifier = check if all pairs of vertices are connected → O(k²)
In a graph, can we find a set of vertices that covers all edges? An edge is covered if one of its two ends belongs to the Vertex Cover.
certificate = selected set of vertices
certifier = check if all edges are covered → O(m)
Find a cyclic path in graph G, traversing each vertex once.
certificate = a permutation (path)
certifier = check if each vertex is visited once and a cycle is formed → O(n)
NP-hard = "At least as hard as the hardest problem in NP".
More formally:
NP-hard problems are those problems to which all NP problems can be poly-time reduced.
NP-hard does not require being in NP (because it may be unverifiable).
The most famous NP-hard non-NP problem is: The Halting Problem → Unverifiable, unsolvable.
The Halting Problem is one of the most fundamental results in theoretical computer science. It asks:
Given a program P and an input x, will P(x) eventually halt, or will it run forever?
Alan Turing proved in 1936 that there is no algorithm that can always answer this question correctly for all possible programs and inputs.
Therefore:
NP-complete
NP-hard is a larger set.
The complete and rigorous proof of whether a problem belongs to NP is at the end of this chapter: How to Prove a Problem Belongs to NP
NP-complete = NP
In other words:
A problem X is NP-complete if and only if:
X ∈ NP
All problems in NP can be poly-time reduced to X
These problems are the most difficult "representative problems" in NP.
Common NP-complete problems:
SAT
3SAT
CLIQUE
Independent Set
Vertex Cover
Hamiltonian Cycle
TSP (decision)
They are mutually reducible, therefore essentially of equal difficulty.

From the above, we know:
P = can be poly-time solved
NP = can be poly-time verified
Obviously:
But is:
P = NP?
Currently unknown.
[!important]
Current conclusion: Whether P equals NP is unknown!
However, most computer scientists believe:
P ≠ NP
What would happen if P = NP?
All NP-complete problems could be solved polytime.
Cryptography (RSA/ECC) would collapse.
Machine learning and optimization would experience a leap forward.
Search/scheduling/TSP problems could be solved instantaneously.
But currently, this problem remains unsolved and is one of the Seven Millennium Problems.
Step 1: List the candidates: i.e., the set of candidates (the set of things to be verified, easily understood through examples).
Step 2: Prove that the verification process is completed polytime.
The Sushi Express wants to implement a new feature, "order batching." The menu consists of a set of disired food items
This is a homework question for me. Of course, I won’t prove it here. HP-Hard, let's first prove that the Decision Version of the problem is NP.
Define the Decision Version
We define the decision version of the Sushi Batching problem as follows:
Input:
A set of food items
A collection of combos
A set of required items
A budget
Question:
Does there exist a subset of combos
Showing the Problem is in NP
A certificate can be a subset of combo indices
Compute
Compute the union
Verify that I have no duplicate indices.
These checks require only scanning sets and summing numbers, all of which take polynomial time. Thus the problem has an efficient certification and is in NP.
Problem
Again, first prove that the problem is NP.
Showing the Problem is NP
Certificate:
A certificate can be a subset of vertices
Certifier:
Given
Checks that
For every pair
There are at most
The proof should be straightforward by now. Proving a problem is NP is very simple; just state that the problem can be verified in poly-time.