Breadth-First Search
Easy
BFS Fundamentals & Patterns
Mastering the Queue traversal patterns.
10 min
Solve on LeetCodeStandard 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
visitedset needed (unless traversing up to parents).
Graphs:
- Can have cycles (A -> B -> A).
- Can be undirected.
- MUST use
visitedset to prevent infinite loops.
ON THIS PAGE
- Standard BFS vs Level-Order BFS
- 1. Simple BFS (Stream Processing)
- 2. Level-Order BFS (Layer Processing)
- Trees vs Graphs
- Complexity Reminders
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.
