Breadth-first search

Breadth-first search (BFS) is a graph traversal algorithm that explores vertices level by level from a starting node. In Combinatorics, it is used to study paths, connectivity, and shortest routes in unweighted graphs.

Last updated July 2026

What is breadth-first search?

Breadth-first search is a way to explore a graph in Combinatorics by moving outward from a starting vertex one layer at a time. You visit all neighbors at distance 1 first, then all vertices at distance 2, then distance 3, and so on. That level-by-level pattern is what makes BFS different from other traversals.

The usual tool behind BFS is a queue. When you discover a new vertex, you put it at the back of the queue, and you remove vertices from the front in the order they were found. That order matters because it keeps the search organized by distance from the start, not by whichever branch looks deepest.

A simple way to picture BFS is a social network or a city map. If you start at one person or one intersection, BFS checks all immediate friends or streets first, then expands outward. In a graph with no edge weights, that means the first time you reach a vertex, you have found the shortest path to it in number of edges.

That shortest-path feature is one of the main reasons BFS shows up in graph theory problems. If a graph is connected, BFS from one vertex eventually reaches everything in that connected component. If the graph is disconnected, BFS only covers the part you can actually reach from the start, which makes it useful for identifying separate components.

BFS also shows up in trees as level-order traversal. Instead of going down one branch all the way, you list the root, then its children, then its grandchildren. That makes it a natural match for problems about depth, layers, and structure.

A common mistake is mixing up BFS with depth-first search. BFS spreads outward evenly, while depth-first search goes as far as possible down one path before backtracking. If the problem asks for the shortest unweighted path or a level-by-level visit, BFS is usually the move you want.

Why breadth-first search matters in COMBINATORICS

Breadth-first search matters in Combinatorics because graph questions are often really questions about distance, reachability, and structure. When you need to know whether two vertices are connected, how many steps away something is, or how a graph breaks into components, BFS gives you a clean procedure instead of guesswork.

It is also one of the easiest ways to justify a shortest path in an unweighted graph. Since BFS explores all vertices at distance 1 before any at distance 2, and all at distance 2 before distance 3, the first path you find to a vertex is the shortest one by edge count. That idea comes up in homework problems, algorithm trace questions, and proof-style explanations about graphs.

BFS connects directly to connectivity topics too. If a graph has isolated parts, BFS from one starting point will stop once the queue runs dry, which tells you exactly how far that component extends. In tree problems, the same process gives level order, which is a neat way to organize vertices by depth.

It also prepares you for more advanced graph algorithms. Minimum spanning tree methods, cycle checks, and network-style problems all rely on being comfortable with traversing a graph carefully and keeping track of what has already been discovered. BFS is one of the first traversal tools that makes that workflow feel natural.

Keep studying COMBINATORICS Unit 11

How breadth-first search connects across the course

Depth-First Search

Depth-first search is the main traversal people compare with BFS. BFS spreads across a graph by layers, while DFS follows one branch as far as it can before turning back. If a problem asks for shortest paths in an unweighted graph, BFS is usually better. If it asks for exploring structure deeply or testing recursion ideas, DFS is the other traversal to think about.

Shortest Path

BFS is the standard way to find a shortest path when every edge has the same cost. It counts edges, not weights, so it works best in unweighted graphs or graphs where each step has equal length. If weights matter, BFS no longer guarantees the best route, which is where other algorithms come in.

Graph Traversal

Graph traversal is the umbrella category that includes BFS and DFS. Traversal means you have a rule for visiting vertices without getting lost or repeating work. BFS is the version that visits nodes in layers, which makes it especially useful when the graph structure is about distance or connectivity.

Graph Connectivity

Connectivity is one of the first things BFS can reveal. Starting from one vertex, BFS shows exactly which vertices belong to the same connected component. If the queue empties before you reach every vertex in the graph, that is a sign the graph is disconnected.

Is breadth-first search on the COMBINATORICS exam?

A problem set or quiz item might give you a graph and ask for the BFS order from a chosen starting vertex. To answer it, you track the queue step by step, mark each vertex when it is first discovered, and list the vertices in the order they are reached. If the question asks for the shortest path in an unweighted graph, BFS is the method you use to justify the answer, not just guess it.

You may also be asked to explain why a graph is connected, identify a connected component, or show a level-order traversal of a tree. The safest move is to keep the layers straight and avoid revisiting nodes. If you accidentally jump to a deeper vertex before finishing the current layer, you are no longer doing BFS.

Breadth-first search vs Depth-First Search

These two are easy to mix up because both traverse graphs, but they answer different kinds of questions. BFS explores by distance from the start, which makes it the go-to for shortest paths in unweighted graphs. DFS goes down one path at a time, which is better for backtracking-style problems and structure exploration.

Key things to remember about breadth-first search

  • Breadth-first search explores a graph level by level, starting from one chosen vertex.

  • A queue keeps BFS in the correct order, so you process vertices in the same sequence they are discovered.

  • In an unweighted graph, BFS finds the shortest path in number of edges.

  • BFS is useful for connected components, level-order tree traversal, and basic cycle checks in undirected graphs.

  • If you see a problem about layers, distance from a start node, or reachability, BFS is probably the right traversal.

Frequently asked questions about breadth-first search

What is breadth-first search in Combinatorics?

Breadth-first search is a graph traversal algorithm that visits vertices one layer at a time from a starting node. In Combinatorics, it is used to study paths, connectivity, and shortest routes in graphs. It is especially handy when every edge has the same cost.

How does BFS find the shortest path?

BFS finds the shortest path in an unweighted graph because it checks all vertices one edge away before moving to two edges away, then three, and so on. The first time you reach a vertex, you have reached it by the fewest number of edges possible. That is why BFS is so useful for distance questions.

Is breadth-first search the same as depth-first search?

No. BFS spreads outward evenly by levels, while depth-first search goes deep along one branch before backtracking. They both traverse graphs, but they are used for different tasks. BFS is the one you want for shortest unweighted paths and layer-by-layer ordering.

How do you do BFS on a graph?

Start at the chosen vertex, mark it visited, and put it in a queue. Then repeatedly remove the front vertex, visit any unvisited neighbors, and add those neighbors to the queue. Keep going until the queue is empty, which means you have explored the whole reachable component.