Can you traverse from any given word to any other one of equal length by changing one letter at a time?

70 Views Asked by At

This question is inspired by the word game game weaver where you are tasked to do what is in the title for two given words. However is this possible for any pair of dictionary words? Is there a way to mathematically/logically model this? I've made a program to manually search for connections between two four letter words but I'm curios what the theoretical side of the problem entails and I don't know where to start.

1

There are 1 best solutions below

0
On

It depends on your dictionary.

You would model it as a graph with each word being a node and edges between nodes/words that differ by exactly one letter.

For example, say your dictionary consisted of just four words: "cat", "dog", "cot", and "pat". Each of those words would be a node. There would be an edge between words that differ by exactly one letter - the edges for the example would be ("cat", "cot") and ("cat", "pat"). Given a start word and a target word, if there exists a path in the graph from the start word/node to the target word/node, then it would be possible; otherwise, it would not be possible. In the example, it would be possible to go between "cat", "cot", and "pat", but it would not be possible to go from "dog" to any of the other words. In terms of graph theory, this graph would have two connected components, one being ("cat", "cot", "pat") and the other being ("dog"). There would be a path between any two words of the same connected component, but no path between two words of different connected components.

Now, if you added the word "cog" to your dictionary then there would be an two new edges ("dog", "cog") and ("cog", "cot") which would connect the previously separate connected components into one -- there would now be only one connected component and it would be possible to go between "cat", "dog", "cot", "pat", and "cog".