+

SymPy | Prufer.to_tree () in Python

Prufer.to_tree (): to_tree () — nice Python library function that returns a tree view of a Prufer sequence.

Syntax:
sympy.combinatorics.Prufer.prufer.to_tree ()

Return:
representation of the Prufer sequence

Code # 1: to_tree () example

# Python code explaining
# SymPy.Prufer.to_tree ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer

  
# Used from
# sympy.combinatorics.prufer.Prufer .to_tree ()

 
# Create Prufer

a = Prufer ([ 1 , 2 , 3 ], [ 2 , 4 , 5 ], 4 )

 
# to_tree value

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

# Python code explaining
# SymPy.Prufer.to_tree ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer 

 
# Use from
# sympy.combinatorics.prufer.Prufer.to_tree ()

 
# Create Prufer

b = Prufer ([ 1 , 2 , 3 , 2 , 4 , 5 ], [ 6 , 7 ], [ 8 ], 4 )

  
# to_tree value

print ( "Prufer b to_tree:" , Prufer.to_tree ([ 0 , 2 ]))

Output:

Prufer b to_tree: [[0, 1], [0, 2], [2, 3]]

Get Solution for free from DataCamp guru