Skip to content

Conversation

ArpitaHanjagi
Copy link
Contributor

This R program uses backtracking to find a Hamiltonian Cycle in a graph.
A Hamiltonian Cycle is a path that visits every vertex exactly once and returns to the starting vertex.

The graph is given as an adjacency matrix, and the algorithm recursively tries to build a valid cycle by checking:

if the next vertex is connected to the previous one, and

if it hasn’t been visited before.

If a full cycle is found, it returns the vertex order; otherwise, it reports that no cycle exists.

Time Complexity: O(N!)
Space Complexity: O(N)

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit f0c8fcd into TheAlgorithms:master Oct 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants