The Breadth-First Search(BFS) is another fundamental search algorithm used to explore the nodes and edges of a graph. It runs with time complexity of O(V+E), where
V is the number of nodes, and
E is the number of edges in a graph.
BFS is particularly useful for finding the shortest path on unweighted graphs.
BFS Visualization on Maze
The source is at the position of left-up, and the target is the position of right-bottom.
As we can see, BFS uses the opposite strategy as with DFS. BFS will explore all of the neighbor nodes at the present position, then move on to the larger depth of nodes.
The maze is generated by disjoint set.
An implementation of BFS needs the data-structure of
queue, with the property of First-In-First-Out.
The worst-case space complexity is O(V), where V is the number of nodes in the graph.
- C: Algorithms
Join my Email List for more helpful insights, It's Free!😋