The relationship between the degree of the tree and the node count

Source: Internet
Author: User

First, the concept

Unlike the "degrees" in graph theory, the degree of the tree is defined as: the number of children in the root tree T, node X is called the degree of X. That is: in the tree, the node has a few bifurcation, the degree is a few.

A useful little formula: node in the tree = Total Fork number +1. (The number of forks here is the sum of the degrees of all nodes).

Second, the degree of calculation

1. The degree of the tree T is 4, where the number of nodes with 1,2,3,4 is 4,2,1,1, then the number of leaves in T is?

Solution:

The number of leaves is 0, then the number of leaves is X, then the total score of the tree is 1*4+2*2+3*1+4*1=15; the number of nodes in this tree is 16 (a formula is involved here; the number of nodes = the number of forks is +1, which can be observed by the graph). And according to the topic can know the number of vertices can also list a formula: 4+2+1+1+x can get the equation: 4+2+1+1+x=16;x=8 is the number of leaves.

Because this is a problem in the data structure: In general, there is a direction to the tree, so the degree of the leaf node is 0, to distinguish it from the discrete mathematics of the non-tree leaf node degree of one. In the data structure commonly used in the formula is: Two tree: The number of nodes with degrees 0 = 2 nodes +1 (n0=n2+1) This formula can be deduced from the above calculation idea (generally in the binary tree there are more formulas, as long as you clearly define the tree, draw a diagram, you can find out the pattern according to the graph)

The relationship between the degree of the tree and the node count

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.