ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ParentTree.h File Reference

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...

#include "ADS/Contract.h"
#include <vector>
#include "ADS/tree/impl/ParentTree.tpp"

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

Detailed description

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.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 5.4, https://algoritmicamente.it/materiali/libro/capitoli/cap05.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa