Balanced Trees
Trees are optimal data structures for dynamic sets as their implementation allows us to reduce
We can use some declinations of the binary tree to improve its balance
AVL Trees
AVL trees are BST that are always balanced.
For every node
- A key of any kind,
- Balancing Factor (BF),
- An integer indicating the difference between the height of the left-subtree and the height of the right-subtree.
- In an AVL Tree, for each node
for every node x.
This complicates the operations of insertion and extraction because we need to maintain the BF.
B-Trees
B-Trees are balanced BST of degree t (with t>=2). They are not necessarily binary trees.
However, they must satisfy the following conditions:
- Every leaf has the same depth
- Every node (except for the root) saves
sorted keys. - Where
, with
- Every node
(except for the root) have - The root saves
ordered keys - Every internal node
, has children - The keys
separates the intervals of keys saved in each subtree: - If
is a key in the i-ary subtree of a node , then with as the number of the children.
- If

The keys being ordered reduced to a cost
Red and Black Trees
Red and black trees are BST almost balanced.
Their main feature is that their nodes contain one more piece of information about themselves: the color of the node.
- Black
- Red
They must also respect the following conditions:
- Every node is either black or red
- The root node is initially black
- Every leaf is black and contains NULL
- Both children of a red node, are black
- Every path from a node x to a leaf (contained in x's subtree) has the same number of black nodes.
If all these conditions are to be found in a BST, then a RB Tree also guarantees the following invariant: The longest path of the tree cannot be longer than double the smallest path.
Here again, most operations have a reduced cost equal to