Quantcast
Channel: What to infer about maximum height of AVL tree from these three different formulae - Computer Science Stack Exchange
Viewing all articles
Browse latest Browse all 2

What to infer about maximum height of AVL tree from these three different formulae

$
0
0

I have came across following problem:

What is the maximum height of any AVL-tree with 7 nodes?

The recurrence giving number of nodes $n$ in the AVL tree for given height $h$ is as follows:

$n(h)=n(h-1)+n(h-2)+1$

$n(0)=1$

$n(1)=2$

So if we follow this recurrence, we get the height of the AVL tree with 7 nodes = 3 as follows

$n(2)=n(1)+n(0)+1=2+1+1=4$

$n(\color{red}{3})=n(2)+n(1)+1=4+2+1=7$

However I find two formulae, both listed on this page:

  1. The first one is stricter one:

    $h < 1.475 \times log_2(n(h)) - 1.475$

    According to this formula, I get

    $h < 1.475 \times log_2(7)-1.475$

    $h<\color{red}{2.665}$

  2. The second one is rough estimate and it is taken from Goodrich's book:

    $h < 2 \times log_2(n(h)) + 2$

    According to this formula, I get

    $h < 2 \times log_2(7) + 2$

    $h<\color{red}{7.61}$

So with these different answers, I don't get what should I infer. Am I doing any miscalculations? Or should I just stick to what is yielded by recurrence and ignore formulae as they are mere estimates? Or should the first formula have ceil function to give perfect answer rather than the estimates as follows?

$h \color{red}{=} \color{red}{\lceil} 1.475 \times log_2(n(h)) - 1.475 \color{red}{\rceil}$


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images