Red/black tree

Source: Internet
Author: User

Binary Search tree with the following features: (the depth of the red/black tree can be ensured to be logarithm-level, and its depth is usually the same as that of the AVL Tree)

1. Each node is marked as red or black.

2. The root is black.

3. If a node is red, its child is black (continuous red nodes are not allowed)

4. Each path from a node to a null chain must contain the same number of black nodes.

Bottom-up insert:

1: (1) the new node must be painted in red.

1) The father of the new node is black and the operation is complete.

2) The father is red and needs to change the color and rotate the tree:

The father's brother node is black, and X is an external grandson.

 

X is the internal grandson

 

 

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.