Red black tree is a self-balancing two-fork search tree, because of the existence of red and black rules, so effectively prevent the two fork tree degenerate into a linked list, and find and delete fast, time complexity is log (n).
What is the red and black rule?
1. The root node must be black.
2. The node color is either red or black.
3. Each fork in the tree has the same black node.
4. There are two contiguous red nodes that are not allowed.
How to adapt to the red and black rules in the writing program?
1. Rotate
---single rotation
Lateral node single rotation. The lateral node refers to the left child node of Zuozi and right child node of right child tree.
---double rotation
The inner node is double-rotated. The medial node refers to the right child node of the Zuozi, the left child node of the right child tree.
2. Discoloration
---the node color to make changes.
---Forces the color of the root node to become black.
Post reference link: http://www.cnblogs.com/skywang12345/p/3245399.html (red + black node refers to the parent node is red, the current node is black.) Black + Black is the parent node black, the current node is black. The front color can be seen as inherited).
Data structure Java version of the Red-black tree (eight)