对于以下情况有用的数据结构

发布于 2024-11-07 14:15:08 字数 169 浏览 0 评论 0原文

对于以下情况,这可能是最好的数据结构。

1.应具有查找、插入、删除等操作。主要是搜索活动。大约 90% 的操作是搜索,其余的是删除和插入。

2 插入、删除、查找都是根据对象的key来进行的。每个键将指向一个对象。密钥将被排序。

任何有关最佳数据结构的建议都将受到高度赞赏。

Which can be the beste data structures for the following case.

1.Should have operations like search, insert and delete. Mostly searching activities will be there.Around 90% of the operations will be search and rest are delete and insert.

2 Insertion,deletion and searching will be based on the key of the objects. Each key will point to a object. The keys will be sorted.

Any suggestion for optimal data structure will be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

2024-11-14 14:15:08

AVL 树,或者至少是 BST。

如果您想经常访问相同的元素,您可能也需要考虑展开树。

(需要我解释一下原因吗?)

AVL tree, or at least BST.

If you want to acces often the same elements you might want to consider splay trees too.

(Should I explain why?)

行至春深 2024-11-14 14:15:08

不确定你所说的“数据结构”是什么意思

我建议使用MySQL
在这里阅读更多内容:WikiPedia

Not sure by what you mean with "data structures"

I would suggest MySQL.
Read more here: WikiPedia

梦里的微风 2024-11-14 14:15:08

自平衡树(AVL、RB)或哈希表。

Self-balancing tree of sorts (AVL, RB), or a hash table.

岁月打碎记忆 2024-11-14 14:15:08

我的猜测是你想优化时间。总体而言,红黑树在所有三个操作中都将具有对数时间性能。这可能是您对执行时间的最佳总体选择;然而,红黑树实现起来很复杂,并且需要节点结构,这意味着它们将使用比所包含的数据本身所需的内存更多的内存来存储。

My guess is that you want to optimize time. Overall, a red-black tree will have logarithmic-time performance in all three operations. It will probably be your best overall bet on execution time; however, red-black trees are complex to implement and require a node structure meaning they will be stored using more memory than the contained data itself requires.

若水般的淡然安静女子 2024-11-14 14:15:08

你想要一张有树支撑的地图;基本上,您只需要一棵树,其中节点按键动态排序(“自平衡”),并且您的对象用相应的键挂在每个节点上。

如果您想要一个“最佳”数据结构,那完全取决于您期望的输入模式的分布。自平衡树的好处是您实际上不需要太关心输入的模式。如果您确实想要我们所知道的尽可能接近最佳的最佳猜测,并且您对查询的特定序列了解不多,则可以使用 http://en.wikipedia.org/wiki/Tango_tree ,即 O(log(log(N))-竞争如此激烈。慢慢地,出于所有实际目的,您拥有的东西的性能不比您可能选择的最佳数据结构中的常数因子差,

但是实现起来有点蹩脚,您可能最好使用库来实现 。平衡树


https://github.com/pgrafov/python-avl-tree/

Java:
如果您只是使用 Java,只需使用 TreeMap(基于红黑树)并忽略实现细节。大多数语言在其标准库中都有类似的数据结构。

You want a tree-backed Map; basically you just want a tree where the nodes are dynamically sorted ("self-balanced") by key, with your objects hanging off of each node with corresponding key.

If you would like an "optimal" data structure, that completely depends on the distribution of patterns of inputs you expect. The nice thing about a self-balancing tree is you don't really need to care too much about the pattern of inputs. If you really want the best-guess as-close-to-optimal as possible we know of, and you don't know much about the specific sequences of queries, you can use a http://en.wikipedia.org/wiki/Tango_tree which is O(log(log(N))-competitive. This grows so slowly that, for all practical purposes, you have something which performs no worse than effectively a constant factor from the best possible data structure you could have chosen.

However it's somewhat grungy to implement, you may just be better using a library for a self-balancing tree.

Python:
https://github.com/pgrafov/python-avl-tree/

Java:
If you're just Java, just use a TreeMap (red-black tree based) and ignore the implementation details. Most languages have similar data structures in their standard libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文