|
ADS
Algorithms and Data Structures
|
The tree as a vector of parents: the nodes are \( 0 , \ldots , n - 1 \), and \( p[ i ] \) is the parent of \( i \), or -1 if \( i \) is a root. More...
Go to the source code of this file.
Classes | |
| class | ADS::ParentTree |
| a tree (a forest) of the nodes \( 0 , \ldots , n - 1 \) as a vector of parents More... | |
Namespaces | |
| namespace | ADS |
The tree as a vector of parents: the nodes are \( 0 , \ldots , n - 1 \), and \( p[ i ] \) is the parent of \( i \), or -1 if \( i \) is a root.
It answers parent() alone, in \( O( 1 ) \) time and with the least memory, which is all that is needed when a tree is built and walked toward the root, as the trees of the visits of a graph; the order among siblings is lost, unless it is the one of their numbers. Since setParent() may hang any node anywhere, the structure is a forest of \( n \) isolated nodes at the start.
The contracts [see Contract.h]: the nodes are in \( [ 0 , n ) \), and a node is not its own parent. The operations are defined in ParentTree.tpp.