Breadth-First Search (BFS)

What is BFS?

Breadth-First Search is a graph traversal algorithm that explores nodes level by level, starting from a designated root node.

Key Steps of BFS

  1. Start by adding the source node to a queue.
  2. Remove a node from the queue and visit it.
  3. Add all unvisited neighbors to the queue.
  4. Repeat steps 2-3 until the queue is empty.

Advantages of BFS

BFS Diagram

Breadth-First Search Diagram

Learn More

For more detailed information, visit GeeksforGeeks: Breadth First Search or BFS for a Graph .