Dijkstra's algorithm
Dijkstra finds the cheapest path from one source to every node in a graph with non-negative edge weights. Green arrows form the final shortest-path tree; grey edges were never the best option, and each node's height is its distance from A.
Start at the source
A gets distance 0 and every other node infinity. Settling A relaxes its edges: C becomes 2 and B becomes 4, both tentative.
Settle the closest: C
C (2) is the smallest tentative distance, so it is final. Relaxing its edges improves B from 4 to 2+1 = 3, and gives D 10 and E 12.
B, then D
B is settled at 3 and lowers D to 3+5 = 8. Then D (8) is the closest, so it is settled, and it lowers E to 10 and gives F 14.
E and F
E is settled at 10 and improves F to 10+3 = 13, beating the route through D. Finally F is settled at 13 and the queue is empty.
The shortest-path tree
Following each node's best predecessor gives the tree A-C-B-D-E-F. Because a node is only settled when it is the closest left, its distance can never improve later.