SymPy | Prufer.nodes () in Python

Python Methods and Functions

Prufer.nodes (): node () — nice Python library function that returns the number of nodes in a tree.

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

Return:
the number of nodes in the tree

Code # 1: Example node ()

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

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer

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

 
# Create Prufer

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

 
number of nodes

print ( "Prufer a nodes:" , a.nodes)

Output: < / p>

Prufer a nodes: 5

Code # 2: node () Example

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

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer

  
# Using from
# sympy.combinatorics.prufer.Prufer.nodes ()

 
# Create Prufer

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

 
number of nodes

print ( " Prufer b nodes: " , b. nodes)

Output:

Pr ufer b nodes: 8





Get Solution for free from DataCamp guru