The Beauty of BFS


Breadth First Search is an algorithm fo finding a specified node in a tree or graph. It works by first visiting the start node, and then visiting all of its children before any of the children's children.

Key Features of BFS

Algorithm Steps for BFS

  1. Select a starting node and insert it into an empty queue.
  2. Given that the queue is not empty, extract the node from the queue and add all of its children to the queue for later processing.
  3. If extracted node is the node to search for, return the node.
  4. Repeat process with children now in queue until specified node is found or queue is empty.

Visualization of BFS

BFS Step 1 BFS Step 2 BFS Step 3 BFS Step 4 BFS Step 5 BFS Step 6 BFS Step 7

Learn More

For more in-depth information, check out Geeks for Geeks.