Real world applications of Binary heaps and Fibonacci Heaps [closed]

自作多情 提交于 2019-11-27 10:48:59

问题


What are the real world applications of Fibonacci heaps and binary heaps? It'd be great if you could share some instance when you used it to solve a problem.

Edit: Added binary heaps also. Curious to know.


回答1:


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).




回答2:


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.




回答3:


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
      • average for binary heap, see: https://stackoverflow.com/a/29548834/895245)
      • amortized for Fibonacci. This is stronger than average, weaker than worst case.
    • 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.




回答4:


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).



来源:https://stackoverflow.com/questions/3767863/real-world-applications-of-binary-heaps-and-fibonacci-heaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!