For a two-fork tree , as shown:
We can have the following hypothesis, set the number of leaf nodes is n0, the degree of 1 of the number of nodes is N1, the degree of 2 of the number of nodes is N2.
Then there is:n0+n1+n2=n
And because in addition to the root node, each node occupies one side,
Then there is:n-1=2n2+n1
Combine the above two formulas to get:
Leaf node and two-degree node number relationship:n0=n2+1
If this is a completely binary tree , then the number of nodes at one point is limited, either 0 or 1. So we can finally get the relationship between the total number of nodes and the leaf node:
(1) When n1=0, n=2n0-1 so n0= (n+1)/2. The n here is an odd number.
(2) When n1=1, N=2n0 so N0=N/2. n is an even number here.
Sum up:
For a complete binary tree, the relationship between the leaf node and the total number of nodes is:
A complete binary tree with n nodes whose number of leaf nodes is N0: (n+1)/2 is rounded down.
[Tree structure] a calculation formula for a tree with a practical purpose