0% found this document useful (0 votes)
11 views16 pages

MST (Dijkstra)

Dijkstra's algorithm is a method for solving the single-source shortest path problem in graph theory, applicable to both directed and undirected graphs with nonnegative edge weights. It utilizes a greedy approach to determine the shortest paths from a source vertex to all other vertices in a weighted graph. Common applications include traffic information systems and mapping services like Google Maps.

Uploaded by

A1Virus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

MST (Dijkstra)

Dijkstra's algorithm is a method for solving the single-source shortest path problem in graph theory, applicable to both directed and undirected graphs with nonnegative edge weights. It utilizes a greedy approach to determine the shortest paths from a source vertex to all other vertices in a weighted graph. Common applications include traffic information systems and mapping services like Google Maps.

Uploaded by

A1Virus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

SWE 213

Computer Algorithms With Lab

Minimum Spanning Tree

(Dijkstra’s Algorithm)
Single-Source Shortest Path Problem

Single-Source Shortest Path Problem - The


problem of finding shortest paths from a source
vertex v to all other vertices in the graph.

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

dist[s] ←0 (distance to source vertex is zero)


for all v ∈ V–{s}
do dist[v] ←∞ (set all other distances to infinity)
S←∅ (S, the set of visited vertices is initially
empty)
Q←V (Q, the queue initially contains all
vertices)
while Q ≠∅ (while the queue is not empty)
do u ← mindistance(Q,dist)(select the element of Q with the min.
distance)
S←S∪{u} (add u to list of visited vertices)
for all v ∈ neighbors[u]
do if dist[v] > dist[u] + w(u, v) (if new shortest path
found)
then d[v] ←d[u] + w(u, v) (set new value of
shortest path)
(if desired, add traceback code)
return dist
4
Dijkstra Animated Example

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

You might also like