Dijkstra's algorithm is a fundamental graph algorithm that solves the single-source shortest path problem. Given a weighted graph with non-negative edge weights, it efficiently finds the shortest distance from a starting node to every other reachable node in the graph.
The algorithm follows these key steps: First, we initialize all distances to infinity except the source node which gets distance zero. Then we maintain a priority queue of unvisited nodes. In each iteration, we extract the node with minimum distance, mark it as visited, and update the distances to its neighbors if we find a shorter path.
Let's trace through the algorithm execution starting from node A. First, we visit A with distance 0 and update its neighbors D to distance 2 and B to distance 4. Next, we visit D with the smallest unvisited distance of 2, updating E to distance 5. Then we visit B with distance 4, updating C to distance 7 while E remains at 5 since the new path isn't shorter.
The relaxation process is the heart of Dijkstra's algorithm. For each edge from node u to node v with weight w, we check if going through u gives us a shorter path to v. If the current distance to u plus the edge weight is less than the current distance to v, we update v's distance and record u as v's predecessor. This process ensures we always maintain the shortest known distance to each node.
Here are the final results showing the shortest distances from source node A to all other nodes. The algorithm guarantees these are optimal paths. Dijkstra's algorithm has time complexity O of V plus E log V using a binary heap, where V is vertices and E is edges. It's widely used in GPS navigation systems, network routing protocols, and social network analysis for finding optimal connections.