← All templates

BFS

Pro

Use when you need level-by-level exploration. Examples may be shortest path or minimum steps in an unweighted graph/tree.

Keywords for BFS Problems

→ “Shortest path” (unweighted)
→ “Minimum number of steps / moves”
→ “Nearest / closest”
→ “Level by level”
→ “Minimum distance”
→ “Fewest edges”
→ “Multi-source”
→ “Expand outward”

Unlock the BFS template

Get the full code template and worked LeetCode examples for BFS — plus every other pattern in the library — with a one-time $29 lifetime upgrade.

Upgrade to ProSee free Binary Search template →
BFS · Templates · Grind Patterns