Quantcast
Channel: What is the average height of a binary tree? - Computer Science Stack Exchange
Viewing all articles
Browse latest Browse all 3

What is the average height of a binary tree?

$
0
0

Is there any formal definition about the average height of a binary tree?

I have a tutorial question about finding the average height of a binary tree using the following two methods:

  1. The natural solution might be to take the average length of all possiblepaths from the root to a leaf, that is

    $\qquad \displaystyle \operatorname{avh}_1(T) = \frac{1}{\text{# leaves in } T} \cdot \sum_{v \text{ leaf of } T} \operatorname{depth}(v)$.

  2. Another option is to define it recursively, that is the average height for a node is the average over the average heights of the subtrees plusone, that is

    $\qquad \displaystyle \operatorname{avh}_2(N(l,r)) = \frac{\operatorname{avh}_2(l) + \operatorname{avh}_2(r)}{2} + 1$

    with $\operatorname{avh}_2(l) = 1$ for leafs $l$ and $\operatorname{avh}_2(\_) = 0$ for empty slots.

Based on my current understanding, for example the average height of the tree $T$

    1       / \  2   3 /4

is $\operatorname{avh}_2(T) = 1.25$ by the second method, that is using recursion.

However, I still don't quite understand how to do the first one. $\operatorname{avh}_1(T) = (1+2)/2=1.5$ is not correct.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images