Algorithm for converting one word to another word by changing each letter to an iteration, which should be another meaningful word?

I want to make an algorithm for changing one word to another. For example, the given word is “MUD” and I need to convert it to “BED”. For each iteration, I can change one character, but this should form another meaningful word. For example, "MUD" may be changed to "MAD". I need to find the shortest way to convert "MUD" to "BED".

A separate method is provided for finding a valid word. IsWord () is a method that will give us a logical result whether a given string is valid or not. Therefore, do not worry about it.

I also don't need to worry about performance or lines of code, etc. Anyone have an idea how to make this algorithm. If yes, please help me.

Thanks at Advance.

(I know that we should use the tree and do a binary traversal, but I don't know how to use it in this algorithm)

+5
source share
4 answers

This is called word ladder . Check the post The Longest Word Ladder Puzzle on Wolfram's Blog.

+10
source

(). / ( ) . . , , .

, . , (, ) . , , , , , .

+3

:

node, , .

.

See http://en.wikipedia.org/wiki/Shortest_path_problem for how to calculate the shortest path.

+2
source

At each iteration, make all possible new words from the words that you have, and collect them in a list, set or whatever. Filter out duplicates and words that you had before. For instance:

1. (BED)
2. (BAD, BET, ....)
3. (MAD, BAN, ...., BUT, BOT, ....)

You either get an empty list, then the problem is not solvable, or the search word is in the list.

+1
source

All Articles