Complexity Class
Complexity Class
• Intractable Problems :
Problems that can be solved in exponential time, O(kn) (solved using
nondeterministic polynomial time algorithms)
These problems comes under the complexity class NP (Nondeterministic
Polynomial time)
Deterministic and Nondeterministic Algorithms
• Deterministic Algorithms • Nondeterministic Algorithms
Algorithms contains the result of Algorithms contain operations
every operation is uniquely whose outcome are not uniquely
defined. defined but are limited to a certain
set of possibilities.
Algorithm Lsearch(A,n,key) Algorithm Lsearch(A,n,key)
{ {
for i= 1 to n do i= choice(1,n);
if a[i]=key then if a[i]=key then
{ write i; return();} { write i; success();}
write 0; else{write 0; Failure();}
} }
Decision Problems and Optimization Problems
NPH
NP
P
NP Complete (NPC)
A problem L is said to be in NP Complete if and only if it satisfies the
following two conditions.
1. L is in NP class
2. Every problem in NP is polynomial time reducible to L
Explanation:
The problem is to check whether a clique of size K exists in G.
graph G = (V, E) with vertex cover V − V ‘ = {w, z}. complement G with clique V ‘ = {u, v, x, y}.
To prove this reduction is correct, we need to show two things: • If there is a solution to
VERTEX-COVER(G, k), then there must be a solution to CLIQUE(G, |V | − k)
Count =0
for each vertex v in V’
remove all edges adjacent to v from set E
increment count by 1
if count = k and E is empty
the given solution is correct
else
the given solution is wrong
This can be done in polynomial time. Thus the vertex cover problem
is in the class NP
Proof that vertex cover is NP complete
Proof that vertex cover is NP Hard –
To prove that Vertex Cover is NP Hard, we take some
problem which has already been proven to be NP Hard,
and show that this problem can be reduced to the Vertex
Cover problem.
For this, consider the Clique problem, which is NP
Complete (and hence NP Hard).
F=
Clause 2
𝑎 b c
a a
𝑏 b
𝑐 c
Clause 1 Clause 3
4. Clique Problem (NP complete Problem)
F is satisfiable iff G has a clique of size k= 3.
A clique of k corresponds to assignment of true to k literals in k
different clauses. b
2
2
5
5
1 3
1 3
4
4
Graph G with Clique V’={1,2,3} Graph with vertex cover V-V’= {4,5}
6. Vertex Cover Problem is NP-complete
• The reduction algorithm takes as input an instance (G, k) of the clique
problem.
• It computes the complement of G, which is easily done in polynomial
time.
• The output of the reduction algorithm is the instance , of the vertex-
cover problem.
• To complete the proof, we show that this transformation is indeed a
reduction: the graph G has a clique of size k if and only if the graph
has a vertex cover of size |V | - k.
6. Vertex Cover Problem is NP-complete
• Suppose that G has a clique V' V with |V'| = k.
• We claim that V - V' is a vertex cover in .
• Let (u, v) be any edge in Ē.
• Then, (u, v) ∉ E, which implies that at least one of u or v does not
belong to V', since every pair of vertices in V' is connected by an edge
of E.
• Equivalently, at least one of u or v is in V - V', which means that edge
(u, v) is covered by V - V'. Since (u, v) was chosen arbitrarily from Ē,
every edge of Ē is covered by a vertex in V - V'. Hence, the set V - V',
which has size |V | - k, forms a vertex cover for .
6. Vertex Cover Problem is NP-complete
• So we have proven that CLIQUE can be reduced to VERTEX-COVER and
the reduction be done in polynomial time.
• That is to generate the complement graph, we only need a single scan over
all pairs of vertices in the original graph, and generate an edge if there is not
edge between any pair.
• This operation can be done in polynomial time.
• Since CLIQUE can be reduced to VERTEX-COVER in polynomial time, and CLIQUE
is NPH so, VERTEX-COVER∈ NPH