Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weight-unbalanced AVL tree

Tags:

avl-tree

Believing the wikipedia article: 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.

But, as an AVL tree is:

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

I don't see how an AVL could be weight-unbalanced since -if I understood the definition of an AVL tree well-, every sibling will have approximately the same number of child since they have the same height +/- 1.

So, could you give me an example of an AVL tree which is unbalanced ? I did not succeed to find one. Thus, or I misunderstood the definition of an AVL/unweighted tree, or the wikipedia article is false...

Thanks

like image 686
taktak004 Avatar asked Mar 21 '13 17:03

taktak004


People also ask

Is an AVL tree weight-balanced?

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.

Can an AVL tree be unbalanced?

AVL tree may become unbalanced, if a node is inserted in the left subtree of the left subtree. The tree then needs a right rotation. As depicted, the unbalanced node becomes the right child of its left child by performing a right rotation.

How do you find the unbalanced node in AVL tree?

Get the balance factor (left subtree height – right subtree height) of the current node. If the balance factor is greater than 1, then the current node is unbalanced and we are either in the Left Left case or left Right case.

What is the balance condition for AVL trees?

AVL balance condition: For every node in the tree, the absolute difference in the heights of its left and right subtrees is at most 1.


1 Answers

You are correct in your understanding that an AVL tree is defined by the nearly-uniform height of its edge nodes, but your confusion appears to be about the difference between node position and edge weight.

That is: In an AVL tree, the depth of the edge nodes will the same +/- (but not both!) one. This makes no claims as to the cost associated with an edge between the nodes. For an AVL tree with a root node and two children, the left path may be twice as expensive to traverse as the right path. This would make the tree weight-unbalanced, but still maintain the definition of an AVL tree.

This page has more information: Weight-balanced tree - wikipedia

From Wikipedia:

A Binary Tree is called μ-balanced, with equation, if for every node N, the inequality: mu-balance inequality

holds and μ is minimal with this property. |N| is the number of nodes under the tree with N as root (including the root) and Nl is the left sub-tree of N.

Essentially, this means that the children in an AVL tree are not necessarily evenly distributed across the lowest level of the tree. Taking N as indicating the root node of the tree, one could construct a valid AVL tree that has more children to the left of the root than to the right of it. With a very deep tree, there could be many nodes at this bottom level.

The definition of an AVL tree would require that they all be within one of the deepest point, but makes no guarantee as to what node they are a child of with respect to a node N.

like image 188
Fiarr Avatar answered Sep 29 '22 18:09

Fiarr