code: def tree_isomorphism(t1, t2):
      """
      Given two undirected (or free) trees `t1` and `t2`,
      this routine will determine if they are isomorphic.
      It returns the isomorphism, a mapping of the nodes of `t1` onto the nodes
      of `t2`, such that two trees are then identical.
  
      Note that two trees may have more than one isomorphism, and this
      routine just returns one valid mapping.
  
      Parameters
      ----------
      t1 : undirected NetworkX graph
          One of the trees being compared
  
      t2 : undirected NetworkX graph
          The other tree being compared
  
      Returns
      -------
      isomorphism : list
          A list of pairs in which the left element is a node in `t1`
          and the right element is a node in `t2`.  The pairs are in
          arbitrary order.  If the nodes in one tree is mapped to the names in
          the other, then trees will be identical. Note that an isomorphism
          will not necessarily be unique.
  
          If `t1` and `t2` are not isomorphic, then it returns the empty list.
  
      Notes
      -----
      This runs in O(n*log(n)) time for trees with n nodes.
      """
  
      assert nx.is_tree(t1)
      assert nx.is_tree(t2)
  
      # To be isomorphic, t1 and t2 must have the same number of nodes.
      if nx.number_of_nodes(t1) != nx.number_of_nodes(t2):
          return []
  
      # Another shortcut is that the sorted degree sequences need to be the same.
      degree_sequence1 = sorted(d for (n, d) in t1.degree())
      degree_sequence2 = sorted(d for (n, d) in t2.degree())
  
      if degree_sequence1 != degree_sequence2:
          return []
  
      # A tree can have either 1 or 2 centers.
      # If the number doesn't match then t1 and t2 are not isomorphic.
      center1 = nx.center(t1)
      center2 = nx.center(t2)
  
      if len(center1) != len(center2):
          return []
  
      # If there is only 1 center in each, then use it.
      if len(center1) == 1:
          return rooted_tree_isomorphism(t1, center1[0], t2, center2[0])
  
      # If there both have 2 centers,  then try the first for t1
      # with the first for t2.
      attempts = rooted_tree_isomorphism(t1, center1[0], t2, center2[0])
  
      # If that worked we're done.
      if len(attempts) > 0:
          return attempts
  
      # Otherwise, try center1[0] with the center2[1], and see if that works
      return rooted_tree_isomorphism(t1, center1[0], t2, center2[1])
  
file_path: networkx/networkx/algorithms/isomorphism/tree_isomorphism.py
imports: import networkx
  from networkx.utils.decorators import not_implemented_for
label_desc: Use image node_id 6 for calling a global function with example usage: tree_isomorphism(t1, t2) and returns: rooted_tree_isomorphism, list, list, list, rooted_tree_isomorphism, attempts