trees /returns true if word and word are the same length /and differ in only one character bool onecharoffconst string word const string word ifword length!word lengthreturn falseint diffs forint word length)++ ifword !word if++diffs return falsereturn diffs = figure routine to check if two words differ in only one character /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 algorithm mapcomputeadjacentwordsconst vector words mapadjwordsforint words size)++ forint words size)++ ifonecharoffwordsi ]wordsj adjwordswordsi push_backwordsj )adjwordswordsj push_backwordsi )return adjwordsfigure function to compute map containing words as keys and vector of words that differ in only one character as values this version runs in minutes on an , word dictionary store each collectionand the same idiom applies the code is shown in figure line shows the declaration for the second maplines and populate the mapand then an extra loop is used to iterate over each group of words compared to the first algorithmthe second algorithm is only marginally more difficult to code and runs in secondsor about six times as fast