Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Height difference between leaves in an AVL tree

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

like image 304
Prasita Mukherjee Avatar asked Mar 10 '15 13:03

Prasita Mukherjee


1 Answers

The difference in levels of any two leaves can be any value! Definition of AVL describes height difference only on two sub-trees from one node. So you need to fill subtrees with equal height then add new nodes just to create that single node difference. But nobody said that that subtree doesn't contain some subtrees with the exact same definition. Of course tree is selfbalanced but if we'll be that accurate to not touch it's balance then we can create any height difference between some leaves.

Example with leaf 24 on level 3 and leaf 10 on level 6: AVL-tree

like image 123
Vladimir Mezentsev Avatar answered Oct 21 '22 04:10

Vladimir Mezentsev