"Introduction to Algorithms", 13th chapter, Red and black trees

Source: Internet
Author: User

The red-black tree is a "balanced" lookup tree that can determine the dynamic set operation time O (LOGN)

13.1 Nature of red and black trees

Each node of the red and black tree has color, except key, value, p, left, right,

A value is considered an inner node, and if there is no son, the son is nil,

Red Black Nature:
1. Each node is either red or black

2. Root node Black

3, leaf node (NIL) Black

4, if the node is red, then the son is black

5, starting from any node, any one of the following path, the number of black nodes are the same.

Witty handling

The nil node points to the same location, whose value is Nil,p, left, and right's definition is not important.

The number of black nodes in any one path of the tree is called the black height.

Theorem: N nodes with a red-black tree height of up to 2log (n+1)

13.2 rotation

Inserting and removing elements that may cause red-black properties to change, in order to maintain the red-black nature, can be rotated.

L-and right-handed:

L: Left parent right child to right parent left dial hand:

Right: Right parent left dial hand to left parent right child:

13.3 inserting

13.4 Delete

"Introduction to Algorithms", 13th chapter, 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.