0-1 BFS & Multi-Source BFS

Data Structures & Algorithms · Advanced Graphs · Advanced · 20 min

Find cheapest paths when every move costs 0 or 1 using a deque instead of a heap, and run one search from many starting points at once.

This lesson is part of TuringPath Pro. See plans.

What you will learn

  • Weights 0 and 1: a heap is overkill
  • The 0-1 BFS loop
  • Multi-source BFS: start everywhere at once
  • Grids with free and costly moves

More in Advanced Graphs

Previous: Bellman-Ford & Floyd-Warshall · Next: Strongly Connected Components