RBT VS. AVL

来源:互联网 发布:阿里云翼 编辑:程序博客网 时间:2024/06/08 03:05

搜索了很久RBT和AVL的差别,先粘贴整理一下在网络上查找到的有价值的信息:


“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. ”

关于选择:

1. RBT侧重局部调整,所以有益于对于insertion、deletion多的应用场景(或者与query三者比较平均的情况),在stl::map以及linux下广泛应用;

2. AVL侧重整体调整,对于每一个insertion和deletion操作会对路径上所有的结点进行调整,有益于query较多的场景。

原创粉丝点击