I have a class that I'm using to find the shortest word ladder between two words. Each "Step" in that ladder is returned as a String element in a LinkedList. If it can't find one, it returns an empty LinkedList. The class is only intended to work with capital letters.

A step can only be formed from a word in the HashSet<String> dictionary variable.

I haven't made anything like this before, and I'm posting here because I'd appreciate help making it run faster and advice regarding how to make the code itself more easily read by other humans.

Parsing input could be performed in other method while this one would accept two strings: initial and final word. That way it's much more versatile like Sharon Ben Asher mentioned.

Code most likely works but you just can't see what is really doing. Either commenting or extracting vital parts of algorithm into named methods would most likely shed some light.

I would really suggest trying to implement graph based algorithm where nodes are words and edges connect words with distance of 1. That way you could construct Graph once and use for example Dijkstra's algorithm to determine shortest path between two given nodes if it exists. Complexity would be O(n^2) where n is number of words. It could be a bit more intuitive with a bit of an explanation and possibly faster on multiple runs.

API definition: the api you chose is counter-intuitive. why not accept two string words?

code to the interface: if you meant words to be a LIFO stack, use the Stack interface of push() and pop(). there are two reason for that: one is that it makes the usage of words clearer to another human. more importantly - how do you that LinkedListadd() is doing the same as push()?

the method violates the single responsibility principle. it is parsing the input, it searches for a word in the dictionary and all the other stuff. what if you wanted to have another data structure for the dictionary? or put it in a DB?

\$\begingroup\$Sorry, I only intended it to work with uppercase letters, but I forgot to make that clear. My bad. If you run it with capital letters it will work. I will edit my question.\$\endgroup\$
– LuminousNutriaMay 7 at 13:37

\$\begingroup\$Also, the LinkedLists are not utilized as Stacks, but as Queues.\$\endgroup\$
– LuminousNutriaMay 7 at 13:44

\$\begingroup\$all the more reason to use the proper interface. queue does not have pop().\$\endgroup\$
– Sharon Ben AsherMay 7 at 13:53