About red-black tree

1 understand left and right hand

 For triangular rotation is selected with respect to two nodes and sibling nodes constituted, the left side of the rotation is the rotation of the two nodes constituting another left to one side, and the right rotation is enough both nodes rotate the right side to the edge of another one. After the success of the rotation, when the father of a son extra edge gave the original father. 

Rotating steps:

The first step, the two nodes selected to be rotated, the father and son.

The second step, father, son and the father of another son (not just a fiction), three people form a triangle;

The third step is to rotate the left side of the father and son formed to rotate to the left edge of another one, right rotation is the father and son side structure of the rotary right to the edge of another one.

 

5 wherein the red-black tree 2

Color restrictions: only two colors, red and black.

Root and leaf node limitations: black.

All restrictions on the red node: the sub-node red node are black nodes.

All restrictions on the black nodes: nodes on the number of black leaf node to any node in the path is the same.

 

3 is inserted into the red-black tree balance

The newly inserted node to red. Because the original tree is a red-black tree satisfying the condition, i.e., number of black node to any node on the path to the leaf node is the same. If you insert a black, then a violation of this nature. Then insert the red, although it may violate child nodes red node are black nodes, but can be adjusted by exchange of color parent-child node.

 

 

 

4 balanced red-black tree delete

 

Guess you like

Origin www.cnblogs.com/hustdc/p/10937869.html