ZZ red and black trees are not as complicated as you think

Source: Internet
Author: User

re-write the chapter on the red and black trees written a year ago. The red/black tree is a very popular Self-adjusted balanced binary sorting tree.

generally, he gives us a complicated impression. He has many cases and must be careful with the rotation. Some people once said on TL that during an interview with a company, they were asked to implement the red/black tree. He doesn't think it makes sense. Few
people can remember so many cases without referring to textbooks.

in this chapter, I will show you the most concise implementation of the Red/black tree that I have ever seen. To what extent is it concise? I bet you can easily pass the above interview-wow, the red and black tree can be as simple as this
!

This implementation comes from Dr. Chris okasaki's research at Carnegie Mellon University (CMU. He inspired me to implement AVL Tree and
splay tree in the same way.

This chapter describes the red and black trees. The general content is as follows:
1. introduction -- let's take a look at the fatal weakness of a common sorting binary tree and give the concept of tree rotation.
2. definition of the Red-black tree -- Let's see why the nature of the Red-black tree solves the balance problem and is better than the sorting binary tree.
3. insert -- we provide a mathematical definition of the algorithm inserted into the red/black tree. Here is the essence of this chapter.
4. delete-delete is not a problem, but we need to show how complicated deletion is than insertion.
6. traditional implementation-Let's look at the complexity of the traditional red/Black Tree Insertion Algorithm and make further comparative analysis. We will leave the traditional deletion algorithm for practice.
7. other words

full text in
https://sites.google.com/site/algoxy/rbtree

because Google site cannot be accessed in China, so I put a copy in the iteye attachment.
http://liuxinyu95.iteye.com/blog/1068508

all Source Code can be obtained on GitHub:
https://github.com/liuxinyu95/AlgoXY

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.