Algorithms
Algorithms copied to clipboard
Hamiltonian cycle in cpp, java, python.
Is your feature request related to a problem? Please describe. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian path that is a cycle. Determining whether such paths and cycles exist in graphs is the Hamiltonian path problem, which is NP-complete.
Hamiltonian paths and cycles are named after William Rowan Hamilton who invented the icosian game, now also known as Hamilton's puzzle, which involves finding a Hamiltonian cycle in the edge graph of the dodecahedron. Hamilton solved this problem using the icosian calculus, an algebraic structure based on roots of unity with many similarities to the quaternions (also invented by Hamilton). This solution does not generalize to arbitrary graphs.
Describe the solution you'd like CPP/Java/Python: Represent the graph using an adjacency matrix or an adjacency list. Start with an empty path and mark all vertices as unvisited. Choose a starting vertex and mark it as visited. Recursively explore unvisited adjacent vertices from the current vertex. If all vertices are visited and the last vertex has an edge to the starting vertex, a Hamiltonian cycle is found. Otherwise, backtrack by marking the current vertex as unvisited and continue exploring other paths. Repeat the above steps for all possible starting vertices until a Hamiltonian cycle is found or all paths are explored.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Assigned! @vimarsh11 : C, C++, Python
@vimarsh11 What is your status on this issue?
@vimarsh11 What is your status on this issue? @Kumar-laxmi Yes, I'm working on it. I will do it by today.
I would like to work on this issue, kindly assign this to me.
Stale issue message