Python Arena

Module 63 Extra

Graphs

Graphs, for anything made of connections. Adjacency lists built from a list of edges, breadth-first search for the fewest steps on a grid, depth-first search with a stack of your own for flood fill and groups, topological sort for an order to build things in, Dijkstra's algorithm with heapq for weighted routes, and union-find for groups that merge, with big tests where the right algorithm is the fast way.

Steps

  1. Graphs and adjacency lists
  2. Breadth-first search
  3. Depth-first search and flood fill
  4. Topological sort
  5. Dijkstra's shortest paths
  6. Challenge: union-find