Breadth-First Search (BFS)

Explores the grid level by level using a queue, guaranteeing the shortest path in unweighted graphs.

Optimal:YesWeighted:No
Complexity
Best
O(V+E)
Average
O(V+E)
Worst
O(V+E)
Space
O(V)
When to use: Best for unweighted grids when you need the shortest path.Finds the shortest path (unweighted)Can explore many nodes in large open areas
Pseudocode
queue ← [start]
parent[start] ← null
while queue not empty:
v ← pop_front(queue)
for each neighbor u of v:
if u not seen:
parent[u] ← v
push_back(queue, u)
if goal reached: reconstruct path
Waiting to start…