[Data structure] The nature of the binary tree

The nature of the binary tree

  1. If the level of the root node is specified as 1, then there are at most 2^(i-1) nodes on the i-th level of a non-empty binary tree.
  2. If the number of root nodes is specified to be 1, the maximum number of nodes in a binary tree with depth h is 2^h-1.
  3. For any binary tree, if degree is 0, the number of leaf nodes is n0, and the number of branch nodes with degree 2 is n2, then n0=n2+1
  4. If the level of root node is 1 and the depth of a full binary tree with n nodes, h=Log2(n+1). (ps: Log2(n+1) is log base 2, n+1 is logarithm)
  5. For a complete binary tree with n nodes, if all nodes are numbered starting from 0 in the array order from top to bottom and left to right, then for the node with sequence number i:
    if i>0, the value of the node at i Parent sequence number: (i-1)/2; i=0, i is the root node number, no parent node
    If 2i+1<n, the left child sequence number: 2i+1, 2i+1>=n otherwise there is no left child
    if 2i+2<n, the serial number of the right child: 2i+2, 2i+2>=n otherwise there is no right child
  6. For a complete binary tree with n nodes, the degree of the tree is (log2 n)+1 (log base 2 is the logarithm of n+1)

Guess you like

Origin blog.csdn.net/weixin_43962381/article/details/114397482