Red black tree over avl tree

前端 未结 5 1356
醉梦人生
醉梦人生 2021-01-29 17:39

AVL and Red black trees are both self-balancing except Red and black color in the nodes. What\'s the main reason for choosing Red black trees instead of AVL trees? What are the

5条回答
  •  -上瘾入骨i
    2021-01-29 18:18

    Try reading this article

    It offers some good insights on differences, similarities, performance, etc.

    Here's a quote from the article:

    RB-Trees are, as well as AVL trees, self-balancing. Both of them provide O(log n) lookup and insertion performance.

    The difference is that RB-Trees guarantee O(1) rotations per insert operation. That is what actually costs performance in real implementations.

    Simplified, RB-Trees gain this advantage from conceptually being 2-3 trees without carrying around the overhead of dynamic node structures. Physically RB-Trees are implemented as binary trees, the red/black-flags simulate 2-3 behaviour

    As far as my own understanding goes, AVL trees and RB trees are not very far off in terms of performance. An RB tree is simply a variant of a B-tree and balancing is implemented differently than an AVL tree.

提交回复
热议问题