MST (Dijkstra)
MST (Dijkstra)
(Dijkstra’s Algorithm)
Single-Source Shortest Path Problem
2
Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the single-
source shortest path problem in graph theory.
Works on both directed and undirected graphs.
However, all edges must have nonnegative weights.
Approach: Greedy
Input: Weighted graph G={E,V} and source vertex
v∈V, such that all edge weights are nonnegative
Output: Lengths of shortest paths (or the shortest
paths themselves) from a given source vertex v∈V
to all other vertices
3
Dijkstra's algorithm - Pseudocode
5
Dijkstra Animated Example
6
Dijkstra Animated Example
7
Dijkstra Animated Example
8
Dijkstra Animated Example
9
Dijkstra Animated Example
10
Dijkstra Animated Example
11
Dijkstra Animated Example
12
Dijkstra Animated Example
13
Dijkstra Animated Example
14
DIJKSTRA'S ALGORITHM - WHY USE
IT?
• As mentioned, Dijkstra’s algorithm calculates
the shortest path to every vertex.
• Therefore, anytime we are able to know the
optimal path to some other vertex from a
determined origin through Dijkstra’s
algorithm.
15
Applications of Dijkstra's Algorithm
- Traffic Information Systems are most
prominent use
- Mapping (Map Quest, Google Maps)
- Routing Systems
16