O(1)随机插入/删除和O(1)随机访问的数据结构有哪些?

编程入门 行业动态 更新时间:2024-10-17 00:19:34
本文介绍了O(1)随机插入/删除和O(1)随机访问的数据结构有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道用什么数据结构来解决这个问题。我想要结构:

I don't know what data structure to use for this problem. I want the structure to have:

  • 定时插入或删除。
  • id。

实际系统是:

我有一个一堆对象,每个对象都有唯一的ID。我的程序将需要接收id的请求并返回相关对象。

I've got a bunch of objects each with a unique id. My program will need to receive requests for an id and return the relevant object.

无论何时收到请求,我想要:搜索结构以查看是否存在。如果是,返回。如果没有,请将其从磁盘加载到内存(将其放在结构中,以便下次请求时不必使用磁盘),然后返回。

Whenever it receives a request I want it to: search the structure to see if it's there. If it is, return it. If it isn't, load it from the disk into memory (put it in the structure so that next time it is requested it doesn't have to use the disk) and then return it.

我正在使用C。

这是一个类似的问题,但我不确定它是多么相关。

Here's a similar question but I'm not sure how relevant it is.

推荐答案

哈希表可能是在你的情况下,很好的解决方案 - 即使没有在O(1)有一个联合:这是一个非常有效的解决方案。

A Hash table might be a pretty good solution in your case -- even if it's not in O(1) when there's a colision : it's a quite efficient solution.

更多推荐

O(1)随机插入/删除和O(1)随机访问的数据结构有哪些?

本文发布于:2023-11-29 22:38:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据结构   有哪些

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!