0

I don't think a c++ priority queue is the right structure for the dijkstra queue, because it contains no functionality for an easy lookup or deletion of elements.

The right structure would be a fibonacci heap, but there is none in the std library.

Does anyone have suggestions for a better, c++ implemented structure?

Pradhan
  • 16,391
  • 3
  • 44
  • 59
thi gg
  • 1,969
  • 2
  • 22
  • 47
  • 1
    There is an implementation of a Fibonacci heap in [Boost](http://www.boost.org/doc/libs/1_55_0/doc/html/boost/heap/fibonacci_heap.html). – D Drmmr Jun 28 '14 at 09:52
  • 1
    I totally recommend the Boost Fibonacci heap or the D_ary heap with D=2 (binary heap). Actually, this last use to be the faster when the grid is not big enough (which is in most applications) – Javi Jun 28 '14 at 10:57

2 Answers2

0

You can use std::set and store a pair<distance, vertex> in it. To lookup and delete elements, you can keep distance to each vertex in an array or in std::vector to obtain a pair<distance, vertex> for a given vertex quickly. The closest unvisited vertex is always in the first element of the set(and can obtained using set.begin()).

kraskevich
  • 18,368
  • 4
  • 33
  • 45
0

For most practical purposes, the std::priority_queue based implementation is good enough for sparse graphs. Implementing Dijkstra this way has a runtime of O(E log V). If you have a dense enough graph, you could simply use the basic O(V*V) version of Dijkstra's algorithm. As the graph gets denser, the asymptotics of the Fib-heap version move closer to the vanilla implementation.

Pradhan
  • 16,391
  • 3
  • 44
  • 59