Breadth-First Search
Easy

BFS Fundamentals & Patterns

Mastering the Queue traversal patterns.
Standard BFS vs Level-Order BFS

There are two main ways to write the BFS loop. Understanding the distinction is key for solving different types of problems.

Trees vs Graphs

Trees:

  • No cycles.
  • Usually directed (Parent -> Child).
  • No visited set needed (unless traversing up to parents).

Graphs:

  • Can have cycles (A -> B -> A).
  • Can be undirected.
  • MUST use visited set to prevent infinite loops.

Stop Guessing, Start Mastering.

Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.

Start Your Premium Prep