BFS Overview
The BreadthFirst 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 leftup, and the target is the position of rightbottom.
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.
The implementation
An implementation of BFS needs the datastructure of queue
, with the property of FirstInFirstOut.
The worstcase space complexity is O(V), where V is the number of nodes in the graph.

References
 C: Algorithms
Join my Email List for more insights, It's Free!😋