AVL树

 AVL树是普通二叉查找树的变形,查找效率会比红黑树好,但是由于要求更严格,所以插入和删除比红黑树消耗大。

定义:

1>它的左子树和右子树都是AVL树
2>左子树和右子树的高度差不能超过1
从条件1可能看出是个递归定义,如GNU一样.

性质:

1>一棵n个结点的AVL树的其高度保持在0(log2(n)),不会超过3/2log2(n+1)
2>一棵n个结点的AVL树的平均搜索长度保持在0(log2(n)).
3>一棵n个结点的AVL树删除一个结点做平衡化旋转所需要的时间为0(log2(n)).

性能:实际效率和插入节点的分布有关系。

AVL trees are actually easier to implement than RB trees because there are fewer cases. And AVL trees require O(1) rotations on an insertion, whereas red-black trees require O(lg n).
In practice, the speed of AVL trees versus red-black trees will depend on the data that you're inserting. If your data is well distributed, so that an unbalanced binary tree would generally be acceptable (i.e. roughly in random order), but you want to handle bad cases anyway, then red-black trees will be faster because they do less unnecessary rebalancing of already acceptable data.On the other hand, if a pathological insertion order (e.g. increasing order of key) is common, then AVL trees will be faster, because the stricter balancing rule will reduce the tree's height.
Splay trees might be even faster than either RB or AVL trees,depending on your data access distribution. And if you can use a hash instead of a tree, then that'll be fastest of all.

实现特点:

a)包括插入的递归和非递归操作,删除的递归和非递归操作。
b)递归函数主要是在递归语句后面加上旋转语句,但要注意真正插入和删除语句并不要旋转操作。

c)非递归插入删除操作是在普通BST操作的基础上加上平衡“上滤”操作完成的,和堆的“上滤”操作思想差不多。从不平衡点开始执行旋转操作一直到“根”或者在“上滤”路径中某个节点符合条件。当然在判断是否要执行旋转之前要更新其高度!!

d)在AVLNode中加入一个parent域后非递归操作比递归似乎更简单,当然递归操作中的对parent操作并不需要,只是为了和非递归操作兼容而强行加入的。

--------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值