Red/Black: The red/black tree is a binary search tree. The color of each node in the tree is either black or red. You can regard the red and black trees as an Extended Binary Tree and use external nodes to represent null pointers.
Feature 1: The color of the root node and all external nodes is black.
Feature 2: The color of two consecutive nodes from the root node to the external node is red.
Feature 3: All paths from the root node to the external node have the same number of black nodes.
Starting from any node X in the red/black tree (excluding node X), the number of black nodes that reach any path of an external node is called the Black height of X, it is also called the node level. The black height of the red/black tree is defined as the black height of the root node.
Nodes in the red and black trees: Red nodes, black nodes, and external nodes (leaf nodes ).
Conclusion 1: the path length (path length, PL) from the root node to the external node is the number of pointers on the path, if p and q are the two paths from the root node to the external node in the red/black tree, there are: PL (p) <= 2Pl (q ).
Conclusion 2: Set H to the height of a red-black tree (excluding external nodes), N to the number of internal nodes in the tree, and r to the Black height of the root node, so there are a, H <= 2R, B, n> = 2r-1, 3, H <= log2 (n + 1)
Red/black tree