Red/black tree

Source: Internet
Author: User

Red/Black: The red/black tree is a binary search tree. The color of each node in the tree is either black or red. You can regard the red and black trees as an Extended Binary Tree and use external nodes to represent null pointers.

Feature 1: The color of the root node and all external nodes is black.

Feature 2: The color of two consecutive nodes from the root node to the external node is red.

Feature 3: All paths from the root node to the external node have the same number of black nodes.

Starting from any node X in the red/black tree (excluding node X), the number of black nodes that reach any path of an external node is called the Black height of X, it is also called the node level. The black height of the red/black tree is defined as the black height of the root node.

Nodes in the red and black trees: Red nodes, black nodes, and external nodes (leaf nodes ).

Conclusion 1: the path length (path length, PL) from the root node to the external node is the number of pointers on the path, if p and q are the two paths from the root node to the external node in the red/black tree, there are: PL (p) <= 2Pl (q ).

Conclusion 2: Set H to the height of a red-black tree (excluding external nodes), N to the number of internal nodes in the tree, and r to the Black height of the root node, so there are a, H <= 2R, B, n> = 2r-1, 3, H <= log2 (n + 1)

Red/black tree

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.