Breadth-First Search (BFS)
Definition
Graph and tree search algorithm, which searches nodes layer by layer for their distance from the starting node.
The breadth-first search first visits the starting node, then all directly adjacent nodes, then their still unvisited neighbors and so on. Typically, a queue is used for this. In unweighted graphs, BFS finds a path with minimal number of edges.
Simply explained
Instead of following a path deeply, the algorithm first looks at everything in close proximity and works its way outwards level by level.
Why it matters in practice
Basic algorithm for graphing, routing, dependencies and state spaces. It is also an important basis for search and planning procedures.
Example from business
Example scenario: In an unweighted network, the shortest path is sought in terms of the number of connections between two nodes.
Limits and pitfalls
- Confuse BFS with depth search; use weighted edges without adjustment; do not mark visited nodes; underestimate memory requirements on very wide graphs.
Origin & history
Broadband search is one of the classic graph search methods and has been used in computer science and artificial intelligence for decades.
Use in mid-sized companies
- Use for unweighted relationship graphs, state spaces or dependency analyses when a layer-by-layer search or shortest number of edges is required.
Frequently asked questions
Does BFS always find the shortest path?
In unweighted graphs with respect to the number of edges, yes.
Which data structure is typically used?
A queue.
Is BFS the same as DFS?
No.
Sources
- breadth-first search · NIST Dictionary of Algorithms and Data Structures, breadth-first search
Source verification: 10/09/2026. Definition and documented classification checked; examples describe possible applications.
Editorially reviewed on: