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 dequeued I update all adjacent nodes with new distance and where it came from, so I can backtrack the path.
The node in the priority queue is updated with new distance and the node in the array is updated where it came from and with new distance. When a node is dequeued the final distance in the array is updated:
PathInfo current = pq.remove();
path[current.pos].distance = current.distance;
Is it acceptable to update both the array with info about previous node and the priority queue with distance?
This happens whenever a better 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 with basically the same info.
I'm currently using a regular array as a data structure in the PQ. Updating the priority is done in linear time and dequeueing is also done in linear time.
What data structure should I use in the priority queue and how should I change a nodes priority?
I'm using C++