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).
发布评论
评论(4)
在现实生活中你很少会使用它。我相信斐波那契堆的目的是提高迪杰斯特拉算法的渐近运行时间。它可能会为非常非常大的输入带来改进,但大多数时候,一个简单的二进制堆就足够了。
来自维基:
二叉堆是一种数据结构,可用于快速查找一组值中的最大值(或最小值)。它用于 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:
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).
不能说斐波那契堆,但优先级队列中使用了二进制堆。优先级队列在实际系统中有着广泛的应用。
一个已知的例子是内核中的进程调度。首先执行最高优先级的进程。
我在集合分区中使用了优先级队列。首先选取成员数最多的集合进行划分。
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.
在大多数情况下,您必须根据以下复杂性进行选择:
通常的嫌疑人是:
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:
And the usual suspects are:
log(n)
insert and findO(1)
insert andO(n)
findO(1)
insertO(1)
find for the first element only,O(n)
in generalThere 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.
优先级队列通常以堆的形式实现,例如: 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).