二叉堆和斐波那契堆的现实应用

发布于 2024-09-24 10:20:43 字数 1435 浏览 4 评论 0原文

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

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

发布评论

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

评论(4

厌倦 2024-10-01 10:20:43

在现实生活中你很少会使用它。我相信斐波那契堆的目的是提高迪杰斯特拉算法的渐近运行时间。它可能会为非常非常大的输入带来改进,但大多数时候,一个简单的二进制堆就足够了。

来自维基:

虽然一个的总运行时间
操作顺序开始于
空结构的边界是
上面给出的界限,一些(很少)
序列中的操作可以采取
完成时间很长(特别是
删除和删除最小值具有线性关系
最坏情况下的运行时间)。为了
这就是斐波那契堆和其他原因
摊销数据结构可能不是
适用于实时系统。

二叉堆是一种数据结构,可用于快速查找一组值中的最大值(或最小值)。它用于 Dijkstra 算法(最短路径)、Prim 算法(最小生成树)和 Huffman 编码(数据压缩)。

You would rarely use one in real life. I believe the purpose of the Fibonacci heap was to improve the asymptotic running time of Dijkstra's algorithm. It might give you an improvement for very, very large inputs, but most of the time, a simple binary heap is all you need.

From Wiki:

Although the total running time of a
sequence of operations starting with
an empty structure is bounded by the
bounds given above, some (very few)
operations in the sequence can take
very long to complete (in particular
delete and delete minimum have linear
running time in the worst case). For
this reason Fibonacci heaps and other
amortized data structures may not be
appropriate for real-time systems.

The binary heap is a data structure that can be used to quickly find the maximum (or minimum) value in a set of values. It's used in Dijkstra's algorithm (shortest path), Prim's algorithm (minimum spanning tree) and Huffman encoding (data compression).

草莓味的萝莉 2024-10-01 10:20:43

不能说斐波那契堆,但优先级队列中使用了二进制堆。优先级队列在实际系统中有着广泛的应用。

一个已知的例子是内核中的进程调度。首先执行最高优先级的进程。

我在集合分区中使用了优先级队列。首先选取成员数最多的集合进行划分。

Can't say about the fibonacci heaps but binary heaps are used in the priority queues. Priority queues are widely used in the real systems.

One known example is process scheduling in the kernel. The highest priority process is taken first.

I have used the priority queues in the partitioning of the sets. The set which has the maximum members was to be taken first for the partitioning.

牛↙奶布丁 2024-10-01 10:20:43

在大多数情况下,您必须根据以下复杂性进行选择:

  • 插入
  • 查找元素

通常的嫌疑人是:

  • BST:log(n) 插入和查找
  • 链表:O(1)< /code> 插入并 O(n) 查找
  • 堆:
    • O(1) 插入
    • O(1)仅查找第一个元素,一般O(n)
      • 二进制堆的最坏情况
      • 按斐波那契数摊销

还有 Brodal 队列 和其他达到 O(1) 最坏情况的堆,但需要 甚至比斐波那契更大的队列也是值得的。

因此,如果您的算法只需要“查找”第一个元素并进行大量插入,那么堆是一个不错的选择。

正如其他人提到的,迪杰斯特拉就是这种情况。

In most scenarios, you have to choose based on the complexity of:

  • insertion
  • finding elements

And the usual suspects are:

  • BST: log(n) insert and find
  • linked list: O(1) insert and O(n) find
  • heap:
    • O(1) insert
    • O(1) find for the first element only, O(n) in general
      • worst case for the binary heap
      • amortized for Fibonacci

There is also the Brodal queue and other heaps which reach O(1) worst case, but requires even larger queues than Fibonacci to be worth it.

So if your algorithm only needs to "find" the first element and do lots of insertions, heaps are a good choice.

As others mentioned, this is the case for Dijkstra.

帅哥哥的热头脑 2024-10-01 10:20:43

优先级队列通常以堆的形式实现,例如: http ://download.oracle.com/javase/6/docs/api/java/util/PriorityQueue.html

使用二进制堆可以有效地计算大型数据集中的前 N ​​个元素(例如顶部搜索)大型网站中的查询)。

Priority queues are usually implemented as heaps, for example: http://download.oracle.com/javase/6/docs/api/java/util/PriorityQueue.html

Computing the top N elements from a huge data-set can be done efficiently using binary heaps (e.g. top search queries in a large-scale website).

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