数据结构快速插入/缺失与分类

编程入门 行业动态 更新时间:2024-10-28 06:25:11
本文介绍了数据结构快速插入/缺失与分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我拼命寻找一种数据结构,让我完成一个良好的数额插入的,几乎同样多的缺失(幅度大概相同的顺序)和最高(或最低的一个非常快速的查找,可以住在一起或者) 值。 缺失永远只会影响最大(或再次,最低)值。 问题是,这些值必须被排序,并在任何时刻,我可以插入打算在另外两个之间的任何点的元件。我想读(和删除)很快,在任意点的唯一值是最大(或,再次,最小值)。

I'm desperately looking for a data structure allowing me to perform a good amount of insertions, almost as many deletions (probably same order of magnitude) and a very quick lookup of the highest (or the lowest, can live with either) value. The deletion will always only affect the highest (or, again, lowest) value. The problem is that the values have to be sorted and at any moment I could insert an element going at any point between other two. The only value I want to read (and delete) quickly, at any point is the maximum (or, again, minimum).

你有什么建议?

请给算法的复杂性分析,你提出的答案。

Please give algorithmic complexity analysis for your proposed answers.

推荐答案

一个堆是你想要的。这里有一个简单的实现二进制堆。无论是最大堆或最小堆取决于你传递给它的比较功能:的 www.informit/guides/content.aspx?g=dotnet&seqNum=789

A heap is what you want. Here's a simple implementation of a binary heap. Whether it's a max heap or min heap depends on the comparison function you pass to it: www.informit/guides/content.aspx?g=dotnet&seqNum=789

请注意,一个二元堆是不建堆的唯一途径。但它可能是最容易构建,它执行不够好,在大多数情况下。

Note that a binary heap isn't the only way to build a heap. But it's likely the easiest to build, and it performs well enough in most situations.

在堆中的项目不排序,虽然他们订购。唯一的保证是,最高(最低)项目是在堆的顶部,当你问下一个项目将是一个检索。

The items in the heap are not sorted, although they're ordered. The only guarantee is that the highest (lowest) item is at the top of the heap and will be the one retrieved when you ask for the next item.

您正在构建的声音,像一个优先级队列。有实现优先级队列的其他方式。举例来说,我已经看到了跳过列表基于优先级的队列优于基于堆的优先级队列

What you're building sounds like a priority queue. There are other ways to implement a priority queue. For example, I've seen a skip list based priority queue that outperforms a heap-based priority queue.

如果你真的需要O(1)插入,然后寻找到类似的斐波那契堆

If you really need O(1) insertion, then look into something like the Fibonacci heap.

更多推荐

数据结构快速插入/缺失与分类

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

发布评论

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

>www.elefans.com

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