Friday, September 26, 2025
HomeLanguagesSymPy | Prufer.to_tree() in Python

SymPy | Prufer.to_tree() in Python

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




# Python code explaining
# SymPy.Prufer.to_tree()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.to_tree()
  
# Creating 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()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.to_tree()
  
# Creating 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]]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS