\mathcal {P} and \mathcal {NP} [00VK]
- December 2, 2026
Motivation [00VM]
- December 2, 2026
Often, problems which seem hard to solve can nonetheless be easy to verify if we are handed a (potential) solution. For example, consider the IND-SET problem. We don’t yet know how hard it is to solve, but if someone hands you a set which they claim is an independent set of size \leq k, it is easy to verify whether it has the desired size and is, in fact, an independent set—just check each pair of vertices in the set to see whether they are connected by an edge. 3-SAT is similar: if someone hands you a variable assignment, all you have to do is plug it in and evaluate the clauses to see whether they are all satisfied.
Let’s be a bit more formal. We will suppose that the input to a problem is encoded as a binary string s. Formally, the “size” of the input will now be the number of bits, n = |s|. We will also identify a decision problem D with the set of all inputs s for which the answer should be “yes”. The problem then boils down to deciding whether a given bitstring s is contained in D or not. (This is another reason why studying decision problems is particularly nice.)
Definition Solve [00VN]
- December 2, 2026
An algorithm A solves a decision problem D if for all binary strings s, A(s) = \mathsf {T} iff s \in D. (Remember that we are identifying decision problems with the set of inputs for which the answer is \mathsf {T}.)
(Really, to be completely formal, we would need to identify an “algorithm” with some concrete model of computation, typically a Turing machine; but we will leave that level of formality to a Theory of Computation course.)
The class \mathcal {P} [00VS]
- December 2, 2026
Definition Polynomial time [00VO]
- December 2, 2026
If there is a polynomial p(n) such that A(s) always terminates in at most p(|s|) steps, we say A is a polynomial-time algorithm.
Definition \mathcal {P} [00VP]
- December 2, 2026
We define \mathcal {P} as the set of decision problems D solvable in polynomial time. That is, D \in \mathcal {P} if there exists some polynomial-time algorithm A which solves D.
Remark \mathcal {P} is problems [00VR]
- December 2, 2026
Note that \mathcal {P} is a set of problems, not a set of algorithms; it is the set of all problems which can be solved by some polynomial-time algorithm. For example, it does not make sense to say that Dijkstra's Algorithm is in \mathcal {P}; but it does make sense to say that the \mathsf {SHORTEST}-\mathsf {PATH} problem is in \mathcal {P}, since it can be solved by Dijkstra's Algorithm (which, as we know, is a polynomial-time algorithm).
Remark Why \mathcal {P}? [00VQ]
- December 2, 2026
Why focus on \mathcal {P}? As mentioned previously, we typically take polynomial-time as our definition of "feasible". There is both a theoretical and a practical reason for this. The theoretical reason is that the set of polynomials is closed under many natural operations. For example, if p(n) and q(n) are polynomials, then p(n) + q(n), p(n)q(n), and even p(q(n)) are all polynomials as well. If we have two algorithms which take time p(n) and q(n) respectively, then p(n) + q(n) represents the time to run the two algorithms in sequence; p(n)q(n) represents the time to run one nested inside the other; and even p(q(n)) corresponds to a natural operation on algorithms which we will encounter shortly. So if we focus on algorithms in \mathcal {P}, we can combine them in many natural ways and still remain in \mathcal {P}.
This would be a bad reason if it were only theoretically nice but did not correspond to reality very well. However, polynomial time corresponds well to what is feasible in practice. Most real polynomial-time algorithms have relatively small exponents; the biggest power I have ever seen in an algorithm which is actually used in practice is n^6. And there are many cases where a small tweak is all that separates a problem from being solvable in something like \Theta (n^2) time to requiring \Theta (2^n) time. That is, problems don't "degrade gracefully" from feasible to infeasible; there often seems to be a sharp divide where problems suddenly jump from having a nice, efficient, polynomial-time solution to having only exponential-time solutions.
The class \mathcal {NP} [00VT]
- December 2, 2026
Motivation [00VU]
- December 2, 2026
Now let’s formally define what it means to be able to verify the solution to a decision problem. The idea is that we need some sort of extra information to verify a positive answer to a decision problem. For example, given some large graph, if someone were to claim that there was an independent set of size \geq 20, you would challenge them to prove it to you by showing you the independent set. Given an actual set of vertices, it would be easy for you to check that the set has size \geq 20 and also that no two vertices in the set have an edge between them. Conversely, if there is no independent set of that size, then no one is going to be able to fool you by giving you some weird set of vertices. The extra information required to verify a solution is called a certificate.
Definition Polynomial-time certifier [00VV]
- December 2, 2026
An algorithm B is a polynomial-time certifier for a decision problem D if:
- B is a polynomial-time algorithm taking some inputs s and t
- There is a polynomial p such that for all bitstrings s, we have s \in D if and only if there is some bitstring t (called a certificate) with |t| \leq p(|s|) and B(s,t) = \mathsf {T}.
In other words, s \in D if and only if there is a (not too big) certificate “proving” it, which can be efficiently checked. That is, if the answer for the input s is supposed to be \mathsf {T}, then there is a certificate t that proves it: the certifier algorithm B, when run on s and t, will return \mathsf {T}. Conversely, if s \notin D, there is no t that works: B will never return \mathsf {T} for a certificate t unless s really is in D.
Example Polnomial-time certifier for IND-SET [00VW]
- December 2, 2026
For example, again thinking about IND-SET, s is of course a description of a graph G and a number k; a certificate t is simply a list of vertices S; the algorithm B checks whether |S| \geq k and whether each pair of vertices in S is not connected by an edge in G. This takes something like \Theta (|S|^2) time which is clearly polynomial in the size of the graph, since |S| \leq |V|.
Definition \mathcal {NP} [00VX]
- December 2, 2026
\mathcal {NP} is defined as the set of all decision problems which have a polynomial-time certifier.
Example \mathcal {NP} problems so far [00VZ]
- December 2, 2026
For example, 3-SAT, VERTEX-COVER, and IND-SET are all in \mathcal {NP} according to our discussion above.
Remark \mathcal {NP} = nondeterminism [00W0]
- December 2, 2026
\mathcal {NP} stands for “nondeterministic polynomial time”. The idea is that if we could make nondeterministic choices (i.e. choose multiple things at once and try them in parallel), we could solve any \mathcal {NP} problem in polynomial time: just nondeterministically make all possible choices for the certificate t and check them all at the same time.
\mathcal {P} vs \mathcal {NP} [00W1]
- December 2, 2026
What is the relationship between \mathcal {P} and \mathcal {NP}? We can first observe that:
Theorem \mathcal {P} \subseteq \mathcal {NP} [00W2]
- December 2, 2026
Proof.
- December 2, 2026
Question Does \mathcal {P} = \mathcal {NP}? [00W3]
- December 2, 2026
The question of whether \mathcal {P} = \mathcal {NP} is literally worth $1 million (it is one of the seven “Millenium Prize Problems” published by the Clay Mathematics Institute). It seems too good to be true, and most believe the answer is no. But this seems extremely difficult to prove.
Remark [00W4]
- December 2, 2026
We now understand the technical definition of the famous P vs NP problem; but what is not yet obvious is why this problem is interesting. To understand that, we must first build up some machinery around the idea of reducing one problem to another.