Algorithm
Dijkstra's Algorithm:
- Initialize the distance of the source node to 0 and all other nodes to infinity.
- Create a priority queue and add the source node with a distance of 0.
- While the priority queue is not empty:
- Extract the node with the smallest distance from the priority queue.
- For each neighboring node of the extracted node:
- Calculate the tentative distance to the neighbor.
- If the tentative distance is smaller than the currently known distance, update it.
- Add the neighbor to the priority queue with the updated distance.
Example:

Fig. 1: Step-by-Step Process of Dijkstra's Algorithm
Note: Dijkstra's Algorithm works only with graphs that have non-negative edge weights.