我应该使用什么树结构来建立索引?
我正在考虑尝试使用树结构进行索引,因为我想测试它是否比我当前的索引实现(本质上是基于哈希的查找)更快。
我阅读了有关 B 树、AVL 树和红黑树性能的各种问题和文章,但实际上看不出它们在性能方面有多大区别。
人们会推荐什么树结构,为什么?理想情况下,它应该有一个可用的现有 .Net 实现,尽管我并不反对在必要时实现我自己的实现
I'm thinking of experimenting with using a tree-structure for indexing as I want to test whether it is faster than my current indexing implementation which is in essence a hash based lookup.
I've read up on various questions and articles about performance of B-Trees, AVL-Trees and Red-Black Trees and can't really see much difference between them performance wise.
What tree structure would people recommend and why? Ideally it should have an existing .Net implementation available though I'm not averse to implementing my own if necessary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个好的哈希表几乎总是比树更快。树的最大优点是您可以使用它来查询范围和排序。因此,如果您不需要这些功能,我宁愿考虑优化基于哈希的解决方案。
并且 AFAIK
SortedDictionary
是基于树的。A good hashtable is almost always faster than a tree. The great advantage of the tree is that you can use it to query ranges and for ordering. So if you don't need these features I'd rather look into optimizing your hash based solution.
And AFAIK
SortedDictionary<K,V>
is tree based.二叉树不是平衡的。不要使用它。
AVL树比红黑树具有更好的平衡性;它有更快的查找速度。
更重要的是,AVL 算法简单易懂。 IME 并不是红黑算法的情况。你无法实现你不理解的算法,或者更确切地说,你可以盲目地实现它们,在我看来,这完全等同于无法实现它们。
A binary tree is not balanced. Do not use it.
An AVL tree is better balanced than a red-black tree; it has faster lookup.
Much more importantly, the AVL algorithm is straightforward and comprehendable. This is, IME, not the case for the red-black algorithm. You cannot implement algorithms you do not understand, or rather, you can implement them blindly, which is properly tantamount in my view to -not- being able to implement them.