Let the input words be , let be their common length, let be the finite alphabet, and let contain the dictionary words of length . Unequal input lengths immediately make the puzzle impossible because a mutation preserves length. A word ladder search problem can use the state space , with initial state ; including handles an input word not itself in the dictionary.
At word , an action is a position–letter pair with , and , permitted precisely when replacing by gives . The search transition model returns that , and the goal test is . If , the empty sequence is accepted; if and , no transition can reach .
Assign each permitted transition cost . A search node at search depth hasThus minimizing path cost is exactly minimizing the number of mutations. Uniform-cost search, with repeated states handled by graph search and the goal test on selection, finds a shortest word ladder if one exists. Because all costs are equal, breadth-first search gives the same optimal-length guarantee.
Articles by others on the same topic
There are currently no matching articles.