The Route with Fewer Stops Takes Longer

Distinguish minimum-hop paths from minimum-cost paths and implement Dijkstra’s nonnegative-cost frontier with explicit unreachable and tie semantics.

14 sections · 4 questions · 1 coding challenge

1 / 14

Shortest Routes Needed a Cost-Aware Search

BOTIE

Dijkstra’s 1959 paper described a procedure for finding the shortest route between nodes in a weighted graph. The useful step is to separate tentative distances from settled ones: with nonnegative lengths, the least tentative distance cannot later be improved by taking a detour through a more expensive unsettled node.

Dijkstra’s shortest-path method is used to find minimum accumulated cost in graphs with suitable nonnegative weights. Neo4j’s Graph Data Science documentation exposes that method separately from simple hop-count path matching. The algorithm keeps the cheapest unsettled distance visible rather than committing to the first route discovered.

For our cart, that distinction allows a route with an extra stop to win. The Python exercise implements a small nonnegative-weight version so we can inspect why the earlier expensive route is replaced.

Sources for this history