SlideShare a Scribd company logo
4
Most read
10
Most read
15
Most read
DIJKSTRA'S ALGORITHM
By Laksman Veeravagu and Luis Barrera
THE AUTHOR: EDSGER WYBE DIJKSTRA
"Computer Science is no more about computers than
astronomy is about telescopes."
http://www.cs.utexas.edu/~EWD/
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.
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
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
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
DIJKSTRA ANIMATED EXAMPLE
IMPLEMENTATIONS AND RUNNING TIMES
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|)

More Related Content

PPT
barrera.ppt
PPT
barrera.ppt
PPTX
Dijkstras-Algorithm-Finding-the-Shortest-Path.pptx
PPTX
dms slide discrete mathematics sem 2 engineering
PPTX
DIJKSTRA_123.pptx
PPTX
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
PPTX
Dijkstra's algorithm presentation
PPT
dijkstra algo.ppt
barrera.ppt
barrera.ppt
Dijkstras-Algorithm-Finding-the-Shortest-Path.pptx
dms slide discrete mathematics sem 2 engineering
DIJKSTRA_123.pptx
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
Dijkstra's algorithm presentation
dijkstra algo.ppt

Similar to Dijkstra's algorithm for computer science (20)

PDF
All pairs shortest path algorithm
PPTX
Dijkstra’s algorithm
PDF
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
PDF
Dijkstra Shortest Path Visualization
PPTX
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
PPT
2.3 shortest path dijkstra’s
PPTX
Data structures and algorithms Dijkstra’s Algorithm (1).pptx
PPT
Dijkstra algorithm ds 57612334t4t44.ppt
PPT
Dijkstra Shortest Path Algorithm in Network.ppt
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
PPT
Shortest path
PDF
04 greedyalgorithmsii 2x2
PPTX
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
PPT
10--Dijkstra-s-Shortest-Path-and-Graph-Representations-24042025-113241am.ppt
PPT
Dijkstra c
DOCX
Shortest Path Problem.docx
PPTX
Shortest-Path Problems - Graph Theory in Computer Applications
PPT
Dijsktra’s Sortest path algorithm
PPT
Dijkstra.ppt
PPTX
15-bellmanFord.pptx...........................................
All pairs shortest path algorithm
Dijkstra’s algorithm
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
Dijkstra Shortest Path Visualization
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
2.3 shortest path dijkstra’s
Data structures and algorithms Dijkstra’s Algorithm (1).pptx
Dijkstra algorithm ds 57612334t4t44.ppt
Dijkstra Shortest Path Algorithm in Network.ppt
Lecture 16 - Dijkstra's Algorithm.pdf
Shortest path
04 greedyalgorithmsii 2x2
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
10--Dijkstra-s-Shortest-Path-and-Graph-Representations-24042025-113241am.ppt
Dijkstra c
Shortest Path Problem.docx
Shortest-Path Problems - Graph Theory in Computer Applications
Dijsktra’s Sortest path algorithm
Dijkstra.ppt
15-bellmanFord.pptx...........................................
Ad

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
web development for engineering and engineering
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Internship_Presentation_Final engineering.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
Queuing formulas to evaluate throughputs and servers
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Model Code of Practice - Construction Work - 21102022 .pdf
web development for engineering and engineering
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Simulation of electric circuit laws using tinkercad.pptx
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Lesson 3_Tessellation.pptx finite Mathematics
Internship_Presentation_Final engineering.pptx
Structs to JSON How Go Powers REST APIs.pdf
Chapter 6 Design in software Engineeing.ppt
Queuing formulas to evaluate throughputs and servers
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
AgentX UiPath Community Webinar series - Delhi
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Ad

Dijkstra's algorithm for computer science

  • 1. DIJKSTRA'S ALGORITHM By Laksman Veeravagu and Luis Barrera
  • 2. THE AUTHOR: EDSGER WYBE DIJKSTRA "Computer Science is no more about computers than astronomy is about telescopes." http://www.cs.utexas.edu/~EWD/
  • 3. 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.
  • 4. 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
  • 5. 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
  • 16. IMPLEMENTATIONS AND RUNNING TIMES 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|)