When to Use Each Algorithm

BFS vs 0-1 BFS vs Dijkstra

Keep these in mind:

  • You use BFS when all edges have equal weight. (usually 11)
  • You use 00-11 BFS when edges are 00 or ww. (again, usually w=1w=1)
  • You use Dijkstra when edges have different positive weights.
  • You use Bellman-Ford when negative edges exist.

For multi-source problems, sometimes we just add all sources to an initial queue.

You'll see how all these help in practice.