8.5 binary sorting tree
An ordered linear table is convenient to search for. However, insertion and deletion operations consume a lot of time, because after insertion and deletion, a large amount of data is moved to maintain a linear order. The binary sorting tree can be used to solve this problem.
Binary sorting tree, also known as binary search tree. It is either an empty tree or a binary tree of the following nature:
1) if its left subtree exists, the value of all nodes on the left subtree is smaller than its root node value;
2) if its right subtree exists, the value of all nodes on the right subtree is greater than the value of its root node;
3) its left and right subtree are also Binary Decision Trees.
The purpose of constructing a binary sorting tree is not to sort, but to speed up searching, inserting, or deleting keywords.
The binary sorting tree is stored as a link, which keeps the link storage structure from moving elements when performing the insert or delete operation. After finding the proper insert and delete locations, you only need to modify the link pointer.
8.6 balanced binary tree
When constructing a binary tree, it is constructed in sequence by elements in the array to satisfy the nature of the binary tree. When constructing a binary tree for an array in a forward order, it will become a right-oblique binary tree without a left subtree, which will affect the search efficiency. Therefore, a balanced binary tree is constructed.
Balanced Binary Tree: a binary sorting tree. The difference between the left and right decision trees of each node is at most 1.
Construction principle: When a node is inserted, first check whether the balance of the tree is damaged because of the insertion. If yes, find the minimum imbalance tree, adjust the links between nodes in the sub-tree with the minimum imbalance and rotate them accordingly to form a new balance tree.
This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1282363