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
0 answers

Can we find a Hamiltonian Cycle in a dense graph with better than O(n^2)?

Given a dense graph (according to ore's theorem, dense means the sum of degrees of any 2 non-adjacent nodes is at least N, where N is the total number of nodes), we can find a Hamiltonian cycle in such a graph using Palmer's algorithm with a time…
Traveling Salesman
  • 2,209
  • 11
  • 46
  • 83
2
votes
1 answer

GCJ - Hamiltonian Cycles

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 any of the K "forbidden" edges. Unfortunately…
2
votes
1 answer

Generate Adjacency matrix from a Map

I know this is a lengthy question :) I'm trying to implement Hamiltonian Cycle on a dataset in Scala 2.11, as part of this I'm trying to generate Adjacency matrix from a Map of values. Explanation: Keys 0 to 4 are the different cities, so in below…
Rohit Nimmala
  • 1,459
  • 10
  • 28
2
votes
1 answer

Shortest Path from Node A to B by going through all other Nodes (NP-Hard?)

My problem: Find the shortest path from node A to node B that passes through all other nodes of the unweighted, direct graph. I know that there exists such a path. I believe this is NP-Hard, but I can't explain it. My Prof. likes to have the…
EvenDance
  • 83
  • 1
  • 1
  • 9
2
votes
1 answer

Time Complexity in code?

I have fun1 calls foo1() which takes O(n^6 + m^4). What do you think the time complexity of fun1? My guess is it would be O(2n^6 + m^4) !! int fun1(int n, int G[MAX][MAX]) { int x, ans; if(n < 2) return 1; for(x = 0; x < n; x++){ …
33ted
  • 689
  • 1
  • 5
  • 14
2
votes
1 answer

Recursive backtracking in Racket?

A while ago, as a proof of concept (and because I was using Logo with my autistic son) I wrote a program in Logo to find a Hamiltonian circuit in a graph (if it exists) using a backtracking method. The basic backtracking schema I used was: boolean…
Alasdair
  • 1,300
  • 4
  • 16
  • 28
2
votes
1 answer

Construct a graph containing a Hamiltonian path

Background I am working on an optimization problem and have managed to reduce the problem to checking if a graph contains a Hamiltonian path. The reduced problem is as follows: The problem We are given a sequence of edges (Example: e[1,5], e[3,4],…
lakshayg
  • 2,053
  • 2
  • 20
  • 34
2
votes
1 answer

Hamiltonian path generator algorithm

I have been playing with Hamiltonian paths for some time and have found some cool uses of it. One being a sort of puzzle where the goal is to connect all the nodes to form a hamiltonian path. So, being a novice programmer I am, I created a very…
2
votes
2 answers

Which crossing over method is best to give us quick changes in best values for TSP in GA?

I am trying to solve Travelling Salesman Problem using Genetic Algorithym in C#. But in my app best values changes so slowly. I have tried with different Crossing-Over methods such as classic, greedy and pmx but I have never got what I want. What is…
Ali Tor
  • 2,772
  • 2
  • 27
  • 58
2
votes
0 answers

Restricted Hamiltonian Cycle

Can someone explain to me the definition of a Restricted Hamiltonian Cycle? I know what a Hamiltonian Path (and a Hamiltonian Cycle) is, but I'm having a problem understanding a what is a Restricted Hamiltonian Cycle exactly. Thank you.
XandY
  • 43
  • 2
2
votes
2 answers

Find all possible hamiltonian cycles in a partially oriented graph

This is my algorithm to find a Hamiltonian cycle in a graph: private SolutionArray solution; private int V, pathCount; private int[] path; private int[][] graph; /** * Constructor */ public ConcreteSolver() { solution = new…
JulioQc
  • 310
  • 1
  • 4
  • 20
2
votes
2 answers

Is it possible to use Dijkstra's Shortest Path Algorithm to find the shortest Hamiltonian path? (in Polynomial Time)

I've read that the problem of finding whether a Hamiltonian path exists in a graph is NP-Complete, and since Dijkstra's Shortest Path Algorithm runs in Polynomial Time, it cannot be modified to find the shortest Hamiltonian path. (Is this logic…
2
votes
0 answers

Seeking samples of grid graphs with holes that are considered "difficult" for finding Hamiltonian cycle

Is there a database or citations for grid graphs with holes that are considered "difficult" to solve for Hamiltonian cycle?
2
votes
2 answers

Algorithm for Enumerating Hamiltonian Cycles of a Complete Graph (Permutations where loops, reverses, wrap-arounds or repeats don't count)

I want to generate all the Hamiltonian Cycles of a complete undirected graph (permutations of a set where loops and reverses count as duplicates, and are left out). For example, permutations of {1,2,3} are Standard…
ruya
  • 391
  • 3
  • 5
  • 12
2
votes
1 answer

Program to find number of hamiltonian paths in a graph given start and end points

Given a graph with n² pathing nodes, and given that the starting node is always in the top right corner (point A) and the ending node is always in the bottom right corner (point B), I need to write a C# program that will determine the number of…
Steve Holt
  • 59
  • 1
  • 2