Defined
There are two definitions of trees:
1. is based on the definition of graph theory;
2. is based on the definition of recursion and node;
1. Based on the definition of graph theory:
If a non-simple graph g satisfies one of the following mutually equivalent conditions, then G is a tree :
- G is a connected graph with no loops.
- G does not have a loop, but adding any edge within G will form a loop.
- G is connected, but if you remove any of the edges, you are no longer connected.
- g is connected, and the full graph {\displaystyle k_{3}} of the 3 vertex is not a sub-graph of G .
- Any two vertices within G can be connected by a unique path.
If there is a finite number of vertices (set to n vertices) for the non-trivial graph g , then G is a tree and is equivalent to:
- g is connected, has n − 1 edges, and G does not have a simple loop.
If there is no simple loop in a non-simple graph g , then G is the forest .
2. Node-and recursive-based definitions:
A tree is a collection of n (n≥0) finite data elements. When n=0, the tree was called an empty tree. In a non-tree T:
(1) There is a special data element called the root node of the tree, and the root node has no precursor nodes.
(2) If n>1, the rest of the data elements outside the root node are divided into M (m>0) disjoint sets of T1,t2,...,tm, each of which is a set of Ti (1≤I≤M) itself is a tree. The tree T1,t2,...,tm is called the root node of the subtree.
As you can see, a recursive concept is used in the definition of a tree to define a tree using a tree. Therefore, the tree structure algorithm is similar to the binary tree structure algorithm, also may use the recursive method.
The definition of a tree can also be formally described as a two-tuple form:
T= (D,r)
where D is the set of nodes in the tree T, and R is the set of relationships between nodes in the tree.
When the tree is empty, d=φ; when the tree T is not empty tree:
D={root}∪df
Where root is the root node of the tree T, DF is the subtree collection of root root of the tree T. DF can be represented by the following formula:
Df=d1∪d2∪ ... ∪DM and Di∩dj=φ (i≠j,1≤i≤m,1≤j≤m)
When the number of nodes in the tree T is n≤1, r=φ; When the number of nodes in the tree T is n>1:
R={<ROOT,RI>,I=1,2,...,M}
Where root is the root node of the tree T, RI is the root node of the subtree Ti, the root node of the tree T.
The formalization of tree definition is mainly used for the theoretical description of trees. Figure 7.1 (a) is a tree with 9 nodes, that is, t={a,b,c,...,h,i}, Node A is the root node of the tree T, and the remaining nodes outside the root node A are divided into two disjoint sets: T1={b,d,e,f,h,i} and T2={c,g},t1 and T2 constitute the end point A. The two subtrees trees, T1 and T2 themselves, were also a tree. For example, the root node of subtree T1 is B, and the remaining nodes are divided into two disjoint collections: T11={d},t12={e,h,i} and T13={f}.
T11, T12, and T13 form the three subtrees tree of the root node B of the subtree T1. This continues to fall into smaller sub-trees until each subtrees tree has only one root node.
As can be seen from the tree definition and Figure 7.1 (a), the tree has the following two characteristics:
(1) There is no precursor node in the root node of the tree, and there is only one precursor node for all nodes outside the root node.
(2) All nodes in the tree can have 0 or more successive nodes.
The characteristic shows that the figure 7.1 (b), (c) and (d) are not tree structures.
Several important tree structures
The tree in computer science
| Two fork Tree |
| ? Two fork tree |
? Two forks find tree |
? Cartesian tree |
? top tree |
| ? t tree |
&NBSP; |
&NBSP; |
&NBSP; |
| &NBSP; |
|
|
| Self-balancing binary search tree |
| ? AA Tree |
? AVL Tree |
? red and black trees |
? Stretching tree |
| ? Tree Heap |
? node size balance tree |
|
|
|
|
|
| B-Tree |
| ? B-Tree |
? B + Tree |
? b* Tree |
? bx Tree |
| ? UB Tree |
? 2-3 Trees |
? 2-3-4 Tree |
? (A, b)-Tree |
| ? Dancing Tree |
? H-Tree |
|
|
|
|
|
| Trie |
| ? prefix tree |
? suffix Tree |
? Cardinality Tree |
|
|
|
|
| Spatial Partitioning Tree |
| ? Four fork Tree |
? Eight-fork Tree |
? k-d Tree |
? vp-Tree |
| ? R-Tree |
? r* Tree |
? r+ Tree |
? X-Tree |
| ? M-Tree |
? Segment Tree |
? Hilbert R-Tree |
? Priority R-Tree |
|
|
|
| non-binary tree |
| ? exponential tree |
? Fusion Tree |
? interval Tree |
? PQ Tree |
| ? Range Tree |
? SPQR Tree |
? Van emde Boas Tree |
|
|
|
|
| Other Types |
| ? Heap |
? Hash Tree |
? Finger Tree |
? Metric Tree |
| ? Cover Tree |
? Bk-tree |
? doubly-chained Tree |
? idistance |
| ? link-cut Tree |
? tree-like array |
|
|
|
Common operations for Trees
Application of the tree
The name of the tree |
Application Scenarios |
Trie Tree |
Features: Guaranteed dictionary order, storage dictionary space compression rate is high |
Prefix search |
Regular match |
Data compression |
Database Build Index |
|
C++ |
Four-fork tree, eight-fork Tree |
Robot field, detecting collisions |
|
directory structure of the file system |
|
Routing protocol |
Huffman Tree |
Encode, compress |
B-Tree, B + |
Distributed systems, MySQL |
BST two fork find tree |
Memory Lookup |
AVL Self-balancing binary tree |
Memory Lookup |
Reference Links:
Http://c.biancheng.net/cpp/html/985.html
Https://zh.wikipedia.org/wiki/%E6%A0%91_ (%E5%9B%BE%E8%AE%BA)
http://philoscience.iteye.com/blog/1112759
Data Structure-tree