Planning & Search in Rust
Esc

Loading…

↑↓ move ↵ open Esc close
Colour theme
All algorithms

Breadth-first search

Also known as BFS

search miniplanheuristic-search

Breadth-first search (BFS) explores a state space level by level from the start: first all states one step away, then all states two steps away, and so on. It keeps the frontier in a first-in, first-out queue and visits each state at most once. So the first goal it reaches has the fewest steps of all paths to a goal. BFS is complete on finite spaces and optimal in the number of steps, but it ignores action costs; when steps have different costs, use Dijkstra's algorithm or A*.

See it run

1/102

The start state is the only open state.

Breadth-first search on a small example.Open states are expanded in the order they were found, ignoring costs. openclosedexpandingpathwallcostly cell

Pseudocode

algorithm BFS(s₀, goal)input: start state s₀, goal test goaloutput: a path to a goal with the fewest steps, or failureQ ← ⟨s₀⟩                                     ▷ first in, first outSEEN ← {s₀}while Q ≠ ∅ dos ← pop-front(Q)if goal(s) then                            ▷ heuristic-search tests when a state is generatedreturn path-to(s)for each (o, s′) in successors(s) do       ▷ every operator applicable in sif s′ ∉ SEEN thenSEEN ← SEEN ∪ {s′}parent[s′] ← (s, o)push-back(Q, s′)return failure

In the crates

Lineage

Comes from

Nothing on this site.

Led to

Beam search builds on it

Bidirectional BFS builds on it

IW builds on it

Symbolic BFS builds on it