Dijkstra's algorithm for computer science

ajmalnajath4 133 views 16 slides Jun 28, 2024
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

Dive into the world of graph theory and shortest path algorithms with our detailed presentation on Dijkstra's Algorithm. This PowerPoint covers:

Introduction to Graph Theory: Basics of graphs, nodes, edges, and weights.
Algorithm Explanation: Step-by-step walkthrough of Dijkstra's Algorithm...


Slide Content

DIJKSTRA'SALGORITHM
By Laksman Veeravagu and Luis Barrera

THEAUTHOR: EDSGERWYBEDIJKSTRA
"Computer Science is no more about computers than
astronomy is about telescopes."
http://www.cs.utexas.edu/~EWD/

SINGLE-SOURCESHORTESTPATHPROBLEM
Single-Source Shortest Path Problem-The problem of
finding shortest paths from a source vertex vto all other
vertices in the graph.

DIJKSTRA'SALGORITHM
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 vertexv∈V to all other
vertices

DIJKSTRA'SALGORITHM-PSEUDOCODE
dist[s] ←0 (distance to source vertex is zero)
forall v ∈V–{s}
dodist[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)
dou ←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]
doifdist[v] > dist[u] + w(u, v) (if new shortest path found)
thend[v] ←d[u] + w(u, v)(set new value of shortest path)
(if desired, add traceback code)
return dist

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

DIJKSTRAANIMATEDEXAMPLE

IMPLEMENTATIONS ANDRUNNINGTIMES
The simplest implementation is to store vertices in an array
or linked list. This will produce a running time of
O(|V|^2 + |E|)
For sparse graphs, or graphs with very few edges and many
nodes, it can be implemented more efficiently storing the
graph in an adjacency list using a binary heap or priority
queue. This will produce a running time of
O((|E|+|V|) log |V|)