Resource · Guide or article
Hamiltonian Path
Covers Hamiltonian paths and cycles, which visit every vertex once, and two search approaches: brute force and backtracking.
Reviewed
Open the original: Hamiltonian Path (opens the original site in a new tab)Practice this topicOpens the practice interviewer with a question on Graphs.
Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
Hamiltonian path (or traceable path) is a path in an undirected or directed graph that visits each vertex exactly once. 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. One possible Hamiltonian cycle through every vertex of a dodecahedron is shown in red – like all platonic solids, the dodecahedron is Hamiltonian. Generate all possible configurations of vertices and print a configuration that satisfies the given constraints. There will be n! (n factorial) configurations.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- Definitions, with a dodecahedron example
- Pseudocode for trying all n! vertex orderings
- Backtracking that grows a path from vertex 0 using adjacent, unused vertices
How to use it
PrepKit study advice, not a claim made by the source.
Implement the backtracking version on an adjacency matrix and count partial paths explored versus the n! orderings on a small graph.
Scope and limitations
The backtracking part is one paragraph with no pseudocode or complexity, and NP-completeness is not mentioned.
Access and format
Free English README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/graph/hamiltonian-cycle/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.