[Tree structure] a calculation formula for a tree with a practical purpose

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.