Dijkstra's Shortest Path
Single-source shortest paths on a non-negative weighted graph
From tentative to final distances
Dijkstra's algorithm stores the best distance currently known from one source to every vertex. The source starts at 0 and all other vertices start at infinity. Repeatedly choose the unsettled vertex with the smallest tentative distance, settle it, and relax each outgoing edge.
Watch relaxation change the graph
The amber ring marks the active vertex, green vertices are settled, and the small badge beside each vertex is its current distance. An edge relaxation asks whether reaching a neighbor through the active vertex is shorter than the route stored so far. The final green edges form a shortest-path tree rooted at A.
Set the source distance to 0 and every other distance to infinity.
Why non-negative weights matter
Once the nearest unsettled vertex is chosen, non-negative edges guarantee that no later route can make it cheaper. Negative edges break that argument. With a binary heap, the usual running time is O((V + E) log V).