保持AVL树平衡,而不旋转而不、AVL

2023-09-11 06:27:27 作者:推开苍白的厮守

B +树像AVL树自平衡树。 这里我们可以看到左,右旋转用于保持AVL树平衡。

B Tree is self balancing tree like AVL tree. HERE we can see how left and right rotations are used to keep AVL tree balanced.

和这里是说明在插入一个链接B +树。这种插入技术不涉及任何旋转,如果我没有错,以保持树的平衡。因此它看起来简单。

And HERE is a link which explains insertion in B tree. This insertion technique does not involve any rotations, if I am not wrong, to keep tree balanced. And therefore it looks simpler.

问:是否有任何类似的(或不使用旋转任何其他技术),以保持AVL树平衡

Question: Is there any similar (or any other technique without using rotations) to keep avl tree balanced ?

推荐答案

答案是...是的,没有。

The answer is... yes and no.

B树不需要进行旋转,因为它们具有与它们可以多少不同的密钥包成节点中的某些松弛。当您添加越来越多的按键成B树,你能避免树变得渐行渐远,通过吸收那些键进入节点本身。

B-trees don't need to perform rotations because they have some slack with how many different keys they can pack into a node. As you add more and more keys into a B-tree, you can avoid the tree becoming lopsided by absorbing those keys into the nodes themselves.

二叉树没有这种奢侈。如果插入钥匙插入一个二叉树,它会增加在该树的一些分支的身高1在所有情况下,因为这关键需要进入其自己的节点。轮作确保,如果某些部门过度发展,也高度洗牌成树的其余部分打击树的整体增长。

Binary trees don't have this luxury. If you insert a key into a binary tree, it will increase the height of some branch in that tree by 1 in all cases because that key needs to go into its own node. Rotations combat the overall growth of the tree by ensuring that if certain branches grow too much, that height is shuffled into the rest of the tree.

最平衡的BSTS有某种再平衡战略,涉及旋转,但不是所有的事情。不直接涉及轮换策略的一个显着的例子是替罪羊树,该重新平衡由撕裂的巨大子树出了主树,最佳重建它们,然后再刷胶子树回主树。这种方法不会的技术上的涉及任何轮换,是pretty的实施平衡树清洁的方式。

Most balanced BSTs have some sort of rebalancing strategy that involves rotations, but not all do. One notable example of a strategy that doesn't directly involve rotations is the scapegoat tree, which rebalances by tearing huge subtrees out of the master tree, optimally rebuilding them, then gluing the subtree back into the main tree. This approach doesn't technically involve any rotations and is a pretty clean way to implement a balanced tree.

这是说 - 的替罪羊树是最节省空间的实现确实使用旋转转换不平衡树成一个完美的平衡的。你不的有无的使用旋转来做到这一点,但如果间隔较短也可能是这样做的最好方法。

That said - the most space-efficient implementations of scapegoat trees do indeed use rotations to convert an imbalanced tree into a perfectly balanced one. You don't have to use rotations to do this, though if space is short it's probably the best way to do so.

希望这有助于!