Skip to main content
edited per suggestions
Source Link
Joshua Schrier
  • 3.7k
  • 12
  • 21

Assuming you are interested in DirectedEdges between the pairs, something like this will work:

Graph[ Map[DirectedEdge @@ # &,DirectedEdge@@@list list] ] 

(where list is a variable storing your list of pairs above)

Unfortunately, this is not a Hamiltonian graph:

HamiltonianGraphQ[%] (*False*) 

However, the undirected version does contain a Hamiltonian cycle:

FindHamiltonianCycle@Graph[ Map[UndirectedEdge @@FindHamiltonianCycle #@ &,Graph[ list]]UndirectedEdge@@@list] (*list of results showing the cycle*) 

As noted in a subsequent answer, by default Graph interprets lists of pairs as a set of undirected edge instructions, so this is equivalent to:

FindHamiltonianCycle @ Graph[list] 

Assuming you are interested in DirectedEdges between the pairs, something like this will work:

Graph[ Map[DirectedEdge @@ # &, list] ] 

(where list is a variable storing your list of pairs above)

Unfortunately, this is not a Hamiltonian graph:

HamiltonianGraphQ[%] (*False*) 

However, the undirected version does contain a Hamiltonian cycle:

FindHamiltonianCycle@Graph[ Map[UndirectedEdge @@ # &, list]] (*list of results showing the cycle*) 

Assuming you are interested in DirectedEdges between the pairs, something like this will work:

Graph[ DirectedEdge@@@list ] 

(where list is a variable storing your list of pairs above)

Unfortunately, this is not a Hamiltonian graph:

HamiltonianGraphQ[%] (*False*) 

However, the undirected version does contain a Hamiltonian cycle:

FindHamiltonianCycle @ Graph[ UndirectedEdge@@@list] (*list of results showing the cycle*) 

As noted in a subsequent answer, by default Graph interprets lists of pairs as a set of undirected edge instructions, so this is equivalent to:

FindHamiltonianCycle @ Graph[list] 
Source Link
Joshua Schrier
  • 3.7k
  • 12
  • 21

Assuming you are interested in DirectedEdges between the pairs, something like this will work:

Graph[ Map[DirectedEdge @@ # &, list] ] 

(where list is a variable storing your list of pairs above)

Unfortunately, this is not a Hamiltonian graph:

HamiltonianGraphQ[%] (*False*) 

However, the undirected version does contain a Hamiltonian cycle:

FindHamiltonianCycle@Graph[ Map[UndirectedEdge @@ # &, list]] (*list of results showing the cycle*)