50LecComplexity
50LecComplexity
Definition 2 (The class P). A decision problem belongs to the complexity class P if there exists a polynomial-
time algorithm solving that decision problem.
Unfortunately, the world is not nice, and not all decision problems come with a polynomial-time algorithm.
We cannot say that these problems belong to the class P, so we must have another class in which to place
these problems. While we can define such a class in a few ways, we will use the following definition in this
course.
Definition 3 (The class NP). A decision problem belongs to the complexity class NP if there exists a
verification algorithm A and two polynomial expressions p1 and p2 such that
1. For all inputs x and y, A(x, y) runs in time p1 (|x|);
2. For all instances x of the decision problem for which the answer is “yes”, there exists a string y with
|y| ≤ p2 (|x|) such that A(x, y) outputs “yes”; and
CSCI 550: Approximation Algorithms
Lecture 2, Fall 2021 Page 2
3. For all instances x of the decision problem for which the answer is “no”, and for all strings y with
|y| ≤ p2 (|x|), A(x, y) outputs “no”.
The definition of the class NP we use here is sometimes referred to as the “verifier-based” definition. Here,
the algorithm A takes as input the problem instance x and a string y, and then verifies that y is a “proof”
for x; that is, if x corresponds to a “yes” answer, then y encodes the answer itself, and if x corresponds to a
“no” answer, then no valid proof string y exists. The first condition of our definition ensures that A is able
to verify its input in polynomial time. In addition, the statement |y| ≤ p2 (|x|) in conditions 2 and 3 ensures
that y is a short proof for x, or a proof whose length is upper-bounded by some polynomial in the size of
the instance.
If you take away one thing from this lecture, let it be this:
NP does not stand for “non-polynomial”!
In a machine-centric context, the N in NP stands for “nondeterministic”. This stems from the fact that a
problem in NP can be solved by a nondeterministic Turing machine in polynomial time. By contrast, our
“verifier” algorithm is entirely deterministic. Even though it cannot actually solve the problem, it can at
least check whether a claimed solution is correct.
There are some known relationships between the classes P and NP. For example, clearly P ⊆ NP, since any
decision problem that can be solved in polynomial time can also have its solution verified in polynomial
time. On the other hand, proving (or disproving) the other direction of the inclusion is a notoriously difficult
problem.1
All in all, here’s how we generally think the complexity world looks at the moment (assuming P 6= NP):
NP
2 Reductions
Occasionally, we may have a deep understanding of the complexity or difficulty of one decision problem, and
we may come across another decision problem that resembles the first problem in some way. For example,
recall that we discussed the (unweighted) set cover problem in our previous lecture. As it turns out, there
exists another problem that is very similar to the set cover problem:
Vertex-Cover
Given: an undirected graph G = (V, E) and an integer k
Determine: a subset of vertices S ⊆ V such that |S| ≤ k and, if (u, v) ∈ E, then either u ∈ S, v ∈ S,
or both
If, in the set cover problem, we want to know whether we can find a collection of k subsets that cover all
elements of a ground set, then in the vertex cover problem we want to know whether we can find a subset
of k vertices that covers at least one endpoint of every edge in the graph.
Indeed, the vertex cover problem and the set cover problem appear to be so similar that one might reasonably
think that we can model an instance of the vertex cover problem in terms of an instance of the set cover
1 If you have a correct solution to this problem, please let me know.
CSCI 550: Approximation Algorithms
Lecture 2, Fall 2021 Page 3
problem. This is indeed true: if we have a “black box” decider that solves instances of the set cover problem,
then we can solve the vertex cover problem in the following way:
• Take an instance {G = (V, E), k} of the vertex cover problem.
• Create an instance of the set cover problem as follows:
– Take the ground set of elements, E, to be the set of edges E;
– Take each subset Sv to contain all edges e ∈ E incident to vertex v ∈ V ; and
– Take the integer k to be unchanged.
• Give the instance of the set cover problem to the “black box” decider.
Thus, there exists a set cover of size at most k if and only if there exists a vertex cover of size at most k.
We can generalize this idea of modelling instances of one problem as instances of another problem using the
notion of a reduction. Specifically, in this course, we would like our reductions to be efficient; that is, to run
in polynomial time.
Definition 4 (Polynomial-time reduction). Given two decision problems A and B, we say that there exists a
polynomial-time reduction from A to B (or “A reduces to B”) if there exists some polynomial-time algorithm
that takes an instance of A as input and produces an instance of B as output, such that the transformed
instance has the same output as the original instance.
In other terms, if A reduces to B, then we can transform every instance x of A to an instance f (x) of B.
Moreover, since the transformed instance has the same output as the original instance, we can conclude that
f (x) ∈ B if and only if x ∈ A. Thus, we can use our transformation algorithm together with our “black
box” decider for B to get an answer for our instance of A.
Diagrammatically, we can visualize a polynomial-time reduction from A to B in the following way:
Decider for A
Theorem 5. If A ≤P
m B and B ∈ P, then A ∈ P.
Proof Sketch. If we are able to both apply the reduction from A to B in polynomial time and run the decider
for B in polynomial time, then the overall decider for A also runs in polynomial time.
Theorem 6. If A ≤P
m B and B ∈ NP, then A ∈ NP.
Proof Sketch. After applying the reduction from A to B, we are able to use a verifier for instances of B to
verify instances of A.
These two theorems tell us that, if we know to which complexity class a decision problem B belongs, and if
we have a polynomial-time reduction from another decision problem A to B, then we can conclude that A
belongs to the same complexity class.
The class NP is central to the study of complexity theory. As such, it has been investigated in depth, and a
number of “NP-like” classes have been defined. The first such class we will introduce is the class NP-hard,
which contains decision problems whose difficulty is on par with those problems in NP itself.
Definition 7 (NP-hard). A decision problem A is NP-hard if, for every decision problem B ∈ NP, there
exists a polynomial-time reduction B ≤P
m A.
Since we can reduce any decision problem in NP to an NP-hard decision problem A, we can informally
characterize A as being at least as difficult as the most difficult decision problem in NP.
We can equivalently view an NP-hard decision problem A as a problem for which there exists an oracle 2 to
solve A, and we can use this oracle for A to solve any problem B ∈ NP in polynomial time.
Note from our earlier definition that an NP-hard decision problem does not necessarily need to be in NP
itself! If we know additionally that A belongs to the class NP, then it falls into a particular subclass at the
intersection of NP and NP-hard, which we call NP-complete.
Proof. We require the fact that polynomial-time reductions are transitive: that is, for three decision problems
X, Y , and Z, if X ≤P P
m Y and Y ≤m Z, then X ≤m Z.
P
Since B is NP-complete, we know that for all decision problems C ∈ NP, there exists a polynomial-time
reduction C ≤P P
m B. Additionally, we know by our hypothesis that B ≤m A. By the transitivity of reductions,
P
we therefore have that C ≤m A for all decision problems C ∈ NP, meaning that A is NP-hard. Since A is
additionally in NP, we conclude that A is NP-complete.
If we know an example of an NP-complete decision problem B, then using this result, we can easily show
that another decision problem A is NP-complete: all we need to do is show that A ∈ NP, and then find a
reduction B ≤Pm A.
2 An oracle is a special machine that is capable of solving its problem in only one computational step.
CSCI 550: Approximation Algorithms
Lecture 2, Fall 2021 Page 5
Let’s now establish the hardness of our two decision problems, Vertex-Cover and Set-Cover.
Proof Sketch. We first show that Vertex-Cover is in NP. If we are given a subset of vertices S, a verifier
can check that the subset is of size at most k and that the subset contains at least one endpoint of every
edge in the graph.
We can show that Vertex-Cover is NP-complete by constructing a reduction from the well-known NP-
complete problem 3-Satisfiability to Vertex-Cover. However, we omit that here.
Proof. We first show that Set-Cover is in NP. If we are given a collection of subsets Si , a verifier can check
that the collection contains at most k subsets and that the union of all subsets is equal to the ground set E.
To show that Set-Cover is NP-complete, we use our earlier reduction from Vertex-Cover to Set-Cover.
Since Vertex-Cover is NP-complete and there exists a reduction from it to Set-Cover, we can conclude
that Set-Cover is also NP-complete.
Lastly, taking these two new classes into account, here’s our expanded view of the complexity world:
NP-hard
NPC
NP
P