平衡二叉树的追求的是全局均衡,如在做插入,删除操作时,需要调整整棵树,显然这是费时的,因此希望在做调整时,是局部调整,因此提出了红黑树,这样一种高效的数据结构(也是最变态的一种数据结构)。
红黑树属于非严格意义上的平衡二叉树,说它不严格是因为它不是严格控制左、右子树高度或节点数之差小于等于1。但红黑树高度依然是平均log(n),且最坏情况高度不会超过2log(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. ”
红黑树属于非严格意义上的平衡二叉树,说它不严格是因为它不是严格控制左、右子树高度或节点数之差小于等于1。但红黑树高度依然是平均log(n),且最坏情况高度不会超过2log(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. ”
32位Windows系统中,进程在用户态可用的地址空间范围是低2G(x64下是低8192G)。随着进程不断的申请和释放内存,这个2G的地址空间,有的地址范围是保留状态(reserved),有的地址范围是提交状态(映射到了物理页面,committed),有的地址范围是空闲的。Windows采用平衡二叉树把这些离散的地址范围管理起来。
Linux内核进程调度使用红黑树进行管理。
常见的平衡二叉树有红黑树和AVL树两种,其中红黑树应用更广,C#/Java/C++STL等若干数据结构内部都是用红黑树实现的,然而Windows这次选择了AVL树。根据 《数据结构与算法C语言描述》,AVL树的最大高度是1.44 * log(N+2) - 1.328,红黑树的最大高度是2.00* log(N+1)。与红黑树相比,AVL树的插入删除操作更慢一些,但是查询操作更快。想必对进程地址空间的查询操作更频繁一些,所以AVL得以入选。
常见的平衡二叉树有红黑树和AVL树两种,其中红黑树应用更广,C#/Java/C++STL等若干数据结构内部都是用红黑树实现的,然而Windows这次选择了AVL树。根据 《数据结构与算法C语言描述》,AVL树的最大高度是1.44 * log(N+2) - 1.328,红黑树的最大高度是2.00* log(N+1)。与红黑树相比,AVL树的插入删除操作更慢一些,但是查询操作更快。想必对进程地址空间的查询操作更频繁一些,所以AVL得以入选。