Number of Binary Tree nodes [N0, N1, N2]

Source: Internet
Author: User

If the number of nodes in the Complete Binary Tree is 2n-1, the number of leaf nodes is ()
A) N-1 B) 2 x n C) 2n-1 d) 2N
Resolution:
Number of Subtrees owned by a node
Proof: because the degree of all nodes in a binary tree is not greater than 2, the total number of nodes (recorded as N) should be equal to zero-degree knots and 1-degree knots (recorded as N1) and the sum of 2-degree Knots:
N = no + N1 + N2 (Formula 1)
On the other hand, the level 1 node has a child, and the Level 2 node has two children, so the total number of child nodes in the binary tree is:
NL + 2n2
Only the root node in the tree is not the child of any node, so the total number of nodes in the binary tree can be expressed:
N = N1 + 2n2 + 1 (formula 2)
Obtained from Formula 1 and formula 2:
No = n2 + 1

Completely Binary Tree n1 = 0
Therefore, n = N0 + N0-1 + 1 = 2n0

 

Binary Tree: number of nodes = number of sides + 1

That is, N0 + N1 + n2 = N1 + 2 * N2 + 1 ==> N0 = n2 + 1

Number of Binary Tree nodes [N0, N1, N2]

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.