A Hamiltonian cycle is a cycle in a directed or undirected graph that visits each node/vertex exactly once.
Questions tagged [hamiltonian-cycle]
104 questions
31
votes
1 answer
Algorithm for finding a Hamilton 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…
![](../../users/profiles/2302617.webp)
user2302617
- 349
- 1
- 3
- 7
20
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.
![](../../users/profiles/169210.webp)
avd
- 12,513
- 29
- 74
- 96
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…
![](../../users/profiles/1534386.webp)
letsc
- 1,933
- 4
- 23
- 41
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…
![](../../users/profiles/2034041.webp)
Varaquilex
- 3,312
- 7
- 39
- 57
8
votes
4 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…
![](../../users/profiles/912387.webp)
Fejuto
- 549
- 1
- 5
- 9
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…
![](../../users/profiles/721998.webp)
Darth.Vader
- 3,249
- 5
- 38
- 66
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…
![](../../users/profiles/270006.webp)
ŹV -
- 2,391
- 1
- 18
- 28
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…
![](../../users/profiles/9470420.webp)
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…
![](../../users/profiles/383313.webp)
Dániel Varga
- 65
- 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…
![](../../users/profiles/1258080.webp)
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…
![](../../users/profiles/662181.webp)
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…
![](../../users/profiles/300915.webp)
alchemey89
- 445
- 1
- 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…
![](../../users/profiles/521070.webp)
Michael
- 37,415
- 63
- 167
- 303