0% found this document useful (0 votes)
29 views30 pages

MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in

The document summarizes the NP-completeness of the Hamiltonian cycle problem. It begins by defining a Hamiltonian cycle and stating the problem of determining if a graph contains one. It then explains that while the problem is in NP, it is NP-complete. This is proven by showing a reduction from the NP-complete 3-SAT problem to the Hamiltonian cycle problem. Specifically, a graph construction is provided that models truth assignments in a 3-SAT formula as Hamiltonian cycles in the graph.

Uploaded by

max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views30 pages

MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in

The document summarizes the NP-completeness of the Hamiltonian cycle problem. It begins by defining a Hamiltonian cycle and stating the problem of determining if a graph contains one. It then explains that while the problem is in NP, it is NP-complete. This is proven by showing a reduction from the NP-complete 3-SAT problem to the Hamiltonian cycle problem. Specifically, a graph construction is provided that models truth assignments in a 3-SAT formula as Hamiltonian cycles in the graph.

Uploaded by

max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

MCS 312: NP Completeness

and Approximation algorithms


Instructor
Neelima Gupta
[email protected]
Table of Contents
• Hamiltonian Cycle
Hamiltonian Cycle Problem
A Hamiltonian cycle in a graph is a cycle
that visits each vertex exactly once

Problem Statement
Given A directed graph G = (V,E)

To Find If the graph contains a Hamiltonian


cycle
Hamiltonian Cycle Problem
Hamiltonian Cycle Problem is
NP-Complete

Hamiltonian Cycle Problem is in NP.


Given a directed graph G=(V,E), and a
certificate containing an ordered list of vertices on
a Hamiltonian Cycle. It can be verified
in polynomial time that the list contains each vertex
exactly once and that each consecutive pair in the
ordering is joined by an edge.
Hamiltonian Cycle Problem
Hamiltonian Cycle Problem is NP Hard

3-SAT ≤p Hamiltonian Cycle

We begin with an arbitrary instance of 3-


SAT having variables x1,…….,xn and
clauses C1,…….,Ck

We model one by one, the 2n different ways in which


variables can assume assignments, and the
constraints imposed by clauses.
Hamiltonian Cycle Problem
To correspond to the 2n truth assignments,
we describe a graph containing 2n different
Hamiltonian cycles.

The graph is constructed as follows:

Construct n paths P1,…….,Pn.


• Each Pi consists of nodes vi1,….., vib,
where b = 2k (k being the number of clauses)
………………. P1

………………. 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’)

What is the interpretation of the clause?


The path P1 should be traversed right to left, or
P2 should be traversed left to right, or P3 right
to left.
We add a node that does this
s C

………………. 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

3 clauses C1 : (x1 v x2 v x3’)


C2 : (x2’ v x3 v x4)
C3 : (x1’ v x2 v x4’)
Hamiltonian Cycle Problem
We reduce the given instance as follows:
n = 4 k = 3 b= 2*3 = 6

Construct 4 paths P1, P2, P3, P4


P1 consists of nodes v1,1, v1,2 ,…….., v1,6
P2 consists of nodes v2,1, v2,2 ,…….., v2,6
P3 consists of nodes v3,1, v3,2 ,…….., v3,6
P4 consists of nodes v4,1, v4,2 ,…….., v4,6
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
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

If xi = 1, traverse Pi left to right, else right to left.


Since each clause Cj is satisfied by the assignment,
there has to be at least one path Pi that moves in the
right direction to be able to cover node cj. This Pi can be
spliced into the tour there via edges incident on vi,2j-1 and
vi,2j
Hamiltonian Cycle Problem
Let us try to verify this with our example

Given A satisfying assignment for 3-SAT, say x1 =


1 x2 = 0 x 3 = 1 x 4 = 0

Let us check out a corresponding Hamiltonian


cycle
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
Part II
Given A Hamiltonian cycle in G.

Observe that if the cycle enters a node cj on


an edge from vi,2j-1 it must depart on an edge
to vi,2j.
Why?
Hamiltonian Cycle Problem
Because otherwise, the tour will not be able
to cover this node while still maintaining the
Hamiltonian property

Similarly, if the path enters from vi,2j, it has to


depart immediately to vi,2j-1.
Hamiltonian Cycle Problem
However, in some situations it may so happen that the path
enters cj from the first (or last) node of Pi and departs at the
first (or last) node of Pi+1.

In either case the following holds true:

The nodes immediately before and after any cj


in the cycle are joined by an edge in G, say e.

Let us consider the following Hamiltonian cycle


given on our graph
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
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.

If it traverses Pi left to right, set xi =1, else


set xi = 0.

We therefore get the following assignments:


x1 = 1 x2 = 0 x3 = 0 x4 = 1
Hamiltonian Cycle Problem
Can we claim that the assignment thus
determined would satisfy all clauses.

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

You might also like