Checking if Hamiltonian path exists

44 Views Asked by At

I am trying so solve interesting algorithmic problem, I would say, and after unsuccessfully trying bunch of various stuff, I am looking for help here.

So here is the assignment:
Suppose we have magnetic board and magnets with words on it. We want to make sequence of all these words so that the last letter of first word is the starting letter of the next word. It's like word chain game.
For example for words "car", "gear", "rig", "rez" the sequence would be as following: car -> rig -> gear -> rez.
Now the output of this program for given set of words is only true (words can be arranged in such way) or false. There is no need to return the specific path.

Do you have any suggestions on how to solve this puzzle? I suppose creating graph and finding the Hamiltonian path is the way, but the problem is that finding Hamiltonian path is way too complex problem that will take too long for bigger input.
Thank you very much for any help
Jan

0

There are 0 best solutions below