The number of tree nodes where each node has two child nodes

I have a tree that looks like this:

enter image description here

In the first pictures, the height of the tree is 1 and there are 3 common nodes. 2 for 7 on the next and 3 for 15 for the last. How to determine how many nodes a tree of this type lheight will have ? Besides, what is this tree (what is called in particular?)?

+4
source share
5 answers

This is the perfect binary tree.

You can get the node number given this recursive match:

n(0) = 1
n(l+1) = n(l) + 2^l

So

n(l) = 2^(l+1) - 1
+4
source

A full binary tree at a depth of 'd is strictly a binary tree, where all leaves are at level d.

  • for fig1, d = 1
  • for fig2, d = 2
  • fig3, d = 3

, T d.

2(d+1)-1

n T.
  • fig1, d = 1; 2(1+1)-1= 2(2)-1= 4-1= 3
  • fig2, d = 2; 2(2+1)-1= 2(3)-1= 8-1= 7
  • fig3 d = 3; 2(3+1)-1= 2(4)-1= 16-1= 15

(h) (d) ( node) .

, , .

+2

...

n = 2 ^ (h + 1) - 1.

+1

, , " ". " - , node " http://en.wikipedia.org/wiki/Binary_tree - " ". http://xlinux.nist.gov/dads//HTML/perfectBinaryTree.html

= 2 ^ ( + 1) -1

= (LOG ( + 1,2) -1,1)

, , Wikipedia, .

+1

.

In the case of an ideal binary tree, the total number of leaf nodes is 2 ^ H (H = tree height)

and the total number of internal nodes 2 ^ H - 1

Consequently, the total number of nodes will be 2 ^ H + 2 ^ H - 1 , which is 2 ^ (H + 1) - 1 , as mentioned by others.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1584815/


All Articles