Trees · Cayley's Formula
Lesson 9
The \(\texttt{networkx}\) library also has built-in methods for working with the Prüfer code.
from networkx import Graph, to_prufer_sequence, from_prufer_sequence
tree = Graph([(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)])
code = to_prufer_sequence(tree)
print(code)
print(from_prufer_sequence(code).edges())[3, 3, 3, 4]
[(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)]