August 2026
Intermediate
138 pages
2h 57m
English

Suppose that you need to find the fastest walking route between two locations in a city. To do so, you would model roads as graph edges connecting corners (vertices), with travel times as weights, and you would seek the minimal-cost route.
In this chapter, we develop two algorithms for building the shortest path between two vertices in a weighted graph. We arrive at both algorithms by again weakening postconditions. The Bellman-Ford algorithm allows negative weights. It is not greedy because it modifies—not just builds on—a developing solution. By contrast, Dijkstra’s algorithm does not allow negative weights and is ...
Read now
Unlock full access