A Hamiltonian cycle is a cycle in a directed or undirected graph that visits each node/vertex exactly once.
Questions tagged [hamiltonian-cycle]
115 questions
37
votes
1 answer
Algorithm for finding a Hamiltonian Path in a DAG
I am referring to Skienna's Book on Algorithms.
The problem of testing whether a graph G contains a Hamiltonian path is NP-hard, where a Hamiltonian path P is a path that visits each vertex exactly once. There does not have to be an edge in G from…

user2302617
- 409
- 1
- 4
- 8
22
votes
2 answers
What is the dynamic programming algorithm for finding a Hamiltonian cycle in a graph?
What is dynamic programming algorithm for finding a Hamiltonian cycle in an undirected graph?
I have seen somewhere that there exists an algorithm with O(n.2^n) time complexity.

avd
- 13,993
- 32
- 78
- 99
14
votes
4 answers
Difference between Hamiltonian path and ST
I was reading up algorithms for finding the minimum spanning tree(in case of weighted graphs) and for finding if a graph has a hamiltonian path(which depends on the presence of a hamiltonian cycle). I got everything messed up. So whats the…

letsc
- 2,075
- 5
- 24
- 43
11
votes
5 answers
Algorithm to find a random Hamiltonian path in a grid?
I'm looking for an efficient algorithm that is able to find an as random as possible Hamiltonian path in a bidirectional N*M grid.
Does anyone know where I can find, or how to go about constructing such an algorithm?
I've already found an efficient…

Fejuto
- 599
- 1
- 5
- 10
9
votes
3 answers
How to detect if the given graph has a cycle containing all of its nodes? Does the suggested algorithm have any flaws?
I have a connected, non-directed, graph with N nodes and 2N-3 edges. You can consider the graph as it is built onto an existing initial graph, which has 3 nodes and 3 edges. Every node added onto the graph and has 2 connections with the existing…

Varaquilex
- 3,447
- 7
- 40
- 60
7
votes
4 answers
Enumerate *all* hamiltonian paths
I know this has been asked before, but I did not find its answer in any of the posts. Can someone please suggest me an algorithm which enumerates ALL Hamiltonian paths in a graph?
A little background: I am working on a problem in which I have to…

Darth.Vader
- 5,079
- 7
- 50
- 90
7
votes
1 answer
Canonical algorithm for "visit each door once" problems
There are a number of puzzles that are variant of the classic "7 Bridges of Konigsberg" puzzle where you must find a route through a set of rooms without ever using a door twice.
Here is an example of one without a solution.
... and is a slightly…

zetavolt
- 2,989
- 1
- 23
- 33
7
votes
3 answers
Complete Weighted Graph and Hamiltonian Tour
I ran into a question on a midterm exam. Can anyone clarify the answer?
Problem A: Given a Complete Weighted Graph G, find a Hamiltonian Tour with minimum weight.
Problem B: Given a Complete Weighted Graph G and Real Number R, does G have a…
user4559497
6
votes
1 answer
Finding Longest Path Grid
I am working with a uniform cost grid that only allows movements in the orthogonal directions. This is used as a base for the game snake where the snake must constantly move and try to eat apples on the board. The location of the food and collision…

Cobey Hollier
- 61
- 6
6
votes
2 answers
Finding Hamiltonian cycles in cubic planar graphs
I have relatively small (40-80 nodes) cubic (3-regular) planar graphs, and I have to decide their Hamiltonicity. I am aware of the fact that this task is NP-complete, but I hope for asymptotically exponential time algorithms that are nevertheless…

Dániel Varga
- 65
- 1
- 3
6
votes
1 answer
Complete Weighted Graph G, Finding Weights and one Machine
I read a lot about Complete Weighted Graph and Hamiltonian Tour topics in this site that asked by one of users, ask a lots of staff in my university, but couldn't get to a good answer, I change an important part of this question as follows:…
user4249446
5
votes
0 answers
Detect cycles in undirected graph using boost graph library
I've been stuck since yesterday with this problem. Unfortunately/fortunately this problem makes only about 0.5% of the my super huge (for me, a c++ newbie) algorithm thus the need for a library of existing code that one can just adapt and get things…

Daniel
- 51
- 1
- 2
5
votes
4 answers
Can someone introduce me to the Hamiltonian Cycle?
I have this project where I have to come up with Java source code implementing the Hamiltonian cycle.
I searched on google and at least now I know what a Hamiltonian cycle is, path that passes through all vertices just once except the starting…

user662181
- 51
- 3
5
votes
1 answer
How to implement an adjacency matrix in java producing hamilton cycles
I am trying to implement an adjacency matrix in java that will produce an output for a Hamiltonian cycle, which can then be solved with different algorithms such as kruskurals, djikstras and the 2opt approach. i know that i need a 2d array but i…

alchemey89
- 485
- 2
- 6
- 8
4
votes
2 answers
How do I find the number of Hamiltonian cycles that do not use "forbidden" edges?
This question actually rephrases that one. The code jam problem is the following:
You are given a complete undirected graph with N nodes and K "forbidden" edges. N <= 300, K <= 15. Find the number of Hamiltonian cycles in the graph that do not use…

Michael
- 41,026
- 70
- 193
- 341