Breadth-First Search

Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph.

Related concepts

TopicDescription
Depth-First SearchExplore as far as possible down one path before backtracking, used to walk trees, graphs, and grids.
QueuesFirst-in, first-out collection for scheduling, BFS, and buffering.
GraphsNodes and edges modeling networks, dependencies, and paths.
TreesHierarchical nodes with parent–child links for ordered and nested data.
Dijkstra's AlgorithmFind the shortest path from a starting node to every other node in a graph where edges have non-negative weights.
Bellman-Ford AlgorithmFind the shortest path from a starting node even when some edges have negative weights, and detect negative cycles.