Definition of a Balanced Tree

后端 未结 6 893
暖寄归人
暖寄归人 2020-12-04 05:38

I am just wondering if someone might be able to clarify the definition of a balanced tree for me. I have that \"a tree is balanced if each sub-tree is balanced and the heigh

6条回答
  •  萌比男神i
    2020-12-04 06:17

    Balanced tree is a tree whose height is of order of log(number of elements in the tree).

    height = O(log(n))
    O, as in asymptotic notation i.e. height should have same or lower asymptotic
    growth rate than log(n)
    n: number of elements in the tree
    

    The definition given "a tree is balanced of each sub-tree is balanced and the height of the two sub-trees differ by at most one" is followed by AVL trees.

    Since, AVL trees are balanced but not all balanced trees are AVL trees, balanced trees don't hold this definition and internal nodes can be unbalanced in them. However, AVL trees require all internal nodes to be balanced.

提交回复
热议问题