The red-black tree is a "balanced" lookup tree that can determine the dynamic set operation time O (LOGN)
13.1 Nature of red and black trees
Each node of the red and black tree has color, except key, value, p, left, right,
A value is considered an inner node, and if there is no son, the son is nil,
Red Black Nature:
1. Each node is either red or black
2. Root node Black
3, leaf node (NIL) Black
4, if the node is red, then the son is black
5, starting from any node, any one of the following path, the number of black nodes are the same.
Witty handling
The nil node points to the same location, whose value is Nil,p, left, and right's definition is not important.
The number of black nodes in any one path of the tree is called the black height.
Theorem: N nodes with a red-black tree height of up to 2log (n+1)
13.2 rotation
Inserting and removing elements that may cause red-black properties to change, in order to maintain the red-black nature, can be rotated.
L-and right-handed:
L: Left parent right child to right parent left dial hand:
Right: Right parent left dial hand to left parent right child:
13.3 inserting
13.4 Delete
"Introduction to Algorithms", 13th chapter, Red and black trees