AA trees use the concept of levels to aid in balancing binary trees. The level of node (instead of colour) is used for balancing information. A link where child and parent’s levels are same, is called a horizontal link, and is analogous to a red link in the red-black tree.
- The level of every leaf node is one.
- The level of red nodes are same as the level of their parent nodes and the links are called horizontal links.
- The level of black nodes are one less than the level of their parent node.
Additional storage requirement with every node is O(Log n) in red black trees instead of O(1) (only color in Red Black Trees), but AA trees simplify restructuring by removing many cases.
An AA tree follows same rule as red-black trees with the addition of single new rule that red nodes cannot be present as left child.
- Every node can be either red (linked horizontally) or black.
- There are no two adjacent red nodes (or horizontal links).
- Every path from root to a NULL node has same number of black nodes (ot black links).
- Left link cannot NOT be red (horizontal). (New added rule)
Why AA trees :
The implementation and number of rotation cases in Red-Black Trees is complex. AA trees simplifies the algorithm.
- It eliminates half of the restructuring process by eliminating half of the rotation cases, which is easier to code.
- It simplifies the deletion process by removing multiple cases.
Below tree is the example of AA tree :
Note that in the above tree there are no left red child which is the new added rule of AA Trees.
After re-drawing the above AA tree with levels and horizontal links (the red nodes are shown connected through horizontal or red links), the tree looks like:
Note that all the nodes on level 1 i.e. 5, 10, 20, 35, 40, 55, 65, 80, 90 are known as leaf nodes.
So, in summarized way, for tree to be AA tree, it must satisfy the following five invariants:
1.) The level of leaf node is 1.
- Generic Trees(N-array Trees)
- proto van Emde Boas Trees | Set 1 (Background and Introduction)
- Wavelet Trees | Introduction
- Disjoint Set Union on trees | Set 1
- Disjoint Set Union on trees | Set 2
- Check if two trees are Mirror | Set 2
- Dynamic Programming on Trees | Set-1
- Dynamic Programming on Trees | Set 2
- DP on Trees | Set-3 ( Diameter of N-ary Tree )
- Proto Van Emde Boas Trees | Set 4 | Deletion
- m-WAY Search Trees | Set-1 ( Searching )
- Extended Disjoint Set Union on Trees
- Write Code to Determine if Two Trees are Identical
- Foldable Binary Trees
- Decision Trees - Fake (Counterfeit) Coin Puzzle (12 Coin Puzzle)
- Print Common Nodes in Two Binary Search Trees
- Find all possible binary trees with given Inorder Traversal
- Iterative function to check if two trees are identical
- Number of full binary trees such that each node is product of its children
- Find first non matching leaves in two binary trees
2.) The level of left child is exactly one less than of its parent.
3.) The level of every right child is equal to or one less than of its parent.
4.) The level of every right grandchild is strictly less than that of its grandparent.
5.) Every node of level greater than one has two children.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.