Create a graph where node numbers are indexes in pset [ ] and there is an edge between two nodes only if they differ by single digit .
g = Graph ( len ( pset ) ) NEW_LINE for i in range ( len ( pset ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( pset ) ) : NEW_LINE INDENT if ( compare ( pset [ i ] , pset [ j ] ) ) : NEW_LINE INDENT g . addedge ( i , j ) NEW_LINE DEDENT DEDENT DEDENT