If you’re looking for speed, wouldn’t the quickest way be to built and compare an index and not the actual strings?
For example, I have 10 words: aaa, bbb, ccc, dog, dot, fog, hot, hog, xxx, zzz
I’d build a base index and then a connection index:
1) aaa:
2) bbb:
3) ccc:
4) dog: 5, 6, 8
5) dot: 4, 7
6) fog: 4, 8
7) hot: 5, 8
8) hog: 4, 6, 7
The only words in your list that “dog” can transform into a single letter at a time is word 5, 6, or 8…
If I want to transform word 4 (dog) into word 7 (hot), I’d just run a recursive loop checking only to see if my indexes would ever match.
START: 4
PASS 1, CHECK 1: 5 (no match to 7)
RECURSIVE PASS 2, CHECK 1 (from 5 to…) 4 (no match to 7)
RECURSIVE PASS 3, CHECK 1 (from 4 to…) NO CHECK, ALREADY COVERED
RECURSIVE PASS 2, CHECK 2 (from 5 to…) 7 (match! abort checking!!)
4 to 5 to 7
OR….
dog to dot to hot
Like this, you’d be building a recursive connection tree using the INTEGER index values, rather than any sort of string comparison. As for run times, I don’t see why you’d ever have more than a fraction of a second involved in your search routines.
You’re not checking to see if words match via character by character…. You’re just checking to see if one integer value can be chained in such a matter to reach another.
One things for certain: Index linking would definitely remove any differences in search times due to word length. 5 letter words would chain just as quickly via index as 3 letter ones…
Note: Prebuild your initial connection index once and be done with it. Don’t rebuild it with each and every search run.