Find cheapest routes with weighted graph algorithms

8 steps · about 2 h 33 min · Intermediate

  1. Name the parts of a weighted graph (article, Runestone Academy, 12 min)

    Start with precise vocabulary for vertices, edges, paths and weights.

  2. Represent the network with adjacency maps (article, Runestone Academy, 18 min)

    A useful implementation begins with a representation that exposes each outgoing weighted edge.

  3. Trace Dijkstra's greedy choice (article, Boost Graph Library, 20 min)

    See why finalising the nearest unsettled vertex works when weights are non-negative.

  4. 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.

  5. Relax every edge with Bellman–Ford (article, CP-Algorithms, 25 min)

    Learn the alternative that tolerates negative edges and exposes reachable negative cycles.

  6. Extract a negative cycle (article, CP-Algorithms, 18 min)

    Make cycle detection actionable by reconstructing the offending loop.

  7. 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.

  8. 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.