红黑树和AVL树的区别 [英] Difference between red-black trees and AVL trees

查看:34
本文介绍了红黑树和AVL树的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下这两种数据结构之间的主要区别是什么?我一直试图在网上找到一个突出差异/相似之处的来源,但我没有找到任何信息量太大的信息.在什么情况下,一种会比另一种更受欢迎?什么实际情况使一个比另一个更好"使用?

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/similarities, but I haven't found anything too informative. In what cases would one be preferred over the other? What practical situations make one "better" to use than the other?

推荐答案

AVL 树比红黑树保持更严格的平衡.在 AVL 树中从根到最深叶的路径最多为 ~1.44 lg(n+2),而在红黑树中最多为 ~2 lg(n+1).

AVL trees maintain a more rigid balance than red-black trees. The path from the root to the deepest leaf in an AVL tree is at most ~1.44 lg(n+2), while in red black trees it's at most ~2 lg (n+1).

因此,在 AVL 树中的查找通常会更快,但代价是由于更多的旋转操作导致插入和删除速度变慢.因此,如果您预计查找次数将支配树的更新次数,请使用 AVL 树.

As a result, lookup in an AVL tree is typically faster, but this comes at the cost of slower insertion and deletion due to more rotation operations. So use an AVL tree if you expect the number of lookups to dominate the number of updates to the tree.

这篇关于红黑树和AVL树的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆