What is a binary tree?
In computer science, a binary tree is a tree structure with a maximum of two Subtrees on each node. Generally, Subtrees are called "Left subtree" and "right subtree". The left and right subtree are also Binary Trees. The subtree of a binary tree can be left or right, and the order cannot be reversed. Binary Trees are defined recursively. Therefore, common Binary Tree-related questions can also be solved using recursive ideas. Of course, some ideas can also be solved using non-recursive ideas, some of the algorithms listed below use recursion, and some are non-recursive algorithms.
What is a binary sorting tree?
The binary sorting tree is also called the binary search tree or the binary search tree. It is a binary tree first and must meet the following conditions:
1) if the left subtree is not empty, the value of all nodes on the left subtree is smaller than the value of its root node;
2) If the right subtree is not empty, the value of all nodes on the right subtree is greater than the value of its root node.
3) The left and right subtree are also Binary Decision Trees.
4) No node with the same key value (? It may be because it is difficult to handle whether the node with the same key value is a left node or a right node)
First-order traversal (left-right root)
Access the root, traverse the left subtree, and then traverse the right subtree. Typical recursive thinking.
Middle-order traversal (left root and right)
Traverse the left subtree first, then access the root, and then traverse the right subtree.
For the binary sorting tree, the sequence obtained by the middle-order traversal is a sequence sorted from small to large.
Post-order traversal (left and right)
Traverse the left subtree first, then the right subtree, and then access the root
B and B +
Reference: https://www.cnblogs.com/vincently/p/4526560.html
Summary:
Because the data of the B + tree is stored in the leaf node, and the branch nodes are indexes, you only need to scan the leaf node once to scan the database easily,
But because B's branch nodes also store data, we need to perform a middle-order traversal and scan in order to find specific data,
Therefore, the B + tree is more suitable for Interval queries. Therefore, the B + tree is usually used for database indexing, while the B tree is often used for file indexing.
Red/black tree:
Reference: https://www.cnblogs.com/CarpenterLee/p/5503882.html
Summary:
The red/black tree is an almost balanced binary search tree. It ensures that the height difference between the left and right subtree of any node does not exceed the height difference between the two.. Specifically, the red/black tree is a binary search tree that meets the following conditions ):
- Each node is either red or black.
- The root node must be black.
- The red node cannot be consecutive (that is, neither the child nor the father of the red node can be red ).
- For each node
null
Any path of the (tree tail end) contains the same number of black nodes.
Introduction to binary tree, B tree, B + tree, and red/black tree