degree_sequence_tree#
- graph_tool.generation.degree_sequence_tree(deg)[git][source]#
Return a tree with the given degree sequence.
- Parameters:
- degiterable of
int Degree sequence, with all values positive (unless it is
[0]) and sum \(2(N-1)\).
- degiterable of
- Returns:
- g
Graph The undirected tree, whose vertex degrees are a permutation of
deg.
- g
See also
realize_degree_sequenceGraph with a given degree sequence
generate_power_law_treeRandom trees with power-law degrees
prufer_treeTree with a given Prüfer sequence
Notes
The result is a caterpillar tree. If \(d_1\le\dots\le d_n\) are the degrees larger than one, in increasing order, the tree consists of the path \(0, 1, \dots, n+1\), where the inner vertex \(i\) has the degree \(d_i\) and the end vertices \(0\) and \(n+1\) are leaves, and of \(d_i - 2\) further leaves attached to every inner vertex \(i\), with the indices \(n+2,\dots, N-1\). The vertices are therefore not in the order of
deg. The algorithm runs in time \(O(N\log N)\).Examples
>>> g = gt.degree_sequence_tree([3, 3, 2, 1, 1, 1, 1]) >>> print(sorted(g.get_out_degrees(g.get_vertices()).tolist())) [1, 1, 1, 1, 2, 3, 3]
The tree is drawn as follows, with the vertices labeled by their degrees:
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... vertex_text=g.degree_property_map("total"), ... output="degree_sequence_tree-example.pdf") <...>
Caterpillar tree with the degree sequence \((3, 3, 2, 1, 1, 1, 1)\). The vertex labels are the degrees.#