Linux kernel to red-black tree and AVL tree

Source: Internet
Author: User

Why did Linux use the AVL tree earlier and then prefer the red-black tree?
In fact, this is the result of the pragmatism of the red and black tree, and this essay remains a metaphysical point of view. Red and black trees can be exported directly from 2-3 trees, we can no longer mention the red and black trees, but only 2-3 trees, because the operation of the 2-3 tree is too simple. In addition, the operation and characteristics of any red-black tree can be mapped to 2-3 trees. The comparison between the red and black and AVL trees is therefore a comparison of 2-3 and AVL trees.
What's the difference between the two? The balance of the 2-3 tree is perfectly balanced, but the number of branches can be 3, while the AVL tree almost points to a perfectly balanced standard binary tree, which allows only the height difference of the subtree to be up to 1. So it seems that 2-3 trees more balanced than AVL tree, but 2-3 trees converted to two tree, that is, the red and black trees, it can no longer maintain the perfect balance, because the three fork node to be split out a red node, so that the subtree height plus 1, so it seems that the red and black trees in strict sense no AVL tree balance!
The AVL tree maintains its "close balance" every time the insert is deleted, while the red-black tree requires no disturbance to the black node, which, in 2-3 trees, is the standard feature that sacrifices the two-fork tree to maintain the balance of the three-prong tree. Visible, red black tree Insert/delete cost is much smaller than the AVL tree, for query overhead, theoretically, more balanced AVL tree is better than red black tree (because for 2-3 trees, you need to compare 2 times), but, the red black tree twice times the height of the unbalanced state is a small probability event! So for normal situations, you can assume that the query cost of the AVL tree and the red-black tree is the same, in short, the red-black tree is better than the AVL tree in general.
The AVL tree is ideal, and the data structures in the Linux kernel, especially the virtual memory management module, especially the task pair columns of the CFS scheduler, are frequently inserted and deleted, so the red-black tree is chosen instead of the AVL tree.


Linux kernel to red-black tree and AVL tree

Related Article

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.