Algo Visualiser
SortingPathfinding

Breadth-First Search

Explores the grid in rings, visiting every cell at distance 1, then 2, and so on, until it reaches the goal.

In real life: Degrees of separation in a social network: friends are level 1, friends of friends level 2, the basis of 'people you may know'.

Live stats

Visited
0
of 1,907
Path length
0
of 83
Path cost
82
Search time
–
  1. queue = [start]
  2. while queue is not empty
  3. tile = queue.dequeue(); mark visited
  4. if tile == end: break
  5. for each unvisited neighbour n of tile
  6. n.parent = tile; queue.enqueue(n)
  7. path = follow parents back from end

Press play or → to start.

How to use

Click or touch and drag to paint walls or weights (pick the brush), or generate a maze. Drag the start and end tiles to move them. Press play (space) to run, and ← / → to step.

Legend

  • Start
  • End
  • Wall
  • Weight: costs 5 to enter
  • Visited
  • Path
0 / 1,990