Weighted Graphs
- A weighted graph has a value (edge weights) attached to each edge
- Shortest path → minimum sum of edge weights between two vertices
- Also called distance between vertices
Dijkstra’s Algorithm
- Dijkstra’s algorithm finds shortest path to all vertices from start vertex
- Graph must be connected, with undirected edges and non-negative edge weights
- This is a greedy algorithm → optimal choice made at each step without considering what is ahead or already transpired
- ! If we have negative-weight edges, it could mess up distances for vertices already in the cloud breaking the algorithm
How does it work?
- We grow a ‘cloud’ of vertices (like Prim-Jarník’s algorithm)
- Begin with starting vertex
s - Eventually cover all vertices
- Begin with starting vertex
- Store with each vertex
va labeld(v)representing current known shortest path fromvtosin the subgraph- Subgraph contains cloud and adjacent vertices
- At each step:
- Add to the cloud vertex
u, which is outside the cloud and has the smallest distance label,d(u) - Update the labels of vertices adjacent to
u
- Add to the cloud vertex
Runs in time, given we are using adjacency list structure
Edge Relaxation
-
Consider edge
e = (u,z)such that:uis vertex most recently added to cloudzis not in cloud

-
The relaxation of edge
eupdates distanced(z)as follows:d(z)←

Edge relaxation is used in Dijkstra’s algorithm to update our distance labels
End of Unit!