Introduction to Algorithms-red and black trees

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.