Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard Java implementation of a Fibonacci heap?

I was looking at the different kind of heap data structures.

The Fibonacci heap seems to have the better worst case complexity for (1) insertion, (2) deletion and (2) finding the minimum element.

I have found that in Java there is a class PriorityQueue that is a balanced binary heap. But why they did not use a Fibonacci heap?

Also, is there an implementation of a Fibonacci heap in java.util?

Thanks!

like image 225
Phil Avatar asked Jun 08 '11 03:06

Phil


People also ask

Which data structure is used in the implementation of Fibonacci heap?

A Fibonacci heap is a specific implementation of the heap data structure that makes use of Fibonacci numbers. Fibonacci heaps are used to implement the priority queue element in Dijkstra's algorithm, giving the algorithm a very efficient running time.

Are Fibonacci heaps used in practice?

To the best of my knowledge, there are no major applications that actually use Fibonacci heaps or Brodal queues. Fibonacci heaps were initially designed to satisfy a theoretical rather than a practical need: to speed up Dijkstra's shortest paths algorithm asymptotically.

Is Fibonacci heap a priority queue?

In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the binary heap and binomial heap.

Is binomial heap a Fibonacci heap?

In Fibonacci Heap, trees can have any shape even all trees can be single nodes (This is unlike Binomial Heap where every tree has to be a Binomial Tree). Fibonacci Heap maintains a pointer to a minimum value (which is the root of a tree).


2 Answers

But why they did not use a Fibonacci heap?

Probably because those heaps have a lot more overhead per entry than binary keys.

Also, is there an implementation of Fibonacci heap in Java.util?

No, but

  1. There is graphmaker from Nathan Fiedler - GPL and with good test coverage, but have a look into this nice blog post about it and about problems a fibonacci impl can have. In this post a lot of other Java implementions are referenced.
  2. There is some code with unit tests here
  3. The JGraphT project (also Nathan Fiedler) and also with (some minor) tests but LGPL.
  4. Last but not least there is Neo4j - GPL - no tests.
like image 25
Karussell Avatar answered Sep 28 '22 01:09

Karussell


No, the standard Java collections API does not contain an implementation of a Fibonacci heap. I'm not sure why this is, but I believe it is because while Fibonacci heaps are asymptotically great in an amortized sense, they have huge constant factors in practice. The collections framework also doesn't have a binomial heap, which would be another good heap to include.

As a totally shameless self-plug, I have an implementation of a Fibonacci heap in Java on my personal website. I'm not sure how useful it will be, but if you're curious to see how it works I think it might be a good starting point.

Hope this helps!

like image 135
templatetypedef Avatar answered Sep 27 '22 23:09

templatetypedef