Data structures: binary tree and

First, the definition of the tree and basic terminology

  • Data elements called node
  • Tree is n (n> = 0) of a limited set of nodes. n = 0, called null tree.
  • And only one root node. n> 1, except that the remaining nodes other than the root node tree is divided into m disjoint subtrees.
  • Of the node: a node has a number of sub-tree.
  • The maximum value of each node: of Trees

The logical binary tree structure

1. Definitions

  • Each node of the binary tree has at most two subtrees
  • Binary tree is ordered
  • Full binary tree: the leaves (0 degrees) can only appear at the next level, only degrees and 0 degrees for the node 2
  • Complete binary tree: the leaf nodes only appear at the lower layers, the lowest level of the leaf nodes are concentrated in the left side of the binary tree; if there is a degree of nodes 1, only one, and that only the left child node . (Look for a map view)

2. The basic properties of binary tree

Up to 2 ^ i-1 i-nodes on layer 1. Binary Tree (1,2,4,8 ...)
2. In a binary tree of depth k, a maximum of 2 ^ k -1 th nodes least k nodes. (1 + 2 + 4 + 8 ...)
3. In a binary tree, the leaf node if the number is n0, is the number of nodes 2 is n2, then: N2 = N0 1 +
4. complete binary tree with n junction depth of n Iog2 (rounded down) + 1
nodes having a complete binary tree of n nodes in 5., starting with 1 sequence number, then for any number (1 <= i <= n ) i nodes, are:
if the node i has a left child, left child is 2i; if node i have the right child, right child is 2i + 1; if the node i has parents, then the parents number i / 2 (rounded down).

Guess you like

Origin www.cnblogs.com/juzijuziju/p/11880305.html