Find Hamiltonian paths and cycles in graphs using multiple algorithms. Visualize graph traversal with step-by-step explanations and performance statistics.
Select a predefined graph example:
Complete Graph K5: Every vertex connected to every other vertex. Many Hamiltonian cycles exist.
Cycle Graph C6: A single cycle connecting all vertices. Exactly one Hamiltonian cycle.
Petersen Graph: Famous non-Hamiltonian graph with 10 vertices.
In graph theory, a Hamiltonian 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 (starts and ends at the same vertex).
Key Definitions:
| Property | Hamiltonian | Eulerian |
|---|---|---|
| Visits | Each vertex exactly once | Each edge exactly once |
| Complexity | NP-Complete (no known efficient algorithm) | Polynomial time (O(E)) |
| Necessary Condition | No known simple necessary and sufficient condition | All vertices have even degree |
| Sufficient Condition | Dirac's Theorem: deg(v) ≥ n/2 for all vertices | Graph is connected and all vertices have even degree |
| Example | Traveling Salesman Problem | Seven Bridges of Königsberg |
Backtracking Algorithm: This calculator uses a backtracking approach to explore all possible paths. The algorithm tries to extend the current path by adding an unvisited neighbor, backtracking when no extension is possible.
Time Complexity: O(n!) in worst caseOptimizations: The algorithm includes pruning techniques like checking if the remaining graph is connected, and using degree constraints to reduce the search space.
Visualization: The step-by-step visualization shows how the algorithm explores the graph, backtracks when needed, and eventually finds a Hamiltonian path or cycle if one exists.
Calculator Features:
| Algorithm | Type | Time | Guarantee |
|---|---|---|---|
| Backtracking | Exact | O(n!) | Yes |
| Nearest Neighbor | Heuristic | O(n²) | No |
| Random Search | Heuristic | O(k·n) | No |
| Greedy | Heuristic | O(n² log n) | No |