I have a tree that has the following form:
On the first pictures, the height of the tree is 1 and there are 3 total nodes. 2 for 7 on the next and 3 for 15 for the last one. How can I determine how many number of nodes a tree of this form of l
height will have? Also, what kind of tree is that (is it called something in particular?)?
That is a perfect binary tree
You can get the number of node considering this recursive approch:
n(0) = 1
n(l+1) = n(l) + 2^l
so
n(l) = 2^(l+1) - 1
A complete binary tree at depth ‘d’ is the strictly binary tree, where all the leaves are at level d.
So, Suppose a binary tree T of depth d
. Then at most
nodes 2(d+1)-1
n
can be there in T.
2(1+1)-1
=2(2)-1
=4-1
=32(2+1)-1
=2(3)-1
=8-1
=72(3+1)-1
=2(4)-1
=16-1
=15The height(h
) and depth(d
) of a tree (the length of the longest path from the root to leaf node) are numerically equal.
Here's an answer detailing how to compute depth and height.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With