Skip to main content

Posts

Showing posts with the label graph algorithms

What is Dijkstra's Algorithm? Explanation and Example

Common applications of Dijkstra's algorithm include: GPS navigation systems Computer network routing Game AI pathfinding Robotics and autonomous vehicles Map-based location recommendation services 1. How It Works Dijkstra's algorithm is based on a greedy approach and operates in the following steps: Set the distance of the starting node to 0, and all other nodes to ∞ $\text{(infinity)}$ . Select the node with the smallest tentative distance $\text{(initially the start node)}$ . For each neighboring node of the current node: 1) Calculate the tentative distance through the current node. 2) If this new distance is shorter than the currently recorded one, update it. 3) Mark the current node as visited (processed). 4) Repeat steps 2–4 until all nodes have been visited. Example Graph               Graph represented as an edge list: $\text{A -> B (1), A -> C (4)}$ $\text{B -> C (2), B -> D (5)}$ $\text{C -...