For each word of length len, repeatedly remove one character from
the word, forming a word of length len-1 and check if what
forms is a word (you can use the map to find words of length len-1 and
do a contains on that set.
Any pairs that you find in this step also form a transormation
of converting one word to another by adding a single character, so
add an edge to the graph in the opposite direction.
An outline of this procedure (this code is by no means complete)
is as follows:
for( Map.Entry<Integer,Set<String>> e : theMap.entrySet( ) )
{
int theWordLen = e.getKey( );
Set<String> theWords = e.getValues( );
// You will need more work for the next line to handle theWordLen == 1
Set<String> shorterWords = theMap.get( theWordLen - 1 );
for( String s : theWords )
{
for( int i = 0; i < theWordLen; i++ )
{
String shorter = removeOneChar( s, i );
if( shorterWords.contains( shorter ) )
{
ADD TWO EDGES TO THE GRAPH
}
}
}
}