prufer_sequence#
- graph_tool.structure.prufer_sequence(g)[git][source]#
Return the Prüfer sequence of a tree.
- Parameters:
- g
Graph Tree with at least two vertices. Edge directions are ignored.
- g
- Returns:
- seq
numpy.ndarray The Prüfer sequence, of length \(V - 2\), in terms of the positions of the vertices in
get_vertices().
- seq
See also
graph_tool.generation.prufer_treeInverse operation
graph_tool.generation.generate_random_treeRandom tree
Notes
The Prüfer sequence [prufer-neuer-1918] is obtained by removing the leaf with the smallest index and recording its neighbor, \(V - 2\) times. It is a bijection between the labeled trees with \(V\) vertices and the sequences of length \(V - 2\) over \(V\) symbols, and is inverted by
prufer_tree(). The time is \(O(V)\).References
[prufer-neuer-1918]Heinz Prüfer, “Neuer Beweis eines Satzes über Permutationen”, Archiv der Mathematik und Physik 27, 142-144 (1918).
Examples
>>> g = gt.Graph([(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)], directed=False) >>> print(gt.prufer_sequence(g)) [3 3 3 4]