101 Logo
onenoughtone

The Four Core Patterns of BFS

Understanding BFS Patterns

Breadth-First Search can be applied to a wide variety of problems, but most of them follow one of these four core patterns.

Each pattern represents a different way of thinking about and applying BFS to solve problems.

Shortest Path Pattern

Find the shortest path between two vertices in an unweighted graph using BFS.

Level Order Traversal Pattern

Traverse a tree level by level, visiting all nodes at each level before moving to the next level.

Connected Components Pattern

Find all connected components in an undirected graph using BFS.

Bipartite Graph Pattern

Check if a graph is bipartite (can be colored with two colors such that no adjacent vertices have the same color).

IntroVisualizePatternsPractice
101 Logo
onenoughtone