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

A binary tree in a positional vector, beyond the book: the root in the place 0, the children of the place \( i \) in \( 2 i + 1 \) and \( 2 i + 2 \), its parent in \( \lfloor ( i - 1 ) / 2 \rfloor \) [see dary_child()], an empty place where no node is. More...

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/queue/ArrayQueue.h"
#include "ADS/tree/BinaryTree.h"
#include <cstddef>
#include <optional>
#include <ranges>
#include <stdexcept>
#include <string>
#include <vector>
#include "ADS/tree/impl/ArrayBinaryTree.tpp"

Go to the source code of this file.

Classes

class  ADS::ArrayBinaryTree< T >
 a binary tree in a positional vector More...
struct  ADS::ArrayBinaryTree< T >::Used
 the places in use, for SlotIterator More...

Namespaces

namespace  ADS

Detailed description

A binary tree in a positional vector, beyond the book: the root in the place 0, the children of the place \( i \) in \( 2 i + 1 \) and \( 2 i + 2 \), its parent in \( \lfloor ( i - 1 ) / 2 \rfloor \) [see dary_child()], an empty place where no node is.

Moving along the tree, reading and writing take \( O( 1 ) \) time; the vector grows to the deepest place used, so that a tree of height \( h \) takes \( O( 2^h ) \) space, which suits the trees nearly complete. insertLeft() and insertRight() copy a whole tree under a node and remove() empties a subtree, in time linear in the places of the subtree. A node is a place, NIL if missing.

The contracts [see Contract.h]: read() and write() need a node, setRoot() an empty tree, and a subtree is inserted under a node where no child is; the invariant is that each node but the root has its parent. The operations are defined in ArrayBinaryTree.tpp.

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