SymPy | Prufer.tree_repr() in Python
Last Updated :
26 Aug, 2019
Prufer.tree_repr() : tree_repr() is a sympy Python library function that returns the tree representation of Prufer sequence.
Syntax :
sympy.combinatorics.Prufer.prufer.tree_repr()
Return :
tree representation of Prufer sequence
Code #1 : tree_repr() Example
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
a = Prufer([ 1 , 2 , 3 ], [ 2 , 4 , 5 ])
print ( "Prufer a tree_repr : " , a.tree_repr)
|
Output :
Prufer a tree_repr : [[0, 1], [1, 2], [2, 3], [3, 4]]
Code #2 : tree_repr() Example
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
b = Prufer([ 1 , 2 , 3 , 2 , 4 , 5 ], [ 6 , 7 ], [ 8 ])
print ( "Prufer b tree_repr : " , b.tree_repr)
|
Output :
Prufer b tree_repr : [[0, 1], [1, 2], [3, 6], [2, 3], [2, 4], [4, 5], [5, 7]]
Share your thoughts in the comments
Please Login to comment...