Rooting trees and parent arrays #
Two ways of presenting a rooted tree.
- Rooting a tree. For a tree
Tonιand a rootr,SimpleGraph.IsTree.pathTo hT r tis the unique path fromttor.SimpleGraph.IsTree.parent hT r tis its second vertex: the neighbour ofton the way tor, orritself whent = r. Every edge ofTjoins a vertex to its parent (SimpleGraph.IsTree.adj_iff_parent), and the parent is one step closer to the root (SimpleGraph.IsTree.length_pathTo_parent). - Parent arrays. A map
p : Fin (n + 1) → Fin (n + 1)withp i < ifor everyi ≠ 0determines the graphSimpleGraph.parentTree p, which joins eachi ≠ 0top i. It is a tree (SimpleGraph.parentTree_isTree). In such a tree a preconnected vertex set has at most one vertex whose parent lies outside it (SimpleGraph.eq_of_preconnected_parentTree).
Parent arrays are the input format of tree-decomposition algorithms; rooting is how an arbitrary finite tree is brought into that format.
Main definitions #
SimpleGraph.IsTree.pathTo,SimpleGraph.IsTree.parent: rooting a tree.SimpleGraph.parentTree: the tree of a parent array.SimpleGraph.parentGraph: the graph of a parent function on any vertex type.
Main results #
SimpleGraph.IsTree.adj_iff_parent: the edges of a rooted tree are the parent edges.SimpleGraph.parentTree_isTree: a parent array withp i < ifori ≠ 0gives a tree.SimpleGraph.eq_of_preconnected_parentTree: a preconnected set in a parent-array tree has a unique topmost vertex.SimpleGraph.parentTree_eq_parentGraph: the two parent graphs agree whenp 0 = 0.
Rooting a tree #
The unique path in the tree T from t to the root r.
Instances For
The parent of t when T is rooted at r: the second vertex of the path from t to r, or
r itself when t = r.
Instances For
Parent arrays #
The graph of a parent array on Fin (n + 1): each i ≠ 0 is joined to p i. When
p i < i for every i ≠ 0 this is a tree rooted at 0 (parentTree_isTree).
Instances For
The graph of a parent function p : ι → ι on any vertex type: x and y are adjacent when one
is the parent of the other. Fixed points of p (roots) give no self-loops. Unlike parentTree,
there is no fixed root and no order condition; when p 0 = 0 the two graphs agree
(parentTree_eq_parentGraph).
Instances For
In a parent-array tree, a preconnected vertex set has at most one topmost element: one that
is the root 0 or whose parent lies outside the set.