Complexity Theory
Complexity Theory
What is an algorithm?
It is a well defined procedure which will take set of values as
input and which will produce set of values of values as
output.
OR
• It is a combination of sequence of finite steps to solve the
problem.
Input Output
Properties of algorithm
It should produce at least one output.
It should take zero or more numbers of input.
Every steps in algorithm should be unambiguous.
It should produce the output within the finite amount of
time.
It should be language independent
For same input it should produce same output at any point of
time.
Rate of growth
Time Complexity Name Example
1 Constant Finding maximum or
minimum element from the
sorted array
logn Logarithmic Finding an element in sorted
array
n Linear Finding an element in
unsorted array
Procedure Procedure
with without
Algorithm Algorithm
Deterministic Nondeterministic
Machine Machine
INPUT ALGORITHM
Complexity Class
In computer science , in order to understand the problem for
which solution are not there , the problems are divided into
classes and we call them as complexity class.
In complexity theory, a complexity class is a set of problems
with related complexity.
It is the branch of Theory of Computation that studies the
resource required during computation to solve given
problem.
P-Class NP-Class
NP-Complete
NP-Hard
P class
The complexity class P is the set of decision problem that can
be solved by deterministic machine in polynomial time ( P
stands for polynomial time).
P class problem are set of problems whose solutions are easy
to find.
In computer science we say problem is easy when we can
solve the problem in polynomial time.
NP-Class
The complexity class NP(NP stands for non –deterministic
polynomial time) is the set of decision problems that can be
solved by non-deterministic machine in polynomial time.
NP class problem refers to set of problems whose solution
are hard to find but easy to verify.
Easy to verify means verification in polynomial time.
Easy to verify if answer is ‘YES’.
How to verify:
I/P: Graph with n vertices.
Question: Does G contains Hamiltonian cycle or not?
1
Prover verifier
YES
2 3 4
HOW
5 6 7
YES
Verification done in O(n)
times.
Polynomial time reduction
Let A is known problem and B is unknown problem.
If B is polynomial reducible to A
B ≤p A then B is also known problem.
Important observation:
NP
X
This type of problem is hard to solve and hard
to verify also.
Y Y
NP-Complete
A problem Y is NP-complete iff It is a part of both NP-Hard
and NP.
A problem Y is said to be NP-Complete iff
X ≤p Y, for all X belongs to NP and Y belongs to NP.
NP
X
This type of problem is hard to solve but easy
to verify .
Y
Cont…
How to show that a given decision problem Z is NPC ?
a) Show that Z belongs to NP
b) Select a known NPC problem Y
c) Construct a transformation Y ≤p Z
Relation between NPH and NPC
All NP- complete is NP-Hard but all NP-Hard is not NP-
Complete.
NP-HARD
NP
NP-complete