Class CyclesAll

java.lang.Object
topics.backtracking.tsp.HamiltonianAll
topics.backtracking.tsp.CyclesAll

public class CyclesAll extends HamiltonianAll

Simple Cycles of a Node

This class calculates all simple cycles in a graph originating from a specific source node.

*

Pedagogical Note: TSP vs Cycles

  • Traveling Salesman: Requires COMPLETE simple cycles (must visit every node exactly once).
  • Node Cycles: Accepts SIMPLE cycles of ANY length (visiting a subset of nodes and returning).

Even though it doesn't require complete paths, the worst-case time complexity remains factorial O(N!) for highly connected graphs due to the combinatorial explosion of subsets.

* @author vicegd
  • Constructor Details

    • CyclesAll

      public CyclesAll(int n, int source, int[][] weights)
  • Method Details

    • backtrack

      protected void backtrack(int current)
      Description copied from class: HamiltonianAll
      Core backtracking logic following the Choose-Explore-Unchoose paradigm.
      Overrides:
      backtrack in class HamiltonianAll
      Parameters:
      current - The current node being visited.