The hardest part of any delivery is the very last stretch.
Your courier needs the fastest way from the depot to a customer across town — but the map has dozens of roads, each with its own drive distace/time. Guess wrong, and every delivery runs long.
The same problem shows up everywhere: a GPS app picking a route, a flight connecting through airports, a data packet hopping across a network. Every time, there are too many paths to just eyeball the fastest one.
A whole city of locations, connected by streets — each labeled with its walking time in minutes.
This is your city: dozens of locations connected by streets, each labeled with its walking time in minutes. Tap a location on the map to set your start, tap another for your destination, then walk your way across town — try to beat Dijkstra's optimal time.
Before we name what you just did, sit with what you noticed.
When you were choosing which location to visit next, what helped you decide where to go?
Did you always choose the road with the smallest distance/time shown on it? What happened when you did?
When you reached a location through different routes, how did you decide which route to keep?
As you visited more locations, how did the distance/time you had already found help you choose your next move?
What did you notice about the way the fastest route was built from one location to another?
Dijkstra's algorithm finds the shortest path from one starting node to every other node in a graph, by always taking the smallest guaranteed step next. It keeps a running "shortest known distance" for every node, and at each turn it locks in whichever unvisited node currently has the smallest number in that table — because once every cheaper path has already been checked, that number can't get any smaller. Locking it in, then rechecking its neighbors for shortcuts, is what lets every node's shortest distance fall into place one at a time, without ever having to try every possible path by hand.
Whenever a shorter path to a node v is found by passing through a just-visited node u, its distance is updated. This single check, repeated over and over, is called "relaxing" the edge.
A few "what would you do" scenarios — no map required, just the idea.
A delivery rider needs to travel from a warehouse to a customer through several roads with different travel times. How could Dijkstra's approach help the rider determine the route with the least total travel time?
Consider the following road network: A–B = 4, A–C = 2, B–C = 1, B–D = 5, C–D = 8. Starting from A, apply Dijkstra's algorithm step by step and determine the shortest path from A to D and its total cost.
Suppose every road in a network takes exactly the same amount of time to travel. Would Dijkstra's algorithm still be necessary? Which simpler approach could be used instead, and why would it produce the same shortest path?
While finding a shortest path, a location may first be reached through one route and later through another shorter route. How does Dijkstra's algorithm handle this change, and why is updating the previously found distance important?
A network contains some connections with negative costs, such as receiving a reward for taking a particular connection. Why can Dijkstra's algorithm fail to find the correct shortest path in this situation? What algorithm could be used instead, and what efficiency trade-off does it involve?
A company has 100 warehouses and wants to know the shortest route between every pair of warehouses, rather than from one warehouse to all others. How does this change the problem, and which algorithm could be used to solve all-pairs shortest paths?
Dijkstra's algorithm systematically builds shortest paths using the costs already found, while ant colony-based approaches discover paths through repeated exploration and reinforcement. How do these two approaches differ in the way they find good paths, and what might be an advantage of using repeated exploration?
You have reached location B with a current travel time of 10 minutes. Later, you find a route to B through location C that takes 4 minutes to reach C and 3 more minutes from C to B. What should happen to B's recorded travel time, and why?
While exploring a graph, Dijkstra's algorithm repeatedly checks whether reaching a neighbouring location through the current location gives a shorter route than the one already known. Why is this step necessary for finding the overall shortest paths?
Dijkstra's algorithm may give an incorrect result when a graph contains negative-weight connections. Bellman-Ford can handle such connections but requires more computation. Why does the presence of negative weights change which algorithm should be used, and what efficiency trade-off is involved?