Complexity Classes
The complexity classes that we shall discuss (informally now and
formally later) are
1. P
The class P consists of those problems that are “solvable” in
polynomial time. To be precise, they are problems that can be
solved in time O(nk ) for some constant k, where n is the size
of the input to the problem.
• For example:- The 2-CNF problem can be solved in
polynomial time w.r.t of the input parameters.
Complexity Classes
P
2. NP
The class NP (Nondeterministic Polynomial) consists of those
problems that are “verifiable” in polynomial time.
If we were somehow given a “certificate” of a solution, then we
could verify that the certificate is correct in time polynomial in
the size of the input to the problem.
• For example, given an integer N and factor f as a certificate,
we can verify in polynomial time w.r.t to size of N, that
GCD(N, f ) is greater than 1 or not.
If the GCD is equal to 1, then f is not a factor of N.
If the GCD is equal to f , then f is a factor of N.
Complexity Classes
P
As another example, for 3-CNF satisfiability, a certificate would be
an assignment of values to variables.
We could check in polynomial time that this assignment satisfies the
boolean formula or not.
F = (x1 ∨ ¬x2 ∨ x3 ) ∧ (¬x1 ∨ x3 ∨ x4 )
is a 3-CNF formula.
For this formula, let’s say one assignment for (x1 , x2 , x3 , x4 ) is
(1,1,0,0) and another assignment is (1,1,1,1).
The first assignment evaluates to false but the second assignment
evaluates the 3-CNF to true. Both these assignments are certificates
which can be tested for correctness in polynomial time.
Complexity Classes
P
One can view classes P and NP in the following way as well.
▶ P consists of problems for which you can find a certificate and
check the validity of a certificate in polynomial time.
▶ NP consists of problems for which you can check the validity of
a certificate in polynomial time.
Thus, any problem A which is in class P is also automatically in
class NP.
If we abuse the notation to mean that P and NP are sets of
problems which lie in class P and NP respectively, then
A ∈ P =⇒ A ∈ NP P ⊆ NP
The million dollar question (both literally and figuratively) is
whether P = NP or P ⊂ NP.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
An abstract problem Q to be a binary relation on a set I of
problem instances and a set S of problem solutions.
For example, in case of SHORTEST-PATH
▶ an instance is a triple consisting of a graph and two vertices.
▶ a solution is a sequence of vertices in the graph, with perhaps
the empty sequence denoting that no path exists
.
The problem SHORTEST-PATH sitself is the relation that
associates each instance of a graph and two vertices with a shortest
path in the graph that connects the two vertices.
Many abstract problems are not decision problems, but rather
optimization problems, which require some value to be minimized or
maximized. However, we can usually recast an optimization problem
as a decision problem that is no harder.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
In order for a computer program to solve an abstract problem, we
must represent problem instances in a way that the program
understands.
An encoding of a set S of abstract objects is a mapping e from S
to the set of binary strings.
Till now whatever algorithms we have studied we notice that
computer algorithm that “solves” some abstract decision problem
actually takes an encoding of a problem instance as input.
The codomain of the encoding need not be binary strings; any set of
strings consisting of finitely many symbols (and least 2 symbols) will
do.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
We call a problem whose instance set is the set of binary strings a
concrete problem.
We say that an algorithm solves a concrete problem in time
O(T (n)) time if, when it is provided a problem instance i of length
n = |i|, the algorithm can produce the solution in O(T (n)) time.
A concrete problem is polynomial-time solvable, therefore, if there
exists an algorithm to solve it in time O(nk ) for some constant k.
The complexity class P is the set of concrete decision problems that
are polynomial-time solvable.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
We would like to extend the definition of polynomial-time solvability
from concrete problems to abstract problems by using encodings as
the bridge, but we would like the definition to be
independent of any particular encoding.
That is, the efficiency of solving a problem should not depend on
how the problem is encoded.
Unfortunately, it depends quite heavily on the encoding.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
Suppose that an integer k is to be provided as the sole input to an
algorithm A, and suppose that the running time of the A is Θ(k).
▶ If the integer k is provided in unary—a string of k 1s—then
the running time of the algorithm is linear Θ(n) in size of input
(if n denotes size of input) which is polynomial time.
▶ If we use the more natural binary representation of the integer
k, however, then the input length is n = ⌊lg k⌋ + 1. In this
case, the running time of the algorithm is Θ(k) = Θ(2n ),
which is exponential in the size of the input.
Thus, depending on the encoding, the algorithm runs in either
polynomial or superpolynomial time.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
In practice, if we rule out “expensive” encodings such as unary ones,
the actual encoding of a problem makes little difference to whether
the problem can be solved in polynomial time.
▶ For example, representing integers in base 3 instead of base 2
has no effect on whether a problem is solvable in polynomial
time, since we can convert an integer represented in base 3 to
an integer represented in base 2 in polynomial time.
Thus, whether an abstract problem has its instances encoded in
binary or base 3 does not affect whether it is polynomial-time
solvable or not; but not if instances are encoded in unary.
From now, we shall assume that the encoding of the input is in
binary representation or in some other encoding e which can be
converted in binary representation in polynomial time with respect
to size of input in binary representation.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
We need to use some terms from Formal Languages Theory.
▶ An alphabet Σ is a finite set of symbols.
▶ A string is any combination of symbols present in Σ
▶ A language L over Σ is any set of strings made up of symbols
from Σ.
For example, if we define alphabet Σ = {0, 1}. The combinations
such as 00,01,1011 . . . are strings. One can define language L1 to
set of strings which are binary representations of powers of two.
Then L1 = {1, 10, 100, 1000 . . .}.
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
Since languages are basically sets, we can apply various set-theoretic
operations on them.
1. Union
L = L1 ∪ L2
2. Intersection
L = L1 ∩ L2
3. Kleene Star/Closure
L∗ = {ϵ} ∪ L ∪ L2 ∪ L3 . . .
4. Complement
L = Σ∗ − L
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
From the point of view of language theory, the set of instances for
any decision problem Q is simply the set Σ∗ , where Σ = {0, 1}.
Since Q is entirely characterized by those problem instances that
produce a 1 (yes) answer, we can view Q as a language L over
Σ = {0, 1}, where
L = {x ∈ Σ∗ : Q(x) = 1}
We say that an algorithm A accepts(rejects) a string x ∈ Σ∗ if,
given input x, the algorithm’s output A(x) is 1(0).
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
The language accepted by an algorithm A is the set of strings
L = {x ∈ {0, 1}∗ A(x) = 1} that is, the set of strings that the
algorithm accepts.
A language L is decided by an algorithm A if every binary string in
L is accepted by A and every binary string not in L is rejected by A.
A language L is accepted(decided) in polynomial time by an
algorithm A if it is accepted (decided) by A and if in addition there
exists a constant k such that for any length-n string x ∈ L,
algorithm A accepts(decides) x in time O(nk ).
Abstract Problems
Complexity Classes Encoding and Concrete Problems
P Why use binary encoding? Case against Unary
Usage of Formal Language Theory
Now, we can define the complexity class P as
P = {L ⊆ {0, 1}∗ : There exists an algorithm AL that decides
L in polynomial time}