Red black tree over avl tree

前端 未结 5 1358
醉梦人生
醉梦人生 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条回答
  •  清歌不尽
    2021-01-29 18:08

    Other answers here sum up the pros & cons of RB and AVL trees well, but I found this difference particularly interesting:

    AVL trees do not support constant amortized update cost [but red-black trees do]

    Source: Mehlhorn & Sanders (2008) (section 7.4)

    So, while both RB and AVL trees guarantee O(log(N)) worst-case time for lookup, insert and delete, restoring the AVL/RB property after inserting or deleting a node can be done in O(1) amortized time for red-black trees.

提交回复
热议问题