MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in
MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in
Problem Statement
Given A directed graph G = (V,E)
………………. P2
………………. P3
Hamiltonian Cycle Problem
• Draw edges from vij to vi,j+1
………………. P1
………………. P2
………………. P3
Hamiltonian Cycle Problem
• Draw edges from vi,j+1 to vi,j
………………. P1
………………. P2
………………. P3
Hamiltonian Cycle Problem
• 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
Add two extra nodes s and t. Define edges from s to v11 and v1b, from
vn1and vnb to t, and from t to s
………………. P1
………………. P2
………………. P3
t
Hamiltonian Cycle Problem
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 2n Hamiltonian cycles.
We have therefore modeled the n independent
choices of how to set each variable; if Pi is traversed
left to right, xi=1, else xi=0
Hamiltonian Cycle Problem
We now add nodes to model the clauses
Consider the clause C = (x1’ν x2 ν x3’)
………………. P1
………………. P2
………………. P3
t
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 !
Hamiltonian Cycle Problem
Consider an instance of 3-SAT having
4 variables : x1,x2 x3,x4
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
Hamiltonian Cycle Problem
Claim: 3-SAT instance is satisfiable if and only if
G has a Hamiltonian cycle
Proof: Part I
Given A satisfying assignment for the 3-SAT instance
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
Hamiltonian Cycle Problem
Part II
Given A Hamiltonian cycle in G.
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
Hamiltonian Cycle Problem
Obtain a Hamiltonian cycle on the
subgraph G – {c1,……ck} by removing
cj and adding ‘e’ as shown below
C1
s
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
Hamiltonian Cycle Problem
We now use this new cycle on the subgraph
to obtain the truth assignments for the
3-SAT instance.
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
Acknowledgements
• BIG Thanks to Sonika Arora