AA Tree

Based on“Data Structures and Algorithm Analysis Edition 3.2 (C++ Version)” from C. A. Shaffer

Proporties

AA Tree is a variation of the red-black tree, whose red nodes can only be added as a right subchild, which greatly simplifies the maintenance operations.
AA trees require O(log(N)) bits of metadata per node, in the form of an integer “level”. The following invariants hold for AA trees:
- The level of every leaf node is one.
- The level of every left child is exactly one less than that of its parent.
- The level of every right child is equal to or one less than that of its parent.
- The level of every right grandchild is strictly less than that of its grandparent.
- Every node of level greater than one has two children.
According to the invariants above, if all the edges point to the red nodes are drawn horizontally, the leaf nodes will be at the same level.
AA Tree
Individual right horizontal links are allowed, but consecutive ones are forbidden; all left horizontal links are forbidden. When forbidden case rises, rebalancing is needed.

Operation

Skew

Skew operation is used for dealing with the first forbidden case. Skew is a right rotation to replace a subtree containing a left horizontal link with one containing a right horizontal link instead.
Skew

Split

Split operation is used for dealing with the second forbidden case. Split is a left rotation and level increase to replace a subtree containing two or more consecutive right horizontal links with one containing two fewer consecutive right horizontal links.
Split

Insert

Insertion begins with the normal binary tree search and insertion procedure. Then check forbidden cases and take corresponding operations, until all the forbidden cases are solved.

Remove

The first step of removing is the same as that in a BST: if internal, exchange it with the leftest leaf in the right subtree, then delete the leaf.
After a removal, the first step to maintaining tree validity is to lower the level of any nodes whose children are two levels below them, or who are missing children. Then, the entire level must be skewed and split. This approach was favored, because when laid down conceptually, it has three easily understood separate steps:
1. Decrease the level, if appropriate.
2. Skew the level.
3. Split the level.
Here’s an example:
Try to delete node 15:
这里写图片描述
Do skew to node 30, solve the left horizontal link problem from 30 to 23:
这里写图片描述
Do skew to node 30, solve the left horizontal link problem from 30 to 25:
这里写图片描述
Do split to node 25:
这里写图片描述
Finish.
这里写图片描述

Performance

The performance of an AA tree is equivalent to the performance of a red-black tree. While an AA tree makes more rotations than a red-black tree, the simpler algorithms tend to be faster, and all of this balances out to result in similar performance.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值