|
Why Linux previously used by AVL trees and red-black tree was predisposed towards?
In fact, this is the result of red-black tree pragmatism characteristics caused this essay is still a metaphysical point of view. Red-black tree can be derived directly from the 2-3 tree, we can no longer mention the red-black tree, but only to mention the 2-3 tree, because the operation is too simple a 2-3 tree. In addition, any operation and characteristics of the red-black tree can be mapped to a 2-3 tree. Therefore, red and black, and AVL trees became 2-3 Comparative Comparative tree and AVL tree.
Where the difference between the two of them? 2-3 balanced tree is perfectly balanced, but it may be the number of branches to three, and AVL tree almost perfectly balanced point binary standard allows only the sub-tree of a height difference of up to 1. So it seems visible, 2-3 tree more balanced than an AVL tree, but the 2-3 tree into a binary tree, red-black tree that is when it is no longer able to maintain the perfect balance, because the trigeminal node to split out a red node so that the sub-tree height plus 1, so it seems, in the strict sense of the red-black tree AVL tree is no balance!
AVL tree at each insertion and deletion must maintain it was "almost point of balance", and red-black tree without disturbing black nodes only need to order a 2-3 tree is concerned, it is after all the expense of a binary tree standard features into a ternary tree to maintain balance. Visible, red-black tree insertion / deletion costs far less than the AVL tree, the query overhead, in theory, a more balanced AVL tree better than the red-black tree (because the tree for 2-3 encountered trigeminal node, you need to compare 2 times), but the red-black tree twice tree height imbalance is a small probability event! So for normal circumstances, you can think of query cost AVL trees and red-black tree is the same, in short, under normal circumstances, is better than the red-black tree AVL tree.
AVL tree was over, while the Linux kernel data structures, especially virtual memory management module, especially the CFS scheduler task column, they are frequently inserted removed, so choose the red-black tree instead of AVL tree . |
|
|
|