An AA tree is a balanced tree structure for efficiently storing and retrieving ordered data. Professor Arne Andersson introduced it in his 1993 paper "Balanced search trees made simple" in 1993; it was designed to reduce the number of cases considered by red-black trees. An AA tree supports search, insertion, and deletion in time. The following is an example of an AA tree.

An AA tree is a variant of a red-black tree. Unlike in a red-black tree, red nodes in an AA tree can only be right children. Thus, an AA tree models a 2-3 tree rather than a 2-3-4 tree, greatly simplifying maintenance. A red-black tree's maintenance algorithm must consider seven different cases to balance the tree correctly.
Because red nodes can only be right children, an AA tree needs to consider only two cases.
Definition
An AA tree follows the same rules as a red-black tree, with one additional rule: a red node cannot be a left child.
- Every node can be red or black.
- The root is always black.
- Leaf nodes (NULL) are always black.
- Both children of a red node must be black; in other words, two adjacent red nodes are not allowed.
- Every path from the root to a NULL node contains the same number of black nodes.
- A red node can only be a right child.
Maintaining balance
Each node of an AA tree maintains a level field, just as each node of a red-black tree maintains a color field ("RED" or "BLACK"). The level satisfies the following five conditions:
-
The level of every leaf is 1.
-
The level of every left child is its parent's level minus 1.
-
The level of every right child is either its parent's level or its parent's level minus 1.
-
The level of every right grandchild is strictly less than its grandparent's level.
-
Every node whose level is greater than 1 has two children.

Horizontal link
A link whose child's level equals its parent's level is called a horizontal link, analogous to a red link in a red-black tree. A single right horizontal link is allowed, but consecutive right horizontal links are not; left horizontal links are not allowed. These restrictions are stricter than those of red-black trees, so balancing an AA tree is considerably simpler to implement.

Insertion and deletion may temporarily make an AA tree unbalanced (that is, violate an AA-tree invariant). Restoring balance requires only two operations: "skew" and "split". "Skew" performs a right rotation on a subtree containing a left horizontal link, replacing it with a subtree containing a right horizontal link. "Split" performs a left rotation and increases the level, replacing a subtree containing two or more consecutive right horizontal links with one containing fewer consecutive right horizontal links. Balanced insertion and deletion become simpler because they rely on "skew" and "split" to modify the tree only when necessary, rather than making the caller decide whether to perform either operation.
split (left rotation)
A consecutive rightward horizontal chain appears (three consecutive right children have the same level, and nodes R and X are both red).
Now rotate node T to the left, treating the nodes at or below this level as a subtree.
- The subtree root's right child becomes the new subtree root;
- The original subtree root becomes the new subtree root's left child;
- The new subtree root's level is increased by 1.
Pseudocode implementation
skew (right rotation)
A leftward horizontal chain appears (two consecutive left children have the same level).
Rotate node T to the right, treating the nodes at or below this level as a subtree.
- The subtree root's left child becomes the new subtree root;
- The original subtree root becomes the new subtree root's right child.
Pseudocode implementation
Operations on an AA tree
An AA tree is itself a binary search tree, so searching is the same as in other binary search trees. Insertion and deletion are similar to those in an AVL tree: first insert or delete the key, then backtrack along the search path to the root and reconstruct the tree along the way.
Insertion
Pseudocode implementation
Deletion
Deletion is similar to deletion in other balanced binary trees: first convert deletion of an internal node into deletion of a leaf. Replace the internal node with its closest predecessor or successor. Since every AA-tree node with level greater than 1 has two children, the predecessor or successor is at level 1, whose deletion is relatively simple.
Pseudocode implementation
Performance
The performance of an AA tree is comparable to that of a red-black tree. Although an AA tree performs more rotations, its algorithms are simpler, resulting in similar performance. Red-black trees have more consistent performance across cases, while AA trees are often flatter, giving them slightly faster searches.