Advanced programmers lessons - Architect of the road (7) - Concept Tree

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/m0_37609579/article/details/99685995

Next we will introduce another data structure - tree. This tree is a binary tree data structure, we will introduce later red-black trees, 2-3-4 trees data structure. So why use the tree? Its virtues?

Data structure array in front of us, we know that for an ordered array, locate quickly and introduced by dichotomy can look, but you want to insert a data item in an ordered array, you must first locate the insert data items, then all position data items into the back of a moving backwards all, to make room for new data, on average, to move N / 2 times, which is very time-consuming. Similarly, the data is deleted.

Then we introduce another data structure - linked list insertions and deletions quickly, we just need to change some reference value on the line, but to find the data very slow, because no matter what we look for data, you need from the list the first item beginning, traverse to find the items until the required data, this find is the need to compare the average N / 2 times.

Then we want a data structure that can also have an array of advantages to find fast and quick insertion and deletion list the advantages, so the tree was born.

First, the definition of the tree

[Baidu Encyclopedia] FIG tree is a data structure which is n (n> = 1) consisting of a finite nodes in a hierarchy of collections . We call it the "tree" because it looks like an upside down tree, which means that it is the root upward, downward and leaves. It has the following features:

Each node has zero or more child nodes; no parent node is called the root node; each non-root node has only one parent node; root addition, each child node It can be divided into a plurality of disjoint sub-trees. This is a tree -------------------- "" "" "" "" "
Here Insert Picture Description

Second, the basic concepts and characteristics of the tree

The basic concept of the tree

Tree (Tree) comprising n (n> = 0) is a finite set of nodes, wherein:

Each element is called node (Node);
have a particular node is called the root node or the root (the root);
the remaining data elements other than the root node is divided into m (m≥0) a mutual disjoint sets T1, T2, ...... Tm-1 , wherein each set Ti (1 <= i <= m) is itself a tree, the tree is referred to the original subtree (subtree).

Tree features:

Each node ① zero or more child nodes;
② no parent node is called a root node;
③ each non-root node has only one parent node;
④ except the root, each node can be divided into a plurality of sub- disjoint sub-trees;

Third, the commonly used terms tree

Path : the nodes along the edges come from one node to another, the order of the nodes through which the arrangement is called "path."
roots : the top of the tree is called the root node. Only a root of a tree, if we want a set of nodes and edges is called a tree, then from the root to any other node must have one and only one
parent node : If a node contains child nodes, the nodes called child of its parent node; B is the parent node D.
child nodes : the root node of a subtree containing the called child nodes of the node; D is a child node of B.
sibling nodes : nodes having the same parent node is called mutual sibling nodes; such as the D and E on FIG mutual called siblings.
leaf node : node has no children is called a leaf node, also known as leaf nodes, such as the figure of H, E, F, G are leaf nodes.
subtree : Each node can be used as the root of the subtree, it and all its child nodes, child nodes are all child nodes contained in subtrees.
level nodes : definition of start from the root, the root of the first layer, the second child of the root level, and so on.
Depth : For any node n, n from the root to a depth of only path length n, the depth of root is 0;
height : for any node n, n is the height of the longest path from a leaf to the n length, the height of all leaves is 0;

Fourth, the classification tree

In terms of the type

  1. Unordered tree: No sequence relationship between the child node of any node in the tree, the tree is called unordered tree, also known as free tree;
  2. Ordered tree : sequential relationship between the child node of any node in the tree, the tree is called ordered tree;
  3. Binary tree: each node containing up to two trees called subtrees of the binary tree;
  4. Full Nimata 树
  5. Full Binary Tree
  6. Huffman tree: binary weighted shortest path or optimal binary Huffman tree referred to;

Algorithmically speaking

Binary search tree (binary sort tree), balanced binary tree (AVL trees), red-black tree, B- tree, B + tree, trie (Trie tree), suffix tree, generalized suffix tree.

Fifth, the operation of the tree

  1. Create a tree
  2. Destruction of trees
  3. Empty tree
  4. Insertion junction
  5. Delete Node
  6. Gets node
  7. Gets the root
  8. Get the number of nodes of the tree
  9. Gets the height of the tree
  10. Get the tree of
    my micro-channel public number: architecture Scriptures (id: gentoo666), shared Java dry, high concurrency programming, popular technical tutorials, and distributed micro-services technology, architecture, design, block chain technology, artificial intelligence, big data, Java interview questions, and leading edge of the top news and so on. Updated daily Oh!
    Here Insert Picture Description

VI. References

https://www.cnblogs.com/ysocean/p/8032642.html
https://www.cnblogs.com/shixiangwan/p/7530015.html
https://blog.csdn.net/wannuoge4766/article/details/83998377

 

Guess you like

Origin www.cnblogs.com/anymk/p/11470503.html