previous | start | next

Indexed minPriorityQueue

Shortest Path from a single source vertex in a weighted digraph with no negative weights

For the graph algorithm to solve this problem, we needed to pick a vertex of minimum distance to the source from the vertices that are connected by an edge to "known" vertices.

The distTo[v] array will keep track of the best distance so far from the source to vertex v.

But this distance might decrease by using a path through a vertex chosen later!

What data structure? We want to know what vertex to add next to the ones with known shortest distance.

A minPriorityQueue seems a possibly good choice with (vertex, distance) pairs, where the distance is the priority.

But there is a problem. How do we update the distance for some vertex that is already in the priority queue.

Example in class



previous | start | next