Graphs: Search algorithm comparison

Tags: til graphs algorithms

The common graph search algorithms all have a common structure:

  1. We can walk walk the graph but don't have random access i.e. we can only ever discover nodes connected to the set of nodes that we have found so far.
  2. As we reach nodes we remember them.
  3. As we reach nodes we queue them up for future exploration.
  4. As we reach nodes we remember some details about the shortest path there e.g. length, or predecessor.

The choice of how we queue up nodes for future exploration is the main difference between the search algorithms:

The choice of what to remember in #4 is problem specific and doesn't relate to the algorithm.

Published on: 02 May 2025