The difference in height between the leaves in the AVL tree

What is the maximum difference between any two leaves in an AVL tree? If I take an example, my tree will become unbalanced if the height difference is greater than 2 (for any two sheets), but the answer is the difference can be any value. I really don't understand how this is possible. Can anyone explain with examples?

+4
source share
2 answers

The difference in levels of any two leaves can be any size! The AVL definition describes the height difference on only two subtrees from one node. So you need to fill the subtrees with equal height, and then add new nodes to create this single node difference. But no one said that this subtree does not contain some subtrees with the same definition. Of course, the tree is self-balancing, but if we are so accurate as not to touch its balance, we can create any height difference between some leaves.

Example with sheet 24 at level 3 and sheet 10 at level 6: Avl tree

+4
source

, AVL , . , ( , ).

0

All Articles