Difference between red-black trees and AVL trees

前端 未结 9 693
温柔的废话
温柔的废话 2020-12-07 08:46

Can someone please explain what the main differences between these two data structures are? I\'ve been trying to find a source online that highlights the differences/simila

9条回答
  •  轮回少年
    2020-12-07 09:36

    The fact that RedBlack trees have less rotations can make them faster on inserts/deletes, however .... . Since they are usually a bit deeper They can also be slower on inserts and deletes. Every time you go from one level in the tree to the next, there is a big change that the information requested is not in the cache and must be retrieved from RAM. Thus the time gained on less rotations can already be lost since it has to navigate deeper and thus have to update its cache more often. Being able to operate from cache or not makes a big difference. If the relevant information is in cache, then you can do multiple rotations operations, in the time needed to navigate an additional level and the next level information is not in cache. Thus in cases that RedBlack is in theory faster, looking only at the operations needed, it could be slower in practice, due to cache misses.

提交回复
热议问题