BFS or DFS for string conversion (using dictionary)

Hello, I came across an interesting problem of finding the shortest chain of steps required to transform a string into a different target string of the same length.

Each "step" would be changing one letter within the string.

1
2
3
4
5
6
7
Example:

Input:  Dictionary = {POON, PLEE, SAME, POIE, PLEA, PLIE, POIN}
             start = TOON
             target = PLEA
Output: 7
Explanation: TOON - POON - POIN - POIE - PLIE - PLEE - PLEA


My logic was to start at the given word and check its adjacent words (differing by one letter in the dictionary), and keep doing so until we reached the target word. I was originally thinking of BFS, but that was assuming a word would not have many valid adjacent words (not very wide, so memory won't be an issue).

Would BFS or DFS be better in this situation?

Thank you!
> Would BFS or DFS be better in this situation?
finding the shortest chain of steps



> (not very wide, so memory won't be an issue)
you've got to store the entire dictionary, making a duplicate shouldn't hurt you so much.
Topic archived. No new replies allowed.