BFS Path Finder

The BFS Path Finder demonstrates how the Breadth-First Search algorithm traverses a grid level by level to locate the shortest path between two points. Each cell in the grid represents a node, and movement between adjacent cells represents edges in a graph. BFS guarantees the shortest path in an unweighted graph by exploring nodes in increasing distance from the starting point. This visualization highlights how the algorithm expands outward like a wave until the target is reached.

Loading demo…

Algorithm explanation

Breadth-First Search (BFS) explores nodes layer by layer using a queue. 1. Start by adding the starting node to a queue. 2. Mark the starting node as visited. 3. While the queue is not empty: - Remove the first node from the queue. - If it is the target node, stop. - Otherwise, add all unvisited neighboring nodes to the queue. 4. Keep track of parent nodes to reconstruct the shortest path. Because BFS visits nodes in order of distance from the start, the first time the target is reached guarantees the shortest path in an unweighted graph.

Concepts used

  • Graphs
  • Queue
  • Breadth-First Search
  • Shortest Path
  • Graph Traversal

Complexity

Time: O(V + E)
Space: O(V)

Real-world usage

  • Shortest path in unweighted maps or grids
  • Network broadcasting and routing
  • Web crawling
  • Social network degree-of-separation analysis
  • Game AI movement in tile-based maps

Related Algorithms