avl-tree - 权重不平衡的 AVL 树

标签 avl-tree

相信维基百科文章:http://en.wikipedia.org/wiki/AVL_tree

AVL trees are height-balanced, but in general not weight-balanced nor μ-balanced;[4] that is, sibling nodes can have hugely differing numbers of descendants.



但是,作为 AVL 树是:

a self-balancing binary search tree [...]. In an AVL tree, the heights of the two child subtrees of any node differ by at most one



我不明白 AVL 是如何实现重量不平衡的,因为 - 如果我很好地理解了 AVL 树的定义 - 每个 sibling 将拥有大致相同数量的 child ,因为他们的高度相同 +/- 1。

那么,你能给我举个不平衡的 AVL 树的例子吗?我没有成功找到一个。因此,或者我误解了 AVL/未加权树的定义,或者维基百科文章是错误的......

谢谢

最佳答案

sibling nodes can have hugely differing numbers of descendants.



我只是在摸索这一点,事实上我的 AVL 实现产生的树最终并不是不平衡的,但里面有越来越大的“远亲”子树。

我勾勒出这一点来让自己放心:

enter image description here

红色节点的余额为 1,绿色节点的余额为 -1,黑色节点的余额为 0。这是一个有效的 AVL 树,因为两个兄弟子树之间的高度差永远不会超过 1,但(几乎)是两倍右子树中的许多节点作为左子树。

关于avl-tree - 权重不平衡的 AVL 树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15554694/

相关文章:

data-structures - 平衡 AVL 树

algorithm - 关于 AVL 树及其高度——我们的阅读脚本有错误吗?

c++ - 树类根节点不更新

ocaml - 为什么OCaml Map中的AVL树使用平衡因子(高度差异)2而不是1?

algorithm - 计算 AVL 树算法的时间复杂度

java - 字典实现的最佳树类型

c - 尝试创建字符串的 avl 树时出现段错误

c - 插入功能无法旋转具有不平衡因子的节点

algorithm - AVL树是邪恶的吗?

algorithm - AVL Tree的平衡过程