Dijkstra Algorithm with Priority Queue

In my implementation of Dijkstra's algorithm, I have 1 array with all nodes and 1 priority queue with all nodes. Whenever a node is deleted, I update all neighboring nodes with a new distance and where it came from, so I can undo the path.

the node in the priority queue is updated with the new distance, and the node in the array is updated where it came from and with the new distance. When the node value is canceled, the last distance in the array is updated:

  PathInfo current = pq.remove();
  path[current.pos].distance = current.distance;

Is it permissible to update both arrays with information about the previous node and priority queues with distance?

This happens when the best distance is found:

      PathInfo key(i, newDistance);
      path[i].distance = newDistance;
      path[i].previous = current.pos;
      pq.decreaseKey(key);

It seems a bit redundant to update my array and priority queue basically with the same information.

PQ. , .

?

++

+5
2

: " ", , " ", ( , ).

, . , node, : arrayNode.distance arrayNode.finalDistance.

: , Dijkstra, node , .


, , decreaseKey(). decreaseKey() , , - node.

, decreaseKey() , , , , ....

+1

, :

, .

node , .

. node, , algo. O (N ^ 2) ( node ) , ( )

0

All Articles