Red-black tree principle analysis

Written in front of the words:
        authors from graduate has been involved in game development, with many games and practical case module code for all to study and exchange, hope the knowledge can bring some help, if you have any questions, please add group 641 792 143 exchanges and learning or No micro-channel public concern programmer dry area
       Road have been heard, industry specializing in surgery, I hope you have educated us

First, tell us about the red-black tree Some properties:
       Property 1: root is black
       nature 2: each leaf node is black (refers to the empty leaf node)
       Property 3: two children each red node must be black
( child nodes must be present or absent)
       nature 4: a path of any node to each leaf node contains the same number of black nodes (non-empty leaf node)
       nature 4.1: if a node exists black child nodes, then the node sure there are two child nodes (otherwise black imbalance)
       extended 5: can not have two red nodes connected to

Red-black tree is a binary search tree, but not perfectly balanced, just black perfect balance.

Red-black tree to achieve self-balancing in three ways: L, D, discoloration.

1. Find a red-black tree

Because the red-black tree is a binary search tree, which satisfies the binary search rule, should not know, refer to the principle blog AVL tree analysis.

2. The red-black tree insertion

Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

3. Delete the red-black tree node

Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionThese are the most important theoretical part of the red-black tree, if desired code, plus the beginning of the article group number

Published 43 original articles · won praise 1 · views 2309

Guess you like

Origin blog.csdn.net/lpl312905509/article/details/103707456