Questions tagged [hamiltonian-cycle]

A Hamiltonian cycle is a cycle in a directed or undirected graph that visits each node/vertex exactly once.

115 questions
2
votes
2 answers

Checking if a Hamilton Cycle exists in a dense graph

A few definitions first: Definition 1 A graph G = (V, E) is called ``dense'' if for each pair of non-adjacent vertices u and v, d(u) + d(v)>=n where n = |V| and d(*) denotes the degree of the vertex * Definition 2 A ``Hamiltonian cycle'' on G…
Traveling Salesman
  • 2,209
  • 11
  • 46
  • 83
1
vote
1 answer

Testing a Hamiltonian Path finder implementation

I am implementing an algorithm which finds an optimal Hamiltonian path in a directed graph. I have implemented an algorithm which appears to work reasonably well, however I am not entirely sure if there are subtle bugs or other issues in certain…
1
vote
0 answers

How do I find a Hamiltonian Cycle in a Graph in C# when some nodes branch to a connected loop of nodes?

I have this graph: The starting node is Hotel and I want the program to find paths for all valid Hamiltonian cycles. But I cannot seem to get the code to work despite following examples of the algorithm. public class Program { private…
D.Man
  • 179
  • 1
  • 15
1
vote
1 answer

Solving Hamiltonian cycle in answer set programming

Hamiltonian cycle instantiation and encoding: % vertices: n=node n(1..4). % edges: e=edge e(1,(2;3)). e(2,(3;4)). e(3,(1;4)). e(4,1). % starting point s(1). # p=path, o=omit, op=on-path, r=reach, s=start% generate path p(X,Y):- not o(X,Y),…
1
vote
1 answer

non-Hamilton path elimination in a graph

Assume that we have a random graph. How do you remove or add edges in the minimum number of steps such that every edge in the resulting graph would be in a Hamilton path? I would really appreciate if someone can share any ideas.
John
  • 11
  • 1
1
vote
1 answer

The vertices of an undirected graph are numbered 1,2,...4286. The edge (i,j) exists if |i-j| <= 3, where i!=j. Which statements are true?

The vertices of an undirected graph are numbered 1,2,...4286. The edge (i,j) exists if |i-j| <= 3, where i!=j. Which statements are true? the graph contains an Eulerian circle the graph contains a perfect matching graph the graph is…
1
vote
1 answer

Writing a Python function that finds a Hamiltonian path in a graph

I was trying to write a function that will take a positive integer n as an input and will put the integers 1 through n in an order such that the sum of every adjacent number is a perfect square (if such an order exists). I realized that if I create…
rmdnusr
  • 113
  • 6
1
vote
1 answer

How to find Hamiltonian Cycle in a graph using BFS? (the condition is that the graph is exactly hamiltonian)

I am trying to solve the Hamiltonian Cycle problem. The condition of my task is: The group consists of N people. In it, everyone has exactly N / 2 friends. Friendship is symmetrical (if A is friend B, then B is friend A). One person in the group has…
1
vote
2 answers

Hamiltonian Cycle; Prove: if there's an efficient algorithm to determine that an HC exists, then there's an efficient FIND algorithm

Let G(V,E) be an undirected graph. A Hamiltonian cycle is a cycle that visits each vertex v of G exactly once (except the first vertex, which is also the last vertex in the cycle). Assume: There Exists an efficient algorithm that determines if a…
Gilad Gur
  • 477
  • 3
  • 10
1
vote
0 answers

Problem returning to Origin Node using Adjacency Matrix

I have to run all USA cities(41 in the map we were given) using an adjacency matrix. The user must type the origin node, and then the algorithm has to run all USA cities, and then return to the origin. /* C program for solution of Hamiltonian…
Raven
  • 71
  • 2
  • 7
1
vote
0 answers

Check if its a Hamilton cycle, create an undirected graph using python

I need to write a code which tells if a cycle is hamilton or not. First i have two text files: 1.file : First line contains the number of vertices and edges while the rest is a pair of two vertices which are connected.Like 0 1 means there is…
1
vote
0 answers

Display all hamiltonian cycles or circuits in an undirected graph

I found this algorithm that shows me just one hamiltonian cycle but I need to print all hamiltonian cycles in an undirected graph. Here's the code that I tried to use: https://www.geeksforgeeks.org/hamiltonian-cycle-backtracking-6/ Could someone…
1
vote
0 answers

Designing a Hamiltoninan path algorithm to find a cycle in a undirected graph

I have recently been working on developing a class to see the given undirected graph has a Hamiltonian cycle. I found out this interesting article http://www.geeksforgeeks.org/backtracking-set-7-hamiltonian-cycle/.I've developed my code accordingly.…
karthi13
  • 15
  • 4
1
vote
2 answers

Generating graphs with only 1 valid Hamiltonian cycle

I am looking for some advice /guidance in the right direction. My requirement is to generate a graph rather than solving one for solution. I am looking to implement an algorithm to generates a graph(NxN grid) with only 1 hamiltonian cycle. Note that…
1
vote
1 answer

How to Find Number of Hamiltonian Paths in a graph?

I am trying out this Google Codejam problem which says to find out number of hamiltonian paths if we remove k edges from a complete graph link to Question https://code.google.com/codejam/contest/32004/dashboard#s=p2 I figured out we can use…
Ezio
  • 723
  • 6
  • 14