Unit 6 TOC
Unit 6 TOC
Algorithm non-det-lin-search
1. j = choice (1:n)
2. If A[ j ] = x
{ write ( j ); success( );}
3. write (0); failure( );
Deterministic vs Non-deterministic Algorithms contd … :
Example-2 : Non-deterministic Sorting Algorithm :
• Using Deterministic algorithm it takes O(nlogn) time
• Using Non-deterministic algorithm it takes O(n) time.
Algorithm Non-det-sort (A, n)
// sorts n positive integers. B[ ] is an auxiliary array.
{ for i = 1 to n do // Initialize aux. array B
B[i] = 0;
for i = 1 to n do // Non-det step decides the rank of the
{ j = choice (1, n); // input number in unit time
if B[ j] ≠ 0 then failure ( );
B [ j] = A[i];
}
for i = 1 to n-1 do // verification
if B[i] > B[i+1] then failure( );
write (B[1:n]);
success ( );
}
Decision Problem & Optimization Problem / Algorithm :
5 10
1 2
8 6 8 13
Graph G = (V,E)
V = {1, 2, 3, 4}
20 10 15 9
4 3
12 9
NP-Hard problems :
• A problem L is said to be NP Hard problem if and only if
satisfiability α L
Algorithm DKP(p,w,n,m,r,x)
{ W = 0; P = 0;
for i = 1 to n do
{ x[i] = choice (0, 1)
W = W + w[i]*x[i]; P = P + p[i] *x[i];
}
if ((W > m) or (P < r) then failure
else success();
}
Time Complexity of DKP = O(n).
Satisfiability :
• Literal : A literal is either a Boolean variable or its negation, Ex.
a,⌐ a
• Clause : A clause is a literal or a disjunction of literals or a
conjunction of literals. Ex. (p V ⌐q V r), (p ٨ q ٨ r)
• CNF : Boolean formula is in Conjunctive Normal Form (CNF)
iff it is represented as ٨Ci , where Ci are clauses each represented
as V lij
1<= i<= k and 1<= j<= n
All NP-hard decision problems that we shall discuss here are NP-
Complete and this can be shown by exhibiting a polynomial time
non-deterministic algorithm for L2
NP-Hard Problems : Reduction of problem
Reduction of L1 to L2 :
I of L1 I‟ Solution for I
Poly. Time Algorithm Poly. Time
transform for L2 transform
L1α L2 or L1 ≤ p L2
NP-Complete Problems : Proof by Reduction
Lemma : If L2 is a problem (language) such that L1 α L2 for
some L1 Є NP-Complete (or NPC) then L2 is
NP-Hard. Further if L2 Є NP then L2 Є NPC
The structure of NP-completeness proofs:
CIRCUIT-SAT
First NP-Complete Problem
SAT
CNF-SAT
CLIQUE SUBSET-SUM
VERTEX-COVER
HAM-CYCLE
TSP
NP-Hard Problems :
To prove : 1) CIRCUIT-SAT α Satisfiability or
2) Satisfiability is NP-complete
Proof :
Consider the following electronic digital circuit.
x1 OR x5
x2
OR
x6
NOT x6 x8
OR x9 x10
AND
X3 x4 x7
NOT AND
x4 x7
NP-Hard Problems :
To prove : 1) CIRCUIT-SAT α Satisfiability or
2) Satisfiability is NP-complete
Proof contd… :
Reducing circuit satisfiability to formula satisfiability:
Proof (2) :
• But we also know that Satisfiability is NP-Hard, therefore
we can say that 3-CNF Satisfiability is also NP-Hard.
• We can verify in polynomial time the certificate of 3-CNF
satisfiability. Hence 3-CNF Satisfiability is NP as well
• Hence 3-CNF Satisfiability is NP-Complete.
NP-Hard Problems :
Node Cover Decision Problem (NCDP):
A set S, a subset of V, is a node cover for graph G = (V, E) if
and only if all edges in E are incident to at least one vertex
in S. The size |S| of the cover is the number of vertices in S.
Example:
1 2
5 4
u v
w
z
y x
Unit IV : Complexity Theory
NP-Hard Problems :
Node Cover Decision Problem (NCDP):
Example : Reducing CLIQUE to VERTEX-COVER
b) An undirected graph G‟ = (V, E‟) with node cover V-V‟ = {w, z}
u v
w
z
y x