Thursday, October 9, 2025
HomeLanguagesSymPy | Prufer.tree_repr() in Python

SymPy | Prufer.tree_repr() in Python

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




# Python code explaining
# SymPy.Prufer.tree_repr()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.tree_repr()
  
# Creating Prufer
a = Prufer([1, 2, 3], [2, 4, 5])
  
# tree_repr value
# rank = 2
# n = 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




# Python code explaining
# SymPy.Prufer.tree_repr()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.tree_repr()
  
# Creating Prufer
b = Prufer([1, 2, 3, 2, 4, 5], [6, 7], [8])
  
# tree_repr value
# rank = 2
# n = 5
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]]

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

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6835 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6790 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS