Applications of red-black trees

后端 未结 4 2036
夕颜
夕颜 2021-01-30 06:35

What are the applications of red-black (RB) trees? Is there any application where only RB Trees can be used and no other data structures?

4条回答
  •  情书的邮戳
    2021-01-30 07:15

    Unless you have very specific performance requirements, an R-B tree could be replaced by some other self-balancing binary tree, for example an AVL tree. Choosing between the two of them is basically a performance optimization - they offer the same basic operations.

    Not that either of them is definitively "faster" than the other, just that they're different enough that specific uses of them will tend to have slightly different performance, all else being equal. So if you draw your requirements carefully enough, or just by chance, you could end up with one of them being "fast enough" for your use, and the other not. R-B offers slightly faster insertion than AVL, at the cost of slightly slower lookup.

提交回复
热议问题