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

An ordered tree in a vector in preorder, beyond the book: the place \( i \) holds the value of the \( i \)-th node of the previsit and the place of its parent, NIL for the root in the place 0. More...

#include "ADS/Contract.h"
#include <ranges>
#include <stdexcept>
#include <vector>
#include "ADS/tree/impl/PreorderArrayTree.tpp"

Go to the source code of this file.

Classes

class  ADS::PreorderArrayTree< T >
 an ordered tree in a vector of ( parent , value ) in preorder More...

Namespaces

namespace  ADS

Detailed description

An ordered tree in a vector in preorder, beyond the book: the place \( i \) holds the value of the \( i \)-th node of the previsit and the place of its parent, NIL for the root in the place 0.

The subtree of a node is the stretch of the vector that starts with it and ends before the first place whose parent precedes it, so that the first child of \( i \), if any, is \( i + 1 \), and the next sibling is the place after its subtree. Reading and writing take \( O( 1 ) \) time, moving along the tree and inserting or removing a subtree \( O( n ) \), since the places after it shift and their parents are renumbered. It extends the vector of parents of section 5.4 [see ParentTree.h] with the values and the order of the children.

The contracts [see Contract.h]: a node is a place of the vector, and a sibling is inserted next to a node that is not the root; the invariant is that the root comes first and each other node after its parent. The operations are defined in PreorderArrayTree.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