Huadian North Wind Blows
Key laboratory of cognitive computing and application, Tianjin University
Date: 2015/9/9
The red-black tree is a balanced extension of the two-fork tree. The red and black trees adopt an Open data expansion strategy, and for example, insert, query, delete Θ( Lg n) Time complexity, so it is also a more widely used data structure.
One, the red and black tree node
Node properties: Keyword key, node color, left child pointer, right child pointer, parent node pointer, satellite data.
Virtual node-nil: For all nodes in a red-black tree if there is no parent node or a child node is missing, the corresponding pointer is pointed to the same NIL.
Second, the nature of red and black trees
1. The color of each node is red or black.
2, the root node is black.
3, each leaf node is black.
4, if a node is red, his two child nodes are black.
5. For each node in the red-black tree, the same number of black nodes are included on the simple path from the node to all of its descendant leaf nodes.
The black height of the node: the number of black nodes on any simple path from the node (which does not contain the node) to any one of the leaf nodes.
Three, the red black tree rotation
Iv. insertion of red and black trees
V. Removal of red and black trees
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. After the BO Master permission to reprint, must be reproduced in full text, and significant location description of the date and the source link.
Introduction to Algorithms-red and black trees