Skip to content

[Rule] HAMILTONIAN CIRCUIT to LONGEST CIRCUIT #358

@isPANN

Description

@isPANN

Source: HAMILTONIAN CIRCUIT
Target: LONGEST CIRCUIT
Motivation: Establishes NP-hardness of LONGEST CIRCUIT via polynomial-time reduction from HAMILTONIAN CIRCUIT. The reduction assigns unit weight to every edge, producing a LongestCircuit optimization instance. A Hamiltonian circuit exists in the source graph if and only if the maximum circuit length in the constructed instance equals |V| (i.e., a circuit using all n vertices is achievable).

Reference: Garey & Johnson, Computers and Intractability, ND28, p.213

GJ Source Entry

[ND28] LONGEST CIRCUIT
INSTANCE: Graph G=(V,E), length l(e)∈Z^+ for each e∈E, positive integer K.
QUESTION: Is there a simple circuit in G of length K or more, i.e., whose edge lengths sum to at least K?
Reference: Transformation from HAMILTONIAN CIRCUIT.
Comment: Remains NP-complete if l(e)=1 for all e∈E, as does the corresponding problem for directed circuits in directed graphs. The directed problem with all l(e)=1 can be solved in polynomial time if G is a "tournament" [Morrow and Goodman, 1976]. The analogous directed and undirected problems, which ask for a simple circuit of length K or less, can be solved in polynomial time (e.g., see [Itai and Rodeh, 1977b]), but are NP-complete if negative lengths are allowed.

Reduction Algorithm

Summary:
Given a HAMILTONIAN CIRCUIT instance G = (V, E) with n = |V| vertices, construct a LONGEST CIRCUIT instance as follows:

  1. Graph: Use the same graph G' = G = (V, E).

  2. Edge lengths: For every edge e in E, set the length l(e) = 1 (unit weights).

  3. Optimization formulation: The codebase implements LongestCircuit as an optimization problem (maximize total circuit length via Max<W::Sum>), not as a decision problem with a bound K. The reduction maps the HC instance to a LongestCircuit instance, and a Hamiltonian circuit exists in G if and only if the optimal circuit length equals n.

  4. Correctness (forward): If G has a Hamiltonian circuit C visiting all n vertices, then C is a simple circuit in G' with exactly n edges, each of length 1, so the total length is n. This achieves the maximum possible value for any simple circuit on n vertices with unit weights.

  5. Correctness (reverse): If the optimal circuit length in G' equals n, then there exists a simple circuit with exactly n unit-weight edges. Since a simple circuit can have at most n edges on n vertices, any such circuit must visit all n vertices exactly once — it is a Hamiltonian circuit in G.

Key invariant: With unit weights, a simple circuit of maximum length n exists if and only if the circuit visits all n vertices, i.e., it is Hamiltonian.

Time complexity of reduction: O(|E|) to assign unit weights.

Size Overhead

Symbols:

  • n = num_vertices of source HamiltonianCircuit instance (|V|)
  • m = num_edges of source HamiltonianCircuit instance (|E|)
Target metric (code name) Polynomial (using symbols above)
num_vertices num_vertices
num_edges num_edges

Derivation: The graph is unchanged. Each edge simply gets a unit length assigned. There is no bound field on LongestCircuit — the model is an optimization problem, not a decision problem.

Validation Method

  • Closed-loop test: reduce a HamiltonianCircuit instance to LongestCircuit, solve target with BruteForce, extract solution, verify on source
  • Test with known YES instance: the triangular prism graph (6 vertices, 9 edges) is Hamiltonian; the longest circuit instance should have optimal value = 6 (all vertices visited)
  • Test with known NO instance: construct a graph without a Hamiltonian circuit; verify that the optimal circuit length is strictly less than n
  • Witness extraction: the optimal LongestCircuit configuration (edge selection) should map back to a valid Hamiltonian circuit in the source graph

Example

Source instance (HamiltonianCircuit):
Graph G with 6 vertices {0, 1, 2, 3, 4, 5} and 9 edges:

  • Edges: {0,1}, {1,2}, {2,3}, {3,4}, {4,5}, {5,0}, {0,3}, {1,4}, {2,5}
  • (Triangular prism / prism graph)
  • Hamiltonian circuit exists: 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 0

Constructed target instance (LongestCircuit):

  • Same graph G' = G with 6 vertices and 9 edges
  • Edge lengths: l(e) = 1 for all 9 edges

Solution mapping:

  • Optimal LongestCircuit solution: simple circuit 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 0
  • Optimal circuit length: 6 edges × 1 = 6 = n (all vertices visited)
  • This circuit visits all 6 vertices exactly once, forming a Hamiltonian circuit in G

Verification:

  • Forward: HC 0->1->2->3->4->5->0 maps to a circuit of length 6 = n (optimal, not just feasible)
  • Reverse: any simple circuit of optimal length 6 with unit weights on a 6-vertex graph must visit all vertices -> Hamiltonian circuit
  • The optimization value Max(Some(6)) signals a YES instance; Max(Some(k)) with k < 6 signals NO

References

  • [Morrow and Goodman, 1976]: [Morrow1976] C. Morrow and S. Goodman (1976). "An efficient algorithm for finding a longest cycle in a tournament". In: Proceedings of the 7th Southeastern Conference on Combinatorics, Graph Theory, and Computing, pp. 453-462. Utilitas Mathematica Publishing.
  • [Itai and Rodeh, 1977b]: [Itai1977c] Alon Itai and Michael Rodeh (1977). "Some matching problems". In: Automata, Languages, and Programming. Springer.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions