[Data Structure] red and Black (red-black tree)-Notes

Source: Internet
Author: User

1. Red Black Tree Properties: The path of the root to the leaf, the longest path is not greater than the shortest path of twice times.

2. The red-black tree is a binary search tree and has

A. Each node has a color attribute, red or black, in addition to the properties of the left, right, and parent nodes.

B. ( root attribute ) The root of the red and black tree can only be black.

C. ( red attribute ) The child nodes of the red node can only be black

D. ( black attribute ) The number of black nodes that appear on each path from a given node to its descendant leaf nodes. The number of black nodes that appear on the path from a node to the leaf node of its descendants is called the black height of the node (black-height).

3. The search and output operations on the red and black trees are the same on the binary tree. The insertion and deletion of binary search may break the red and black tree features mentioned above when applied to the red-black tree. If broken, the structure needs to be adjusted to restore the properties of the red-black tree.

4. Insert operation, each inserted node is marked in red, there may be two consecutive red nodes, so that the red property is broken. If broken, depending on the color of the tertiary node (the sibling node of the parent node), different adjustment methods are used.

Delete operation, delete the node if it is red, will not break the characteristics, if it is black, may change the black height of the other nodes, breaking black properties. If broken, also need to divide the situation, the use of different adjustment methods.

Insert operation, delete operation of the specific implementation, has not been read through, there is a need for further understanding.

Scenario: Java HashMap uses a red-black tree structure to store conflicting elements when dealing with a large number of hash value collisions, improving performance.

Resources

Red-black Trees, cs.wisc.edu

Red–black Tree, Wikipedia

Red-black Tree | Set 3 (Delete), geeksforgeeks.org

13th chapter red and Black Tree "introduction to Algorithms"

[Data Structure] red and Black (red-black tree)-Notes

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.