Data structure Java version of the Red-black tree (eight)

Source: Internet
Author: User

Red black tree is a self-balancing two-fork search tree, because of the existence of red and black rules, so effectively prevent the two fork tree degenerate into a linked list, and find and delete fast, time complexity is log (n).

What is the red and black rule?

1. The root node must be black.

2. The node color is either red or black.

3. Each fork in the tree has the same black node.

4. There are two contiguous red nodes that are not allowed.

How to adapt to the red and black rules in the writing program?

1. Rotate

---single rotation

Lateral node single rotation. The lateral node refers to the left child node of Zuozi and right child node of right child tree.

---double rotation

The inner node is double-rotated. The medial node refers to the right child node of the Zuozi, the left child node of the right child tree.

2. Discoloration

---the node color to make changes.

---Forces the color of the root node to become black.

Post reference link: http://www.cnblogs.com/skywang12345/p/3245399.html (red + black node refers to the parent node is red, the current node is black.) Black + Black is the parent node black, the current node is black. The front color can be seen as inherited).

Data structure Java version of the Red-black tree (eight)

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.