First, the basic terminology
- The degree of the node and the degree of the tree: the number of subtrees of a node in the tree is called the degree of that node. The maximum value of the degrees of each node in the tree is called the degree of the tree, which is usually called the M-secondary tree.
- Branch nodes and leaf nodes: nodes that are not 0 degrees are called non-endpoints, also called branch nodes. Nodes with a degree of 0 are either end nodes or leaf nodes.
- Path and path length: The path length is equal to the number of nodes passed by the path minus 1. It is clear that there is a unique path from the root node of the tree to the rest of the tree.
- child node, parent node, sibling node, descendant node, ancestor node
- The hierarchy of nodes and the height of the tree: the root node is on the first layer, and so on. The maximum level of a node in a tree is called the height of the tree or the depth of the tree.
- Forest: A collection of n disjoint trees is called a forest. As long as the root node of the tree is removed to become a forest, conversely, as long as the n separate tree with a node, and the N tree as a subtree of the node, then the forest becomes a tree.
Second, the nature of the tree
1, the number of nodes in the tree equals the degree of all nodes plus 1.
Each node (outside the root node) corresponds to a branch one by one that points to it.
m^ (i-1) nodes (i>=1) on layer I of a tree of 2 degrees m
When the first layer of an M-tree has m^ (i-1) nodes, the layer is called full. If all leaf nodes of an M-tree are on the same layer, each layer except that layer is full, and the tree is called full M-tree. Obviously, the full M-tree is the tree with the highest total number of nodes in the M-Tree of all the same heights. That is, for n nodes, the constructed m-th tree is full M-tree, at which point the height of the tree is minimal.
3, the height of the M-time tree has a maximum (m^h-1)/(m-1) nodes.
4. The minimum height of the M-secondary tree with n nodes is LOGM (n (m-1) +1) rounding up. The maximum height is n-m+1.
5. The sum of the =n-1 of all nodes
The sum of the degrees of all nodes =n1+2n2+.....+knk
n = n0+n1+n2+n3+.....+nk
Three, the basic operation of the tree
1. Find a node that satisfies a particular relationship. such as the parent node of the current node, child nodes, leaf nodes, etc.
2. Inserting or deleting a node
3, Traversal: root traversal, post-root traversal and hierarchical traversal. (The first two are recursive algorithms, the last of which is implemented by queues)
Tree and two-fork tree