Dijkstra’s Algorithm (Shortest Path) 🚀
Dijkstra’s Algorithm is used to find the shortest path from a single source vertex to all other vertices in a graph with non-negative weights.
🔹 How It Works
✅ Input: A graph represented as an adjacency list or matrix and a starting node.
✅ Output: The shortest path distances from the source to all nodes.
✅ Time Complexity: O((V + E) log V) (using a priority queue).
✅ Uses: Greedy Approach and Min-Heap (Priority Queue) for efficiency.
🔹 Algorithm Steps
1️⃣ Initialize:
- Set the distance to the source as
0
and all other nodes as∞
. - Use a min-priority queue (heap) to store vertices by distance.
2️⃣ Process Nodes:
- Extract the node with the minimum distance.
- Update distances of neighboring nodes if a shorter path is found.
3️⃣ Repeat Until All Nodes Processed:
- Continue picking the next closest node and updating paths.
🔹 Python Implementation
🔹 Example
Graph Representation:
Shortest Paths from 'A':
🔹 Applications of Dijkstra’s Algorithm
✅ Navigation & GPS Systems (Google Maps, Waze)
✅ Network Routing (OSPF routing in computer networks)
✅ AI & Game Development (Pathfinding in games using A*)
✅ Robotics & Automation (Finding shortest paths in warehouse robots)
No comments:
Post a Comment