8

I am interested in implementing a priority queue to enable an efficient Astar implementation that is also relatively simple (the priority queue is simple I mean).

It seems that because a Skip List offers a simple O(1) extract-Min operation and an insert operation that is O(Log N) it may be competitive with the more difficult to implement Fibonacci Heap which has O(log N) extract-Min and an O(1) insert. I suppose that the Skip-List would be better for a graph with sparse nodes whereas a Fibonacci heap would be better for an environment with more densely connected nodes.

This would probably make the Fibonacci Heap usually better, but am I correct in assuming that Big-Oh wise these would be similar?

templatetypedef
  • 328,018
  • 92
  • 813
  • 992
user_48349383
  • 517
  • 6
  • 13

2 Answers2

6

The raison d'etre of the Fibonacci heap is the O(1) decrease-key operation, enabling Dijkstra's algorithm to run in time O(|V| log |V| + |E|). In practice, however, if I needed an efficient decrease-key operation, I'd use a pairing heap, since the Fibonacci heap has awful constants. If your keys are small integers, it may be even better just to use bins.

cutting plane
  • 226
  • 1
  • 2
  • (If you want simple and reasonably efficient, it's hard to do better than the standard library.) – cutting plane Jul 27 '11 at 16:00
  • A fibonacci heap is difficult to implement anyway, and mainly of theoretical interest. The union operation runs at O(1), another reason why one might want to explore this datastructure. – OckhamsRazor Apr 23 '12 at 10:17
4

Fibonacci heaps are very very very slow except for very very very very large and dense graphs (on the order of hundreds of millions of edges). They are also notoriously difficult to implement correctly.

On the other hand, skip lists are very nice data structures and relatively simple to implement.

However I wonder why you're not considering using a simple binary heap. I believe binary heaps-based priority queues are even faster than skip list-based priority queues. Skip lists are mainly used to take advantage of concurrency.

tskuzzy
  • 34,355
  • 14
  • 66
  • 132
  • A binary heap alone is not going to work, because it takes O(n) to find a particular node and updates its priority(in this case, the aggregated distance from source). You can, however, introduce an additional unordered_map for O(1) location of a node, then it will reduce the complexity to O(logn), which is given by the bottleneck of "heapify" after your priority update. – h9uest Apr 06 '15 at 10:53