Dijkstra's Algorithm: Finding
the Shortest Path
Named after Edsger W. Dijkstra, a groundbreaking Dutch computer
scientist. Published in 1959, it remains vital in graph theory. Widely used
in GPS, network routing, and many modern technologies.
by Ghazala Anjum
What is Dijkstra's Algorithm?
Purpose
Finds shortest paths between
nodes in a graph.
Source Node
Calculates shortest paths from
a single source to all other
nodes.
Constraints
Works only with non-negative edge weights (distances).
How Dijkstra's Algorithm Works: Step-by-Step
Initialization
Set source distance to 0, others to infinity.
Select Node
Pick unvisited node with smallest tentative distance.
Update Neighbors
Calculate tentative distances via current node.
Mark Visited
Mark current node as visited.
Repeat
Continue until all nodes are visited or target found.
Dijkstra's Algorithm: A
Visual Example
Graph Setup
Nodes A to E connected with weighted edges.
Source Node
Starting point set at node A.
Distance Updates
Stepwise update of shortest distances to each node.
Shortest Paths
Final paths highlight shortest routes from A to others.
Pseudocode Implementation
Function Dijkstra(Graph, source):
Create vertex set Q
for each vertex v in Graph:
dist[v] ← INFINITY; prev[v] ← UNDEFINED; add v to Q
dist[source] ← 0
while Q is not empty:
u ← vertex in Q with min dist[u]
remove u from Q
for each neighbor v of u:
alt ← dist[u] + length(u, v)
if alt < dist[v]:
dist[v] ← alt
prev[v] ← u
return dist[], prev[]
Code Example (Python)
Uses dictionaries for graph and distances.
Employs priority queue for efficient node selection.
Finds shortest path to a specific target node.
Demonstrates key logic in a compact form.
Time Complexity Analysis
Naive Implementation O(V^2)
With Priority Queue (Heap) O((V + E) log V)
Sparse Graphs O(E log V)
Dense Graphs O(V^2)
Real-World Applications
GPS Navigation
Calculates shortest routes between locations.
Network Routing
Protocols like OSPF use it for optimal data paths.
Robotics
Path planning in known environments.
Social Networks
Calculates degrees of separation between users.
Limitations and
Considerations
Negative Weights
Doesn't handle negative edge
weights; use Bellman-Ford
instead.
Large Graphs
Can be inefficient; consider A*
for better performance.
Edge Weight Assumptions
Edge weights must be non-negative and constant.
Conclusion
Dijkstra is fundamental and
widely adopted for pathfinding.
Efficient for shortest paths in
non-negative weighted graphs.
Key in GPS, routing, robotics,
and many critical systems.

Dijkstras-Algorithm-Finding-the-Shortest-Path.pptx

  • 1.
    Dijkstra's Algorithm: Finding theShortest Path Named after Edsger W. Dijkstra, a groundbreaking Dutch computer scientist. Published in 1959, it remains vital in graph theory. Widely used in GPS, network routing, and many modern technologies. by Ghazala Anjum
  • 2.
    What is Dijkstra'sAlgorithm? Purpose Finds shortest paths between nodes in a graph. Source Node Calculates shortest paths from a single source to all other nodes. Constraints Works only with non-negative edge weights (distances).
  • 3.
    How Dijkstra's AlgorithmWorks: Step-by-Step Initialization Set source distance to 0, others to infinity. Select Node Pick unvisited node with smallest tentative distance. Update Neighbors Calculate tentative distances via current node. Mark Visited Mark current node as visited. Repeat Continue until all nodes are visited or target found.
  • 4.
    Dijkstra's Algorithm: A VisualExample Graph Setup Nodes A to E connected with weighted edges. Source Node Starting point set at node A. Distance Updates Stepwise update of shortest distances to each node. Shortest Paths Final paths highlight shortest routes from A to others.
  • 5.
    Pseudocode Implementation Function Dijkstra(Graph,source): Create vertex set Q for each vertex v in Graph: dist[v] ← INFINITY; prev[v] ← UNDEFINED; add v to Q dist[source] ← 0 while Q is not empty: u ← vertex in Q with min dist[u] remove u from Q for each neighbor v of u: alt ← dist[u] + length(u, v) if alt < dist[v]: dist[v] ← alt prev[v] ← u return dist[], prev[]
  • 6.
    Code Example (Python) Usesdictionaries for graph and distances. Employs priority queue for efficient node selection. Finds shortest path to a specific target node. Demonstrates key logic in a compact form.
  • 7.
    Time Complexity Analysis NaiveImplementation O(V^2) With Priority Queue (Heap) O((V + E) log V) Sparse Graphs O(E log V) Dense Graphs O(V^2)
  • 8.
    Real-World Applications GPS Navigation Calculatesshortest routes between locations. Network Routing Protocols like OSPF use it for optimal data paths. Robotics Path planning in known environments. Social Networks Calculates degrees of separation between users.
  • 9.
    Limitations and Considerations Negative Weights Doesn'thandle negative edge weights; use Bellman-Ford instead. Large Graphs Can be inefficient; consider A* for better performance. Edge Weight Assumptions Edge weights must be non-negative and constant.
  • 10.
    Conclusion Dijkstra is fundamentaland widely adopted for pathfinding. Efficient for shortest paths in non-negative weighted graphs. Key in GPS, routing, robotics, and many critical systems.