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