Beam search
search heuristic-search
Beam search explores a graph layer by layer, like breadth-first search, but keeps only the width states with the smallest f = g + h in each layer. So each layer costs at most width expansions; beam_search still remembers every state it generated and never expands one twice. It is incomplete (it can fail when a path exists) and not optimal. When it finds no goal after the width dropped a state, it reports a cutoff, not that no path exists. Use it when a good path fast matters more than the best path; use beam-stack search when you need a guarantee.
Pseudocode
algorithm Beam search(s₀, goal, h, width)input: start s₀, goal test goal, heuristic h, beam width width ≥ 1output: some path to a goal, a cutoff, or failureg[s₀] ← 0SEEN ← {s₀}LAYER ← ⟨s₀⟩pruned ← falsewhile LAYER ≠ ∅ doNEXT ← ∅for each s in LAYER, in order of f = g + h doif goal(s) thenreturn path-to(s)for each (s′, c) in successors(s) doif s′ ∉ SEEN thenSEEN ← SEEN ∪ {s′}g[s′] ← g[s] + cparent[s′] ← sNEXT ← NEXT ∪ {s′}else if s′ ∈ NEXT and g[s] + c < g[s′] theng[s′] ← g[s] + c ▷ the cheaper path in a layer winsparent[s′] ← sif |NEXT| > width thenpruned ← trueLAYER ← the width states of NEXT with the smallest g + hif pruned thenreturn cutoff ▷ a wider beam may find a goalreturn failureIn the crates
heuristic-searchIncomplete beam search with a fixed width; reports a cutoff when the width pruned.
Lineage
Comes from
builds on Breadth-first search
Led to
Beam-stack search builds on it