| ISSUE 119/456 · COMPUTER SCIENCE |
~4 MIN |
FOUNDATION / CS · SHORTEST PATHS · READING DATE 2027-01-28 · JANUARY 2027 — MOTION AND COMPUTING FOUNDATIONS
Why the route with fewer turns can still be slower
START HERE
A route with two road segments can take longer than another with three shorter segments. A shortest-path search finds a connected route whose total chosen cost is smallest. A graph is the mathematical map used for this: places are points, and connections between them carry costs such as travel time.
|
/ WHY NOW
The word “shortest” only makes sense after choosing what to add up. A delivery planner might minimise minutes rather than distance, while another system might count network delay or the number of connections.
|
/ THE IDEA
Dijkstra’s algorithm works with nonnegative connection costs: zero or positive. It keeps the best total cost discovered so far for each point. A settled point has had its least cost declared final; unsettled points have not. Begin with zero at the start and an unknown or infinite cost elsewhere. Repeatedly take the unsettled point with the smallest known total, then test whether reaching its neighbours through it improves their totals. That improvement step is called relaxation. A route discovered later can replace an earlier expensive proposal. With nonnegative costs, once the smallest unsettled total is chosen, going around through still-more-expensive points cannot later make it cheaper, which is why that point can be settled.
THE FORMAL IDEA
candidate = distance[u] + weight(u,v)
| distance[u] = best known total from the start to point u; weight(u,v) = cost of the connection from u to v. | | If candidate is smaller than distance[v], replace distance[v] and remember u as the previous point. This update builds both the total and the route. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy directed roads, costs in minutes: A→B 4; A→C 1; C→B 1; B→D 1; C→D 7. From A: B = 4, C = 1. Settle C: improve B to 2 and propose D = 8. Settle B at 2: improve D to 3. Best route is A→C→B→D. Change only C→B cost to 5: A→B→D now wins at 4+1 = 5 minutes.
|
The original winning route used three connections, while the direct-looking alternative used two. Summing the stated costs, not counting turns, explained the choice. When one connection became slower, the method reconsidered the full route rather than blindly retaining its earlier sequence.
/ SO WHAT?
For a real map, the costs must describe what you actually want to minimise. If a road’s travel time depends on when you enter it, a fixed-cost graph may be too simple. The algorithm can be perfectly correct for its input while the input fails to model the journey you care about.
ONE CAVEAT |
| The toy times are invented. Dijkstra’s settled-point reasoning requires nonnegative weights; negative costs need a different method. Unreachable destinations also need an explicit “no route” result rather than an invented finite cost. |
KEEP THIS
Choose the cost first, then compare accumulated route totals; the fewest connections need not produce the least-cost journey.
|
NEXT: Why stirring syrup takes more force than stirring water
|