I. Red/black tree (Red-Black TreeIs a binary search tree (Binary Search Tree. In the worst case, the binary search tree may become a linked list (after all nodes are inserted in ascending order ). The cause of this inefficiency is that the tree does not maintain a certain balance. To improve the search efficiency, we need to find a way to maintain the balance on the left of the tree, that is, to minimize the height of the tree, A feasible approach is to use some strategies to adjust the structure of the tree after each modification of the tree content, so as to meet certain balance conditions. One of them meets certain balancing conditions and is currently widely used in the red and black trees. It can be spent every time a node is inserted or deleted.O(Log N) To modify the tree structure to maintain the tree balance. The method of searching the red and black trees is the same as that of the binary tree.O (log N)Time. The method for inserting and deleting nodes in the red-black tree is to maintain the properties of the tree after the original binary tree search and deletion algorithm.
Each node of the red/black tree has one attribute.Key,3Pointers:Parent,Left,RightIn addition, there is an additional attribute:Color. It can only be in two colors: red or black,Of course, you can also add someKeyTo index the data. In addition to all the properties of the Binary Search Tree, the red/black tree also has the following5Point nature:
1.Each node is black or red.
2.The root node is black.
3.The empty node is black (the root node in the red/black treeParentAnd all leaf nodesLeft,RightDo not pointNULL, But points to a defined null