Find all permutation sequences with only neighbor swaps

376 Views Asked by At

I am trying to essentially do what was done at this link, except for five elements instead of four.

The link gives all of the possible sequences of permutations of four elements with the following 2 constraints:

  1. Only neighbor swaps are allowed to get the next permutation in the sequence
  2. The sequence has to end on the same permutation it started on - it's a cycle

I'm trying to solve the same problem with 5 elements, find all sequences of 120 swaps that visit every permutation. There are 7 valid swaps for each row:

12345

X|||

XX|

X|X

|X||

|XX

||X|

|||X

I can only think to make a graph and find all the Hamiltonian cycles on it, and I don't know how to do that without making it take til the sun burns out. Is there a way to solve this in a reasonable amount of time?