(prufer)
return tree
Return the tree (as a list of edges) of the given Prufer sequence.

        Examples
        ========

        >>> from sympy.combinatorics.prufer import Prufer
        >>> a = Prufer([0, 2], 4)
        >>> a.tree_repr
        [[0, 1], [0, 2], [2, 3]]
        >>> Prufer.to_tree([0, 2])
        [[0, 1], [0, 2], [2, 3]]

        References
        ==========

        - http://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html

        See Also
        ========
        tree_repr: returns tree representation of a Prufer object.
Return the tree (as a list of edges) of the given Prufer sequence.
Return the tree ( as a list of edges ) of the given Prufer sequence .
def to_tree(prufer):
        """Return the tree (as a list of edges) of the given Prufer sequence.

        Examples
        ========

        >>> from sympy.combinatorics.prufer import Prufer
        >>> a = Prufer([0, 2], 4)
        >>> a.tree_repr
        [[0, 1], [0, 2], [2, 3]]
        >>> Prufer.to_tree([0, 2])
        [[0, 1], [0, 2], [2, 3]]

        References
        ==========

        - http://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html

        See Also
        ========
        tree_repr: returns tree representation of a Prufer object.

        """
        tree = []
        last = []
        n = len(prufer) + 2
        d = defaultdict(lambda: 1)
        for p in prufer:
            d[p] += 1
        for i in prufer:
            for j in xrange(n):
            # find the smallest leaf (degree = 1)
                if d[j] == 1:
                    break
            # (i, j) is the new edge that we append to the tree
            # and remove from the degree dictionary
            d[i] -= 1
            d[j] -= 1
            tree.append(sorted([i, j]))
        last = [i for i in xrange(n) if d[i] == 1] or [0, 1]
        tree.append(last)

        return tree
def to_tree ( prufer ) : tree = [ ] last = [ ] n = len ( prufer ) + 2 d = defaultdict ( lambda : 1 ) for p in prufer : d [ p ] += 1 for i in prufer : for j in xrange ( n ) : # find the smallest leaf (degree = 1) if d [ j ] == 1 : break # (i, j) is the new edge that we append to the tree # and remove from the degree dictionary d [ i ] -= 1 d [ j ] -= 1 tree . append ( sorted ( [ i , j ] ) ) last = [ i for i in xrange ( n ) if d [ i ] == 1 ] or [ 0 , 1 ] tree . append ( last ) return tree