Breadth-First-Search(BFS) Explained With Visualization

2020-03-22

BFS Overview

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.