Skip to content

[Rule] HAMILTONIAN CIRCUIT to HAMILTONIAN PATH #199

@isPANN

Description

@isPANN

Source: HamiltonianCircuit
Target: HamiltonianPath
Motivation: Establishes NP-completeness of Hamiltonian Path via a minimal modification to a Hamiltonian Circuit instance, showing that the path variant is no easier than the circuit variant despite removing the closing-edge requirement. Connects two currently isolated problems in the reduction graph.
Reference: Garey & Johnson, Computers and Intractability, 1979 (HC and HP are both NP-complete; the standard HC→HP reduction is the vertex-duplication construction with pendant endpoints). See also Wikipedia: Hamiltonian path problem, U of Toronto CSC 463 notes.

Reduction Algorithm

Given a HamiltonianCircuit instance G = (V, E) with n = |V| vertices and m = |E| edges, construct a HamiltonianPath instance G' = (V', E') as follows:

  1. Pick a vertex. Choose an arbitrary vertex v ∈ V (the implementation uses v = 0).

  2. Duplicate v. Create a new vertex v' (index n) and connect v' to every neighbor of v in G. That is, for each edge {v, u} ∈ E, add edge {v', u} to E'. The vertex v retains all its original edges.

  3. Add pendant s. Create a new vertex s (index n + 1) with a single edge {s, v}. Since deg(s) = 1, any Hamiltonian path in G' must start or end at s.

  4. Add pendant t. Create a new vertex t (index n + 2) with a single edge {t, v'}. Since deg(t) = 1, any Hamiltonian path in G' must start or end at t.

Result: G' = (V', E') where V' = V ∪ {v', s, t} and E' = E ∪ {{v', u} : {v, u} ∈ E} ∪ {{s, v}, {t, v'}}.

Correctness argument:

  • (⇒) G has a Hamiltonian circuit ⟹ G' has a Hamiltonian path.
    Let C = (v, u₁, u₂, …, u_{n−1}, v) be a Hamiltonian circuit in G. Then P = (s, v, u₁, u₂, …, u_{n−1}, v', t) is a Hamiltonian path in G': the edge {s, v} exists by construction; the sub-path v → u₁ → … → u_{n−1} follows edges from C; the edge {u_{n−1}, v'} exists because {u_{n−1}, v} ∈ E and v' copies v's neighborhood; and {v', t} exists by construction.

  • (⟸) G' has a Hamiltonian path ⟹ G has a Hamiltonian circuit.
    Any Hamiltonian path in G' must use s and t as endpoints (both have degree 1). So the path has the form (s, v, x₁, x₂, …, x_{n−1}, v', t) where {x₁, …, x_{n−1}} = V \ {v}. The sub-sequence (v, x₁, …, x_{n−1}) visits every vertex of G exactly once, and {x_{n−1}, v'} ∈ E' implies {x_{n−1}, v} ∈ E (since v' has the same neighbors as v). Therefore (v, x₁, …, x_{n−1}, v) is a Hamiltonian circuit in G.

Solution extraction: Given a Hamiltonian path P = (s, v, x₁, …, x_{n−1}, v', t) in G', return the Hamiltonian circuit (v, x₁, …, x_{n−1}) in G. (If P runs t-first, reverse it first.)

Size Overhead

Let n = num_vertices and m = num_edges of the source HamiltonianCircuit instance G, and let d = deg(v) where v is the chosen vertex.

Target metric (code name) Expression Derivation
num_vertices num_vertices + 3 Original n vertices + v' + s + t
num_edges num_edges + num_vertices + 1 Original m edges + d edges from v' + 2 pendant edges. Worst case: d = n − 1, giving m + (n − 1) + 2 = m + n + 1

Note: The exact edge count is m + d + 2 where d = deg(v). The implementation picks v = 0, so the actual count depends on deg(0). The overhead expression uses the worst case d = n − 1 since deg(v) is not available as a source size field.

Validation Method

  • Closed-loop test: Construct a HamiltonianCircuit instance with a known Hamiltonian circuit, apply the reduction to get a HamiltonianPath instance, solve with BruteForce, verify a Hamiltonian path is found, and extract the solution back to verify it is a valid Hamiltonian circuit in the source.
  • Pendant endpoint check: Verify that in every Hamiltonian path found in G', the endpoints are s and t (the degree-1 pendant vertices).
  • Size verification: Check |V'| = |V| + 3 and |E'| = |E| + deg(v) + 2 for the specific instance.
  • Negative test: Construct a graph without a Hamiltonian circuit (e.g., a path graph P_3), apply the reduction, and verify that no Hamiltonian path exists in the target.
  • Round-trip: Brute-force solve the target, map back to the source, and confirm the mapped solution is valid in the source.

Example

Source instance (HamiltonianCircuit):
Graph G = C_4 (4-cycle) with 4 vertices and 4 edges:

  • V = {0, 1, 2, 3}
  • E = {(0,1), (1,2), (2,3), (0,3)}

G has 2 Hamiltonian circuits (the two traversal directions): [0, 1, 2, 3] and [0, 3, 2, 1].

Reduction (v = 0, neighbors of 0 = {1, 3}):

  1. Duplicate v = 0: create v' = 4, add edges {(4,1), (4,3)}
  2. Add pendant s = 5 with edge {(5,0)}
  3. Add pendant t = 6 with edge {(6,4)}

Target instance (HamiltonianPath):

  • V' = {0, 1, 2, 3, 4, 5, 6} — 7 vertices (= 4 + 3 ✓)
  • E' = {(0,1), (1,2), (2,3), (0,3), (4,1), (4,3), (5,0), (6,4)} — 8 edges (= 4 + deg(0) + 2 = 4 + 2 + 2 ✓)

Hamiltonian paths in G' (all 4, verified by exhaustive enumeration):

  1. [5, 0, 1, 2, 3, 4, 6] — corresponds to HC [0, 1, 2, 3]
  2. [5, 0, 3, 2, 1, 4, 6] — corresponds to HC [0, 3, 2, 1]
  3. [6, 4, 3, 2, 1, 0, 5] — reverse of path 1
  4. [6, 4, 1, 2, 3, 0, 5] — reverse of path 2

All paths have endpoints {5, 6} = {s, t} ✓

Non-satisfying configurations (examples):

  • [0, 1, 2, 3, 4, 5, 6]: fails because edge (4, 5) does not exist — s = 5 is only connected to v = 0
  • [5, 0, 1, 2, 4, 3, 6]: fails because edge (2, 4) does not exist — v' = 4 is only connected to neighbors of v = 0, which are {1, 3}, not {2}

Solution extraction:
From HP [5, 0, 1, 2, 3, 4, 6], strip pendant endpoints s = 5 and t = 6, replace v' = 4 with v = 0: circuit [0, 1, 2, 3] → verify (0,1), (1,2), (2,3), (3,0) are all edges in G ✓

Negative test:
Source: P_3 (path graph, 3 vertices, 2 edges: (0,1), (1,2)) — no Hamiltonian circuit.
After reduction with v = 0 (neighbors = {1}): v' = 3, s = 4, t = 5. Target has 6 vertices, 5 edges: {(0,1), (1,2), (3,1), (4,0), (5,3)}.
Exhaustive search confirms: 0 Hamiltonian paths in the target ✓

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.ruleA new reduction rule to be added.

    Type

    No type

    Projects

    Status

    Ready

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions