Reputation: 167
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
Upvotes: 0
Views: 57