/computes map in which the keys are words and values are vectors of words /that differ in only one character from the corresponding key /uses quadratic algorithmbut speeds things up little by /maintaining an additional map that groups words by their length mapcomputeadjacentwordsconst vector words mapadjwordsmapwordsbylength/group the words by their length forauto thisword words wordsbylengththisword lengthpush_backthisword )/work on each group separately forauto entry wordsbylength const vector groupswords entry secondforint groupswords size)++ forint groupswords size)++ ifonecharoffgroupswordsi ]groupswordsj adjwordsgroupswordsi push_backgroupswordsj )adjwordsgroupswordsj push_backgroupswordsi )return adjwordsfigure function to compute map containing words as keys and vector of words that differ in only one character as values it splits words into groups by word length this version runs in seconds on an , -word dictionary our third algorithm is more complex and uses additional mapsas beforewe group the words by word lengthand then work on each group separately to see how this algorithm workssuppose we are working on words of length first we want to find word pairssuch as wine and ninethat are identical except for the first letter one way to do this is as followsfor each word of length remove the first characterleaving three-character word representative form map in which the key is the representativeand the value is vector of all words that have that representative for instancein considering the first character of the four-letter word grouprepresentative "inecorresponds to "dine""fine""wine""nine""mine""vine""pine""linerepresentative "ootcorresponds to "boot""foot""hoot""loot""soot""zooteach individual vector that is value in this latest map forms clique of words in which any word can be changed to any other word by one-character substitutionso after this latest map is constructedit is easy to traverse it and add entries to the original map that is being computed we would then proceed to