algorithm - 一种高效的排序列表数据结构

标签 algorithm data-structures tree sortedlist

我想根据对象属性中的键以排序的方式保存我的对象。稍后我将从最大键到最小键顺序访问这些对象。我也会执行一些搜索任务。

我考虑使用AVL树或RB树。据我所知,它们在理论上几乎是等价的(两者都有 O(logn))。但实际上,在我的情况下,哪个性能可能更好。考虑到我主要执行插入操作并按顺序访问 DS,还有比这些更好的选择吗?

编辑:我将使用java

最佳答案

无论如何,在 C# 中,SortedDictionary<K, V>被实现为红黑树,并且在 C++ 中的 STL 的许多实现中,std::map<K, T>被实现为红黑树。

此外,来自 Wikipedia关于 AVL 与红黑树:

The AVL tree is another structure supporting O(log n) search, insertion, and removal. It is more rigidly balanced than red-black trees, leading to slower insertion and removal but faster retrieval. This makes it attractive for data structures that may be built once and loaded without reconstruction, such as language dictionaries (or program dictionaries, such as the order codes of an assembler or interpreter).

关于algorithm - 一种高效的排序列表数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2796601/

相关文章:

algorithm - 是否有一个平衡的 BST,每个节点都保持子树的大小?

algorithm - 如果树是平衡的,在二叉搜索树中搜索的时间复杂度是多少?

python - 将嵌套字典展平为列表列表

algorithm - 如何在给定两个相对点的二维矩阵中绘制正方形

c++ - 使用 std::fill 填充多维数组的安全方法是什么?

c - 提高成交率的技巧

database - R-Tree 中的扇出是什么?

c# - 修改代码以获取从牛市到熊市周期平滑趋势的合成数据

python - python中快速选择的实现。函数不稳定并返回不同的值

c++ - 无效转换错误和无效类型