Find cheapest routes with weighted graph algorithms
8 steps · about 2 h 33 min · Intermediate
- Name the parts of a weighted graph (article, Runestone Academy, 12 min)
Start with precise vocabulary for vertices, edges, paths and weights.
- Represent the network with adjacency maps (article, Runestone Academy, 18 min)
A useful implementation begins with a representation that exposes each outgoing weighted edge.
- Trace Dijkstra's greedy choice (article, Boost Graph Library, 20 min)
See why finalising the nearest unsettled vertex works when weights are non-negative.
- Implement Dijkstra with a priority queue (article, CP-Algorithms, 25 min)
Turn the idea into an efficient sparse-graph implementation and handle stale queue entries.
- Relax every edge with Bellman–Ford (article, CP-Algorithms, 25 min)
Learn the alternative that tolerates negative edges and exposes reachable negative cycles.
- Extract a negative cycle (article, CP-Algorithms, 18 min)
Make cycle detection actionable by reconstructing the offending loop.
- Compare shortest-path tools and assumptions (article, NetworkX, 15 min)
Use a library reference to connect graph shape and edge properties to the right routine.
- Test shortest paths with a trusted implementation (article, NetworkX, 20 min)
Build changing weighted graphs, predict the cheapest route and compare it with a library result.