Binary search tree, balanced binary tree and black tree

First talk about the tree called a binary tree all only a maximum of two child nodes of each node.

Binary search tree

Binary search tree, also known as binary search trees, or binary sort tree. Its definition is relatively simple, either an empty tree, or is a binary tree with the following properties:

(1) If the left subtree of any node is not empty, then the value of the left sub-tree, all the nodes are less than the value of the root;

(2) If the right subtree of any node is not empty, then the value of the right subtree of all nodes are greater than the value of the root;

Left (3) any node, respectively the right subtree of a binary search tree;

(4) does not equal the node key.

Balanced binary tree (AVL binary tree)

Balanced binary search tree, also known as AVL trees, and having the following properties: it is the absolute value of the difference between the height of the empty tree or a left and right subtrees no more than 1, and a left and right subtrees are balanced binary trees.

Red-black tree

A two binary search tree, but the increase in color indicates a storage node in each node, can be black or red (i.e., non-red black). Each node by way of limitation on the colored any one path from the root to a leaf, a red-black tree to ensure that no other path is deeper than twice the path, thus, a weak red-black tree is a balanced binary tree (due to weak balance, can be seen in the same node, the AVL tree height is lower than the red-black tree), with respect to the demanding AVL tree, the small number of its rotation, so the search, insert, delete operations more under the circumstances, we will use red-black tree.

Attention:

  • Balanced trees (AVL) to solve the case of a binary search tree (BST) degenerate to the list.
  • Red-black tree (RBT) to solve the case of a balanced tree requires frequent adjustments in the delete operation

Reference: https://www.liangzl.com/get-article-detail-136354.html , https://blog.csdn.net/qq_25940921/article/details/82183093 , https://www.jianshu.com/ p / d25e490e2441

Guess you like

Origin www.cnblogs.com/fxtx/p/11594255.html