Chapter IV Introduction of tree data structure

First, the basic concept of the tree

  Tree structure is an important nonlinear structure. It is a tree structure with branches between nodes, and has a hierarchical relationship structure, which is very similar in nature tree. Tree structure in the objective world abound, such as genealogy, administrative organizations are available to represent image building; trees in the computer field also has a wide range of applications, such as compilers, use the tree to represent the grammatical structure of the source ; database system, the tree can be used to organize information; in the analysis of the behavior of the algorithm, the tree can be used to describe its execution and so on.

Recursion is an inherent characteristic of the tree;

Tree: is n (n> = 0) nodes of the finite set T, is satisfied:

  • (1) When n = 0, called the empty tree;
  • (2) when n> 0, and only a specific node called the root; the rest of the nodes can be divided into m (m> = 0) disjoint subsets T1, T2, T3 ... tm, wherein each subset Ti is a tree and call it sub-tree.

● node by: a plurality of data elements and a branch point to other nodes composed.
● degree: degree node: number owned subtree; of trees: tree maximum degree all nodes
● leaf (terminal node): a degree of node 0
● non-terminal node: of the node is not zero.
● children (child node): root of the subtree node is called a child of the node.
● parent (parent node): a parent node is called the root node of all sub
● ancestor node: refers to all ancestor nodes on the path to this root node.
● descendants as: all nodes on branches from the node to a leaf node is called the node's descendants.
● sibling: call each other brothers among children of the same parents. (Parent node of the same node)
● level nodes: counted from the root, root level is 1, the remaining level of the node 1 is added to its parent level.
● cousins: its parent node in the same layer.
● depth (height) of the tree: maximum number of all the nodes in a tree hierarchy.
● ordered tree: the sub-tree if the tree each node is left to right order, not interchangeable, called ordered tree.
● unordered tree: each node if the subtree of the tree is no order, can be interchanged, the tree becomes disordered.
Forest ●: the tree is a set of m (≥0).

The basic operation of the tree

  • ➢ Root Root (T): find the root of the tree T;
  • ➢ seeking parent Parent (T, X): X parents find the node in the tree T; if X is the root of the tree T or X is not T, then the result is a special mark;
  • ➢ seeking child Child (T, X, i): i-th node X on the child node tree T seek; T if X or X does not on the i-th child, the result is a special mark;
  • ➢ achievements Create (X, T1, ..., Tk), k> 1: an X-established as the root, T1, ..., Tk for the first 1, ..., k subtrees of the tree;
  • ➢ pruning Delete (T, X, i): i-th node of the subtree X Delete Tree T; T if no i-th subtree, null operation;
  • ➢ traverse TraverseTree (T): traverse the tree, i.e. each access node in the tree, and each node is visited only once.

 Second, the binary tree

Application Binary Tree plays in a tree structure in a very important role, because binary tree has many good properties and a simple physical representation, and any tree can be converted to a binary tree with each other, so that solves the problems of storage and computation in tree complexity

Binary tree is n (n> = 0) of a finite set of nodes, or it is empty (n = 0), or consists of a root and two disjoint left subtree and right subtree composition, and left subtree and right subtrees are also binary tree. Binary tree may be empty set, the left sub-tree may be empty right subtree can also be empty.

Binary tree features:

  • ① binary tree may be empty, called an empty binary tree;
  • ② Each node can have up to two children;
  • ③ subtree the left and right of the points and the order can not be reversed.

 

 Binary tree node subtree subtree to distinguish between left and right sub-tree, even if only a sub-tree should be distinguished, indicating that it is the left sub-tree, or right subtree. This is the main difference with the binary tree, binary tree there are five basic forms

 

Binary tree has the following important properties:

1, Properties 1: In the first i (i> = 1) binary tree has at most 2 ^ (i-1) th layer nodes. 

2, 2 Properties: depth of k (k> = 1) of the binary tree has at most (2 ^ k) -1 nodes.

3, 3 nature: for any binary tree, if it is the terminal number of nodes n0 (n0 a leaf node), the number of nodes of degree 2 is n2, then n0 = n2 + 1. Namely: Leaves of nodes n0 = number of nodes of degree 2 n2 + 1

A full binary tree: Depth of k (k> = 1) and has a binary tree (2 ^ k) -1-node; full binary tree nodes in sequence number: a top-down starts from the first node layer, left the right to be numbered consecutively.

 

 Complete binary tree: depth in the binary tree of K, K-1 is a full layer nodes 2 ^ (k-2), K is a left node continuous layer (i.e., node numbers are continuous)

 

 

 

Guess you like

Origin www.cnblogs.com/jalja365/p/12601593.html