Module V
Module V
Complexity Classes
P Problem
Number of steps is bounded by a polynomial.
Produce correct answer for any input string of length n in at most n k steps, where
k is s constant independent of n.
e.g., Merge sort, Quick sort etc.
NP Problem
Verifiable in polynomial time by a nondeterministic Turing machine. (A non
deterministic Turing machine is a "parallel" Turing machine which can take many
computational paths simultaneously, with the restriction that the parallel Turing
machines cannot communicate.)
A P-problem is always also NP. If a problem is known to be NP, and a solution to
the problem is somehow known, then demonstrating the correctness of the
solution can always be reduced to a single P verification.
If P and NP are not equivalent, then the solution of NP-problems requires (in the
worst case) an exhaustive search.
NP- hard
An algorithm for solving the problem can be translated into one for solving any
other NP-problem.
NP-Complete
A problem which is both NP and NP-hard.
Hardest of NP problems.
NP Complete Examples
1. Circuit Satisfiability
Given a Boolean combinational circuit composed of AND, OR and NOT gates, is
the circuit satisfiable (output is 1).
The above problem cannot be solved in polynomial time but can be verified. Hence
it belong to NP category.
2. Formula Satisfiablility
Given a boolean formula circuit, is the formula satisfiable (output is 1).
Given right certificates, can be verified in polynomial time. Hence
problem is NP.
To prove this to be NP-complete, reduce CIRCUIT-SAT to this.
CIRCUIT-SAT p FORMULA-SAT
Steps
i. Name all output lines.
3. 3 CNF Satisfiability
Given a boolean formula is in CNF, if it ie expressed as an AND of
clauses, each of which is the OR of one or more literals. A boolean
formula is in 3-CNF, if each clause has exactly three literals. And
satisfiable if output is 1.
Steps
= ((x1 x2) (( x1 x3) x4)) x2
y1 y2 x2 y1 (y2 x2)
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 0
0 1 1 1
0 1 0 0
1 0 1 1
0 0 0 1
1 ’’
= (y1 y2 x2) (y1 y2 x2) (y1 y2 x2) ( y1
y2 x2)
Similarly find all i’’’s and find the AND of all i’’’s.
iii. If all clauses has three distinct literals, select all. Else
a. If all clause contain two distinct literal, introduce new
literal p. Add two more clauses
(l1 l2 p) and (l1 l2 p)
b. If all clause contain only one literal, introduce two new
literals p and q. Add four more clauses
(l1 p q), (l1 p q), (l1 p q)and (l1 p q)
4. Clique problem
Clique in an undirected graph G = (V, E) is a subset V’ V of vertices,
each pair of which is connected by an edge in E. In other words, a clique is
a complete graph. The size of a clique is the number of vertices it contains.
The clique problem is the optimization problem of finding a clique of
maximum size in a given graph.
CLIQUE = { <G, k> : G is a graph with a clique of size k }
To prove this to be NP-complete, reduce 3-CNF-SAT to this. 3-CNF-SAT
CLIQUE.
Steps
= ( x1 x2 x3 ) ( x1 x2 x3 ) ( x1 x2 x3 ) x1 = 0, x2 =
0, x3 =1
Please share lecture notes and other study materials that you have
with us. It will help a lot of other students. Send your contributions to
[email protected]
iii. Each C r contains at least one literal lir that is assigned a, each such
literal corresponds to vertex vir. Pick one such literal from each clause
yields a set V’ of k vertices.
Steps
i. Given G = (V, E), V’ V where V’ is a clique.
ii. Find complement of G, G’ = (V, E ), where E = {(u,v) : u,v V,
u v and (u,v) E }
as graph formed by all edges not in G
iii. Take an edge (u,v) in G’. Either u or v or both are not present
in V’. Hence vertices not present in V’ form cover of G’.
Assumptions
1. No clasuse contains variable and its completment ( x i and xi )
2. Include all variables in every clause
Steps
1. Add 2 numbers for each varioables and clauses.
2. Form numbers consisting of n+k digits, where n is the number of varioables and k is
the number of clauses
3. Form target as a number of the form 111…444…. Where number of 1’s equal to
number of variables and number of 4’s eqaul to number of clauses.
S’ can be created as :
1. If xi = 1 pick vi else vi’.
In above example select v1’, v2’, v3.
They will add 1’s to digit corresponding to variables and maximum of 3 to
digits corresponding to variables.
2. Select appropriate slack Si’s to make sum as 4 for clauses.
In above example select S1, S1’, S2, S2’, S3, S4, S4’.
Hence we have S’ = { v1’, v2’, v3, S1, S1 ’, S2, S2’, S3, S4, S4’}
Please share lecture notes and other study materials that you have
with us. It will help a lot of other students. Send your contributions to
[email protected]