A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex.
If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian.
Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient solution for all graph types, but solutions exist for smaller or specific types.
The Hamiltonian Cycle problem has applications in logistics, network design, and computer science.
Sample Problem
Given an undirected graph, the task is to determine if it contains a Hamiltonian cycle. If found, print the path; otherwise, print "Solution does not exist".
Generate all possible vertex configurations and print a configuration that satisfies the given constraints. This results in n! (n factorial) configurations. Therefore, the overall time complexity of this approach is at least O(n!).
[Expected Approach] Using Backtracking
Backtracking is used to find a Hamiltonian Cycle. Initialize an empty path array, place the starting vertex (e.g., 0) in the first position. Recursively add remaining vertices one by one, ensuring each new vertex is adjacent to the previous one and not already in the path. If a valid vertex is found, proceed; otherwise, backtrack.
Exemplification
Let's find out the Hamiltonian cycle for the following graph:
Note: The algorithm currently starts from a fixed vertex, but a Hamiltonian cycle allows any vertex. Minor adjustments are needed to enable cycle initiation from any node.