Breadth-First Search (BFS) Pattern
Breadth-First Search (BFS) explores nodes level by level in a tree or graph. It uses a queue to process nodes and is ideal for finding shortest paths in unweighted graphs.
When to Use This Pattern
- Finding shortest paths in unweighted graphs
- Level-order traversal in trees
- Finding minimum steps to reach a target
- Problems requiring level-by-level processing
Key Concepts
BFS uses a queue (FIFO) to process nodes level by level. It guarantees finding the shortest path in unweighted graphs.