86. Rooted builds breadth-first with flat child ranges (2026-11-21)
- Decision.
Rootedroots its tree by breadth-first search and keeps the children ofvas the rangebfs[k0[v]..k1[v]]of the search order instead of oneListper vertex;from_parentscounting-sorts the parents into the same form. On a graph with extra edges the tree is the breadth-first tree, sodepthis the distance from the root and the old depth-first promise (every other edge joins an ancestor) is gone. - Why. Building the tree was 2.4x matched C++ (CSR + BFS): one heap list per
vertex and a stack of
(u, p, w)triples. Breadth-first order makes the children contiguous for free. Back edges and low-links belong tostd.graph, and no port relied on the depth-first tree. - Evidence.
bench/trees/root_bench: 0.63 s to 0.45 s at n = 10^6 from aTree<V>edge list (the rest isGraph.undirectedbuilding per-vertex lists for a list of pairs), and 0.30 s against 0.27 s (1.1x) from a[E]edge array. - Reverse. Restore the depth-first stack in
Rooted.buildand akid: [V]List<V>field;childrenkeeps its signature either way.