CS 637: Mathematics-II

Lecture 15: 3SAT to Hamiltonian Cycle Reduction

Reduction Goal

Source and Target Problems

\[ \operatorname{3SAT} = \{\varphi : \varphi \text{ is a satisfiable 3-CNF formula}\} \] \[ \operatorname{DHC} = \{\langle G \rangle : G \text{ is a directed graph with a directed Hamiltonian cycle}\}. \]

Today we build a polynomial-time map \(\varphi \mapsto G_{\varphi}\) such that

\[ \varphi \in \operatorname{3SAT} \iff G_{\varphi} \in \operatorname{DHC}. \]

High-Level Idea

  • Each variable gadget forces the Hamiltonian cycle to choose one of two consistent traversals.
  • Those two traversals encode \(x_i = \text{true}\) or \(x_i = \text{false}\).
  • Clause gadgets can be visited only through a literal that is made available by the chosen traversal.
  • Thus the cycle exists exactly when every clause has at least one satisfied literal.

Why Hamiltonian Constructions Look Complicated

For independent set or clique reductions, a solution is just a selected subset. For Hamiltonian cycle, a solution must visit every vertex exactly once and return to the start. So the reduction must enforce a very rigid global traversal pattern.

Most textbook proofs first show \[ \operatorname{3SAT} \le_p \operatorname{Directed\ Hamiltonian\ Cycle}, \] and then use a standard gadget conversion from directed Hamiltonian cycle to the undirected Hamiltonian cycle problem.

Variable and Clause Gadgets

Variable Gadget

For each variable \(x_i\), construct a directed path \[ p_{i,0}, p_{i,1}, p_{i,2}, \dots, p_{i,3m+2}, \] so each variable gadget has exactly \(3m+3\) vertices.

\[ \text{left-to-right traversal } \Longleftrightarrow x_i = 1, \qquad \text{right-to-left traversal } \Longleftrightarrow x_i = 0. \]

For clause \(C_j\), the interaction with the \(x_i\)-gadget takes place at the consecutive vertices \(p_{i,3j}\) and \(p_{i,3j+1}\). Whether the clause node attaches above or below that slot depends on whether the literal is \(x_i\) or \(\neg x_i\).

  • if \(x_i \in C_j\), the clause attachment is usable when the gadget is traversed left-to-right,
  • if \(\neg x_i \in C_j\), the clause attachment is usable when the gadget is traversed right-to-left.
Variable Gadget for x_i left to right ⇒ x_i = true right to left ⇒ x_i = false 0 1 2 … 3j-1 3j 3j+1 3j+2 … 3m+2 C_j positive occurrence of x_i in clause C_j C_j negative occurrence of ¬x_i in clause C_j Key Facts • one path per variable • total vertices = 3m+3 • slot for clause j uses vertices 3j and 3j+1 • direction determines which clause attachment is usable
The variable gadget is one \(3m+3\)-vertex path. The truth value comes from whether the Hamiltonian cycle traverses that path from left to right or from right to left.
ordinary path vertex
highlighted slot \((3j,3j+1)\)
positive-literal attachment
negative-literal attachment

Clause Gadget

For each clause \(C_j = (\ell_{j1} \vee \ell_{j2} \vee \ell_{j3})\), create one clause node \(c_j\) and attach it to the three relevant variable gadgets at their \(j\)-th slots.

The clause node always uses the pair of vertices indexed \(3j\) and \(3j+1\) inside each involved variable gadget. What changes from literal to literal is whether the attachment matches the left-to-right direction or the right-to-left direction.

Clause Node c_j and Its Three Literal Attachments c_j clause C_j = (l_1 ∨ l_2 ∨ l_3) variable gadget for x_a 3j 3j+1 positive literal x_a in clause C_j variable gadget for x_b 3j 3j+1 negative literal ¬x_b in clause C_j variable gadget for x_c 3j 3j+1 positive literal x_c in clause C_j Interpretation c_j can be inserted only if one of its three literal attachments matches a chosen direction.
Clause \(C_j\) is represented by one node \(c_j\) that connects to three different variable gadgets. In every case, the connection uses the \(j\)-th slot, namely vertices \(3j\) and \(3j+1\), of the corresponding variable path.

Consistency Enforced by the Gadget Design

Chosen traversal direction Clause attachments that become usable
left to right attachments corresponding to occurrences of \(x_i\)
right to left attachments corresponding to occurrences of \(\neg x_i\)

So a clause can be integrated into the Hamiltonian cycle only through a literal whose attachment matches the direction selected for that variable path.

Formal Construction

Input Formula

Let

\[ \varphi = C_1 \wedge C_2 \wedge \cdots \wedge C_m, \qquad C_j = (\ell_{j1} \vee \ell_{j2} \vee \ell_{j3}), \]

with variables \(x_1,\dots,x_n\).

Construction Steps

Step 1

Create one \(3m+3\)-vertex variable path for each \(x_i\), to be traversed in one of two directions.

Step 2

Connect the variable gadgets in sequence so the cycle must pass through all of them.

Step 3

For each clause \(C_j\), create a clause gadget and connect it to the three literal occurrences \(\ell_{j1}, \ell_{j2}, \ell_{j3}\).

Step 4

Add connector vertices so that every vertex has to be covered by the Hamiltonian cycle and the cycle closes back to the start.

Size Bound

Each variable contributes a gadget of size polynomial in its number of occurrences, and each clause contributes a constant-size gadget. Therefore

\[ |V(G_{\varphi})|, |E(G_{\varphi})| = \operatorname{poly}(n+m). \]

What Must Be Checked in a Reduction Proof

  1. The graph is built in polynomial time.
  2. Every satisfying assignment yields a Hamiltonian cycle.
  3. Every Hamiltonian cycle determines a satisfying assignment.

Why the Reduction Works

Forward Direction

If \(\varphi\) is satisfiable, choose a satisfying assignment \(a\).

  1. Traverse each variable gadget in the direction prescribed by \(a\).
  2. For every clause \(C_j\), choose one literal made true by \(a\).
  3. Use the corresponding literal attachment at the \((3j,3j+1)\)-slot to detour through the clause gadget and return to the main cycle.

Because each clause has at least one true literal, every clause gadget can be inserted. The gadget design ensures that the whole walk visits every vertex once and closes into a directed Hamiltonian cycle.

Backward Direction

Suppose \(G_{\varphi}\) has a directed Hamiltonian cycle \(H\).

  1. In each variable gadget, \(H\) must choose exactly one of the two traversal directions; otherwise some gadget vertex would be missed or revisited.
  2. Set \(x_i=1\) if \(H\) uses the left-to-right direction and \(x_i=0\) if \(H\) uses the right-to-left direction.
  3. Each clause gadget must be entered through one of its three literal attachments.

The only usable attachments are those exposed by the chosen direction, so the literal used for clause \(C_j\) is true under the derived assignment. Hence every clause is satisfied and \(\varphi\) is satisfiable.

Core Invariant

The Hamiltonian constraint is doing two jobs simultaneously:

  • it forces a globally consistent truth assignment across all occurrences of a variable, and
  • it forces every clause gadget to be serviced by at least one satisfied literal.

NP-Completeness Consequences

Membership in NP

Directed Hamiltonian Cycle belongs to \(NP\): a certificate is an ordering of the vertices. The verifier checks in polynomial time that consecutive vertices form directed edges and that every vertex appears exactly once.

Conclusion

\[ \operatorname{3SAT} \le_p \operatorname{DHC} \quad \text{and} \quad \operatorname{DHC} \in NP, \]

so Directed Hamiltonian Cycle is NP-complete.

From Directed to Undirected Hamiltonian Cycle

There is also a polynomial-time reduction

\[ \operatorname{DHC} \le_p \operatorname{HC}, \]

obtained by replacing each directed vertex with a small undirected gadget that forces any Hamiltonian cycle to respect the original entry and exit directions. Combining this with the reduction above shows that the standard undirected Hamiltonian Cycle problem is NP-complete as well.

How This Leads to TSP (Decision)

Given a graph \(G\), define a complete weighted graph where edges of \(G\) get weight \(1\) and missing edges get weight \(2\). Then

\[ G \text{ has a Hamiltonian cycle } \iff \text{the weighted graph has a tour of cost } \le n. \]

This gives the standard NP-hardness reduction from Hamiltonian Cycle to the decision version of TSP.

Takeaway

Hamiltonian reductions encode logical choices as forced traversal choices. The same pattern reappears in many path and routing problems.

🏠