daa-unit-IV
daa-unit-IV
Vidula V. Meshram
[email protected]
Department of Computer Engineering
1. Time-Space tradeoff
2. Tractable and Non-tractable Problems
3. Polynomial and non-polynomial problems
4. Deterministic and non-deterministic algorithms
5. P-class problems, NP-class of problems
6. Polynomial problem reduction
7. NP complete problems- Vertex cover and 3-SAT
8. NP hard problem - Hamiltonian cycle
1 1 1 1 1
logn 3.3 4.3 4.9 5.3
n 10 20 30 40
Tractable nlogn 33 86 147 212
Problems 100 400 900 1600
n2
Intractable 2n 1024 1 Million 1 Billion 1 Trillion
Problems (1Kilo)
Algorithm non-det-lin-search
1. j = choice (1:n)
2. If A[ j ] = x
{ write ( j ); success( );}
3. write (0); failure( );
I of L1 I’ Solution for I
Poly. Time Algorithm Poly. Time
transform for L2 transform
L1α L2 or L1 ≤ p L2
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
Department of Computer Engineering, VIIT, Pune-48
Unit IV : Intractable Problems and NP-Completeness
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:
First NP-Complete Problem CIRCUIT-SAT
SAT
CNF-SAT
CLIQUE SUBSET-SUM
VERTEX-COVER
HAM-CYCLE
TSP
Department of Computer Engineering, VIIT, Pune-48
Unit IV : Intractable Problems and NP-Completeness
NP-Hard Problems :
To prove : 1) CIRCUIT-SAT α Satisfiability or
2) Satisfiability is NP-complete
Proof :
Consider the following electronic digital circuit.
x1 x5
OR
x2
x6 OR
NOT x8
x6 x9 x10
OR
X3 x4 AND
NOT x4 AND x7
NP-Hard Problems :
• Thus the instance, I of satisfiability is converted into an instance I’ in 3-CNF form in
polynomial time.
• Therefore we can say that Satisfiability α 3-CNF satisfiability.
Part 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 :
Clique Decision Problem (CDP) :
• A maximal complete sub-graph of a graph G = (V, E) is a clique.
• The size of the clique is the number of vertices in it.
• Maximum Clique Problem is an optimization problem that has to determine the
size of a largest clique in G.
• The corresponding Decision Problem is to determine whether G has a clique of
size at least k for some given k.
• Let DClique(G, k) be a deterministic decision algorithm for the clique decision
problem. If the number of vertices in G is n, the size of max. clique in G can be
found by making several applications of Dclique. Dclique is used once for each k,
k = n, n-1, n-2, … until the output from Dclique is 1.
NP-Hard Problems :
Clique Decision Problem (CDP) :
• If the time complexity of Dclique is f(n), then the size of max clique can be found
in time ≤ n.f(n). Also if the size of max clique can be determined in time g(n), then the
decision problem can be solved in time g(n).
• Hence max clique problem can be solved in polynomial time iff clique decision problem can
be solved in polynomial time.
• There is no polynomial time deterministic algorithm for this problem. A naive
algorithm for determining whether a graph G = (V. E) with |V| vertices has a
clique of size k is to list all k-subsets of V, and check each one to see whether it
forms a clique. The running time of this algorithm is Ω(k 2C(|V|, k) which is
polynomial if k is constant. However in general, k could be near |V| / 2, in which
case the algorithm runs in super-polynomial time. Indeed an efficient algorithm for the
clique problem is unlikely to exist.
NP-Hard Problems :
Clique Decision Problem (CDP) :
Applications :
• Patterns in telecommunications traffic
• Design of error-correcting codes
• Fault diagnosis on large multiprocessor systems
• Tiling geometry problems (Keller’s conjecture)
• Computer Vision and Pattern Recognition
• Graph theoretic approaches have also found widespread
application in modern Biological Research
NP-Hard Problems :
Clique Decision Problem (CDP) : Non-deterministic algorithm
Algorithm CDP(G, n, k)
// G is an adjacency matrix, |V| = n and clique size is k
// Algorithm finds whether there exists a clique of size ≥ k in a graph G
{ S = Ф; // initially S is empty
for (i=1; i ≤ k; i++)
{ t = Choice (1, n);
if (t Є S) Failure();
S = S U {t} // add t to S
}
// At this point S contains k distinct vertices
for (all pairs (i, j) such that vertices i and j) Є S and i ≠ j)
if ((i, j) is not an edge of G then Failure();
Success();
} // In general if k = (n/2),
Time Complexity is O((n/2)+(n/2)2) = O(n2) = O(m), m = input length.
NP-Hard Problems :
Clique Decision Problem (CDP) :
Theorem : CNF-satisfiability α Clique Decision problem.
Proof :
Let F = ٨ Ci be a propositional formula in CNF. Let xi be the
1<= i<= k
variable in F such that 1 ≤ i≤ n. We can construct a graph G = (V, E), from F such that G has a clique of
size at least k iff F is satisfiable.
For any F, G = (V, E) is defined as follows:
V = {<σ, i> | σ is a literal in clause Ci } and
E = {(<σ, i>, < δ, j> ) | i ≠ j, and σ ≠ δ}
Example : Consider F = (x1 V x2 V x3) ٨ (¬ x1 V ¬ x2 V ¬ x3)
F is true when x1 = true and x2 = false
NP-Hard Problems :
Clique Decision Problem (CDP) :
Theorem : CNF-satisfiability α Clique Decision problem.
Proof :
Let F = ٨ Ci be a propositional formula in CNF. Let xi be the
1<= i<= k
variable in F such that 1 ≤ i≤ n. We can construct a graph G = (V, E), from F such that G has a clique of
size at least k iff F is satisfiable.
For any F, G = (V, E) is defined as follows:
V = {<σ, i> | σ is a literal in clause Ci } and
E = {(<σ, i>, < δ, j> ) | i ≠ j, and σ ≠ δ}
Example : Consider F = (x1 V x2 V x3) ٨ (¬ x1 V ¬ x2 V ¬ x3)
F is true when x1 = true and x2 = false
C F
< x3,1> < ¬ x3, 2>
u v
w
z
y x
u v
w
z
y x
A Hamiltonian cycle in a graph is a cycle that visits each vertex exactly once
Problem Statement
………………. P2
………………. P3
………………. P1
………………. P2
………………. P3
………………. P1
………………. P2
………………. P3
For each i = 1,2,……..,n-1, define edges from vi1 to vi+1,1 and to vi+1,b.
Also, define edges from vib to vi+1,1 and vi+1,b
………………. P1
………………. P2
………………. P3
………………. P1
………………. P2
………………. P3
Observations:
Any Hamiltonian cycle must use the edge (t,s)
Each Pi can either be traversed left to right or
right to left. This gives rise to 2 n Hamiltonian
cycles.
We have therefore modeled the n independent
choices of how to set each variable; if P i is
traversed left to right, xi=1, else xi=0
s C
………………. P1
………………. P2
………………. P3
t
Department of Computer Engineering, VIIT, Pune-48
Hamiltonian Cycle Problem
In general
We define a node cj for each clause Cj.
In each path Pi, positions 2j-1 and 2j are reserved for
variables that participate in clause Cj
If Cj contains xi, add edges (vi,2j-1 , cj)and (cj , vi,2j)
If Cj contains xi’, add edges (vi,2j , cj)and (cj, vi,2j-1)
Gadget constructed !
1 2 3 4 5 6 P1
1 2 3 4 5 6 P2
1 2 3 4 5 6 P3
1 2 3 4 5 6 P4
t
C3
C2
1 2 3 4 5 6 P1
1 2 3 4 5 6 P2
1 2 3 4 5 6 P3
1 2 3 4 5 6 P4
t
C3
C2
Part II
Why?
1 2 3 4 5 6 P1
1 2 3 4 5 6 P2
1 2 3 4 5 6 P3
1 2 3 4 5 6 P4
t
C3
C2
1 2 3 4 5 6 P1
1 2 3 4 5 6 P2
1 2 3 4 5 6 P3
1 2 3 4 5 6 P4
t
C3
C2
YES !
Since the larger cycle visited each clause node cj, at least one Pi
was traversed in the right direction relative to the node cj