Efficiently build a graph of words with given Hamming distance
问题 I want to build a graph from a list of words with Hamming distance of (say) 1, or to put it differently, two words are connected if they only differ from one letter ( lo l -> lo t ). so that given words = [ lol, lot, bot ] the graph would be { 'lol' : [ 'lot' ], 'lot' : [ 'lol', 'bot' ], 'bot' : [ 'lot' ] } The easy way is to compare every word in the list with every other and count the different chars; sadly, this is a O(N^2) algorithm. Which algo/ds/strategy can I use to to achieve better