Search algorithm
Running BFS centered on _

Execution Summary

Click move forward to enable execution summary

Introduction to Breadth-First Search (BFS)

Breadth-first search (BFS) is a fundamental algorithm used in computer science for traversing or searching tree or graph data structures. It's often compared to exploring a maze, where you systematically explore all possible paths to find the shortest one.

How BFS Works

  1. Starting Point: BFS begins at a designated starting point, typically called the "root" or "starting node."

  2. Exploring Nearby: It explores all neighboring nodes of the starting point before moving on to deeper nodes.

  3. Expanding Horizontally: BFS expands outwards horizontally, exploring all nodes at the current depth level before moving deeper.

  4. Queue: To keep track of which nodes to explore next, BFS uses a data structure called a queue. Nodes are added to the queue as they are discovered and explored in the order they were added.

  5. Marking Visited Nodes: To avoid revisiting nodes and getting stuck in infinite loops, BFS marks each node as visited after exploring it.

  6. Finding the Goal: BFS continues this process until it either finds the goal (if searching for a specific node) or exhausts all possible paths.


  • Shortest Path Finding: BFS is commonly used to find the shortest path between two nodes in an unweighted graph.
  • Connectivity: It can determine whether there is a path between two nodes.
  • Puzzle Solving: BFS can be applied to solve puzzles and games where finding the shortest path is crucial.

BFS is a versatile algorithm with various applications in computer science and beyond.

** Generated with the help of Chat GPT **