A network diagram, representing breadth-first search.

Exploring a graph level by level.

What breadth-first search is

Breadth-first search, often shortened to BFS, is an algorithm for exploring a graph or tree. It starts at a chosen point and explores all of that point's immediate neighbors first, then the neighbors of those, and so on. In other words, it explores the structure level by level, spreading outward evenly rather than diving deep along one path. This orderly, layer-by-layer exploration is what defines BFS.

Exploring level by level

The central idea of breadth-first search is to visit everything at the current distance from the starting point before moving on to anything farther away. It first looks at all the points directly connected to the start, then all points two steps away, then three, and so on. This means BFS discovers nearer parts of the structure before more distant ones, exploring in expanding layers.

How BFS keeps track

To explore in the right order, breadth-first search keeps track of which points to visit next using a queue, a structure that handles items in the order they were added. It also remembers which points it has already visited so it does not process them again. By adding newly discovered neighbors to the queue and handling them in turn, BFS naturally works through the structure level by level.

Finding shortest paths

A useful property of breadth-first search is that, in a graph where all connections count equally, it finds the shortest path from the start to any other reachable point. Because BFS reaches closer points before farther ones, the first time it arrives at a point is by one of the shortest routes. This makes BFS a natural choice for shortest-path problems in unweighted graphs.

Where BFS is used

Breadth-first search is used in many situations that involve exploring connections, such as finding the shortest route in a network, exploring relationships, or systematically searching through possibilities. Its level-by-level approach makes it well suited to problems where nearness matters. As one of the fundamental graph algorithms, BFS appears throughout computer science and practical applications.

Why it matters

Breadth-first search is a foundational algorithm for exploring graphs and finding shortest paths in simple cases. Understanding what BFS is - exploring a structure level by level using a queue - clarifies a core technique in computer science. For anyone learning about algorithms and graphs, breadth-first search is an essential concept to understand.

See also: What is a graph data structure? Explained, What is depth-first search? Explained.

Sources

Published date reflects the original event date (2023-07-18). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.

Skillo Staff

Skillo Staff

All stories by: Skillo Staff

Leave a Reply