1. Red Black Tree Properties: The path of the root to the leaf, the longest path is not greater than the shortest path of twice times.
2. The red-black tree is a binary search tree and has
A. Each node has a color attribute, red or black, in addition to the properties of the left, right, and parent nodes.
B. ( root attribute ) The root of the red and black tree can only be black.
C. ( red attribute ) The child nodes of the red node can only be black
D. ( black attribute ) The number of black nodes that appear on each path from a given node to its descendant leaf nodes. The number of black nodes that appear on the path from a node to the leaf node of its descendants is called the black height of the node (black-height).
3. The search and output operations on the red and black trees are the same on the binary tree. The insertion and deletion of binary search may break the red and black tree features mentioned above when applied to the red-black tree. If broken, the structure needs to be adjusted to restore the properties of the red-black tree.
4. Insert operation, each inserted node is marked in red, there may be two consecutive red nodes, so that the red property is broken. If broken, depending on the color of the tertiary node (the sibling node of the parent node), different adjustment methods are used.
Delete operation, delete the node if it is red, will not break the characteristics, if it is black, may change the black height of the other nodes, breaking black properties. If broken, also need to divide the situation, the use of different adjustment methods.
Insert operation, delete operation of the specific implementation, has not been read through, there is a need for further understanding.
Scenario: Java HashMap uses a red-black tree structure to store conflicting elements when dealing with a large number of hash value collisions, improving performance.
Resources
Red-black Trees, cs.wisc.edu
Red–black Tree, Wikipedia
Red-black Tree | Set 3 (Delete), geeksforgeeks.org
13th chapter red and Black Tree "introduction to Algorithms"
[Data Structure] red and Black (red-black tree)-Notes