Several cities are connected by roads. How can we find the shortest route from the starting point to the destination? Dijkstra’s algorithm works by successively confirming the “closest city known so far,” eventually finding the shortest distance.
How it works: Start by setting the distance to the starting point to 0 and all other distances to infinity. Each time, confirm the “closest city among those not yet confirmed,” then check whether going through that city gives a shorter distance to each neighboring city and update the distances if necessary. Repeat until every city has been confirmed.
Choose a start and destination city, then begin.
💡 Everything from route finding in real map apps to routing that delivers internet data along optimal paths is built on this algorithm (or one of its relatives).