Expand description
Symmetric tree constructor (ALGO-CN-005).
Counterpart of igraph_symmetric_tree() in
references/igraph/src/constructors/regular.c:706-808.
A symmetric tree is a rooted tree where every vertex at depth d
has exactly branches[d] children. Unlike kary_tree, where every
internal vertex has the same number of children, a symmetric tree
lets the branching factor vary per level — for example
branches = [3, 2, 2] produces a tree where the root has 3 kids,
each of those has 2, and each of those has 2 again (so the leaves
sit at depth 3).
Vertex layout follows the same BFS scheme as kary_tree: vertex 0
is the root, then all depth-1 vertices in arrival order, then all
depth-2 vertices in their arrival order, and so on. Arc direction is
controlled by the shared TreeMode enum:
TreeMode::Out— directed, every edge flows from parent to child (parent → child).TreeMode::In— directed, every edge flows from child to parent (child → parent).TreeMode::Undirected— undirected; raw endpoints are(parent, child)but stored as canonical(min, max)byGraph::add_edges.
The C implementation walks one BFS level at a time, expanding every
parent of that level in turn, pushing exactly branches[k] outgoing
arcs per parent. The Rust port mirrors that level-by-level loop.
Vertex count is 1 + Σ_{i=0..d} Π_{j=0..=i} branches[j]. Empty
branches collapses to the singleton root (n = 1, 0 edges).
Edge counts:
branches.is_empty()— singleton root, no edges.- non-empty
branches—n - 1edges (always a tree).
Time complexity: O(|V|).
Functions§
- symmetric_
tree - Build a symmetric tree where each vertex at depth
dhasbranches[d]children.