Complexity Classes
Complexity Classes
Introduction – Complexity
Classes
• For some problems there are known polynomial-time algorithms;
• For others, we have proofs that no polynomial-time algorithm can exist;
• But for others, we have only exponential-time algorithms but no proof that no
polynomial-time algorithm can exist.
• Despite the holes in our knowledge, Computer Scientists have made some
progress.
• Computer Scientists have been able to find relationships between some of the
third kind of problem. – E.g. They have been able to show that some problems
are, in some sense, equivalent in complexity. (They do this using reductions.)
• This isn’t as good as closing the gap for these problems.
• But it is significant because all these problems will stand or fall together, which
makes them particularly worthy of further research effort.
2
Tractable vs. Intractable Problems or
Polynomial time vs Non-polynomial time problem
3
Introduction Contd…
• In Computer Science, many problems are solved where the
objective is to maximize or minimize some values, whereas in
other problems we try to find whether there is a solution or
not. Hence, the problems can be categorized as follows −
• Optimization Problem - Optimization problems are those for
which the objective is to maximize or minimize some values.
(e.g.) Finding the minimum number of colors needed to color a
given graph.
• Decision Problem - There are many problems for which the
answer is a Yes or a No. These types of problems are known
as decision problems. .(e.g.) whether a given graph can be
colored by only 4-colors.
Decision Problems
• Researchers who work in Complexity Theory often concentrate on
decision problems.
• A decision problem is one whose return values are either YES or NO
(or true or false, or 0 or 1).
• Why concentrate on these—
• For many non-decision problems, there are related decision
problems. E.g. the TSP Search and Decision Problems. A non-
decision problem (such as the TSP Search Problem) can often be
turned into a decision problem by introducing a parameter k and
asking if there is an answer that costs at least or at most k.
5
• NOTE- Suppose you’ve a decision problem and an algorithm A that
solves that decision problem.
• We’ll say that algorithm A accepts input x if it returns YES.
• We’ll say that algorithm A rejects input x if it returns NO.
6
The Complexity Class P
• Definition: The complexity class P is the set of all decision problems that can
be solved with worst-case polynomial time-complexity.
• In other words, a problem is in the class P if it is a decision problem and there
exists an algorithm that solves any instance of size n in O(n k ) time, for some
integer k.
• So P is just the set of tractable decision problems: the decision problems for
which we have polynomial-time algorithms.
7
The Complexity Class NP
• The second class of decision problems that we look at is called NP,
which stands for non-deterministically polynomial.
• The definition of NP involves the idea of a non-deterministic
algorithm.
• Definition: The complexity class NP is the set of all decision problems
that can be non-deterministically accepted in worst-case polynomial
time.
8
Deterministic and non-deterministic
algorithms
A deterministic algorithm is one where, given a particular
input, the algorithm will always produce the same output and
follow the same sequence of states. It operates under the
principle of predictability and consistency. The outcome of a
deterministic algorithm can be precisely determined based on
its input.
Some of the terms related to the non-deterministic algorithm are defined below:
• choice(X): chooses any value randomly from the set X.
• failure(): denotes the unsuccessful solution.
• success(): The solution is successful and the current thread terminates.
11
P ⊆ NP
The definition of NP allows for the inclusion of problems that may not be in P. But it may turn out that
there are no such problems and that P = NP. We don’t know which of these is the case. We know P ⊆
NP. But we don’t know whether P ⊂ NP or P = NP. The problems that are in NP but not in P are ones
that we’re not sure about: –
•There is no known polynomial-time algorithm;
12
P vs NP ??
So there are two possibilities
OR
But this gives Computer Scientists a clear line of attack. It makes sense to focus
efforts on the NP-complete problems: they all stand or fall together.
https://youtu.be/pQsdygaYcE4?si=9sqVxqDNOV5JDN9R
13
NP-Hard Problems
• We say that a decision problem Pi is NP-hard if every problem in NP is polynomial
time reducible to Pi .
• In symbols,
• Pi is NP-hard if, for every Pj ∈ NP,
Pj → Pi , in polynomial time.
• Note that this doesn’t require Pi to be in NP.
• Highly informally, it means that Pi is ‘as hard as’ all the problems in NP.
• If Pi can be solved in polynomial-time, then so can all problems in NP.
• Equivalently, if any problem in NP is ever proved intractable (i.e. no proof that
there cannot be a polynomial-time algorithm), then Pi must also be intractable.14
NP-Complete Problems
• We say that a decision problem Pi is NP-complete if
• – it is NP-hard and
• – it is also in the class NP itself.
• In symbols, Pi is NP-complete if Pi is NP-hard and Pi ∈ NP
• Highly informally, it means that Pi is one of the hardest problems in
NP.
15
NP-Complete Problems
• So the NP-complete problems form a set of problems that may or may not be
intractable but, whether intractable or not, are all, in some sense, of equivalent
complexity.
• If anyone ever shows that an NP-complete problem is tractable, then
• – every NP-complete problem is also tractable
• – indeed, every problem in NP is tractable and so
P = NP.
16
• The list below contains some well-known problems that are NP-complete when expressed as
decision problems.