+1 vote
39 views
Why is $n \leq 2^{h+1} - 1$ equivalent to $h \geq \log_2{\frac{n+1}{2}}$ ? This is applicable to Binary Trees

+1 vote

This is a basic concept for calculating minimum height for Binary Trees.

Hope you know A Complete Binary tree corresponds to maximum possible number of nodes in any tree.

When Nodes are maximum (Fully dense tree) then this also corresponds to minimum hight of the tree.

Now lets derive the formula

At level 0 Number of nodes possible --------->>>>> 1 (Root)     // 20

At level 1 Number of nodes possible--------->>>>>2                 //  21

At level 2 Number of nodes possible--------->>>>>4                //  22

At level 3 Number of nodes possible--------->>>>>8               //  23

At level 4 Number of nodes possible--------->>>>>16             //  24

so Ultimately we can generalize it like at Level H (height) Number of nodes possible--------->>>>> 2H

So to know total possible number of nodes add the maximum possible nodes at each individual level

Total number of possible nodes in level 'H' binary tree ---->>> 20+21+22+23+24.....+2H

So maximum nodes possible would be 2h+1-1

so n<= 2h+1-1 Now the log work you can do..

selected by
How do u get the log?

Basic log calculation

n<= 2h+1-1

so n+1 <=2h+1

take log both side

log (n+1) <=h+1

so h>=log2(n+1)-1  ; // log22=1  ; log a/b= log a - log b

so h>= log2 ( (n+1)/2 )