I've been struggling implementing Dijkstra's algorithm; more specifically the part with the priority queue. To add vertices into a data structure and use an iterator to go through all vertices and find the minimum distance; that would be easy, but n time.
What I want is to:
- to be able to insert vertices into the data structure
- extract (return and remove) the vertex v with the lowest distance dist[v]
I believe that for Dijkstra's algorithm to work properly, you should be able to insert vertices in constant time and extract them in log(n) time; and I've been suggested that priority queues and min-heaps could be used, but to me it doesn't seem realistic that we could keep the queue or min-heaps ordered, because the distances are getting constantly modified.
So how am I supposed to declare and use a priority queue, a min-heap or another data structure to do this?