Linux Kernel to the red/black tree and AVL tree,

Source: Internet
Author: User

Linux Kernel to the red/black tree and AVL tree,
Why did Linux use the AVL Tree earlier than the red/black tree later?
In fact, this is the result of the pragmatic nature of the red and black trees. This short article is still a metaphysical point of view. The red-black tree can be exported directly from 2-3 trees. We can not mention the red-black tree, but only 2-3 trees, because the operation of 2-3 trees is too simple. In addition, the operations and features of any red/black tree can be mapped to 2-3 trees. Therefore, the comparison between the red and black trees and AVL trees is a comparison between 2-3 trees and AVL trees.
What are the differences between them? The balance between two and three trees is perfectly balanced, but the number of trees can be three, while the AVL Tree is perfectly balanced by a little difference, it only allows the height difference of the subtree to be 1 at most. It can be seen that 2-3 trees are more balanced than AVL trees, but when 2-3 trees are converted into binary trees, that is, they no longer maintain a perfect balance, because the three nodes need to be split into a red node, so that the height of the subtree is increased by 1. In this case, the red and black trees do not have AVL Tree balance in a strict sense!
Each time the AVL Tree is inserted and deleted, it must maintain a "slightly different balance", while the red and black trees only need not disturb the black nodes. In the case of 2-3 trees, after all, it sacrifices the standard feature of a binary tree to maintain a balance between the three trees. It can be seen that the overhead of insert/delete of the red/black tree is much smaller than that of the AVL tree. In theory, the AVL tree with a more balanced query overhead is better than that of the Red/black tree (because for 2-3 trees, there are three nodes, you need to compare two times), but the imbalance between the two times of the height of the red and black trees is a small probability event! Therefore, in normal cases, you can think that the query overhead of the AVL tree is the same as that of the Red-black tree. In short, in general, the red-black tree is better than the AVL Tree.
The AVL Tree is too ideal, and the data structure in the Linux kernel, especially the virtual memory management module, especially the task columns of the CFS scheduler, will be inserted and deleted frequently, therefore, we chose the red/black tree instead of the AVL 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.