Introduction to Beam Search Algorithm

Last Updated : 23 May, 2026

Beam Search is a heuristic search algorithm used in Artificial Intelligence to efficiently explore large search spaces by selecting only the most promising nodes at each level. Instead of expanding every possible path like Breadth-First Search, it keeps a limited number of best nodes based on heuristic values, making the search faster and more memory-efficient.

  • Uses a fixed beam width to limit node expansion
  • Balances efficiency and solution quality
  • Widely used in NLP, speech recognition, and pathfinding tasks
  • Width of the Beam (W): This parameter defines the number of nodes considered at each level. The beam width W directly influences the number of nodes evaluated and hence the breadth of the search.
  • Branching Factor (B): If B is the branching factor, the algorithm evaluates W \times B nodes at every depth but selects only W for further expansion.
  • Completeness and Optimality: The restrictive nature of beam search, due to a limited beam width, can compromise its ability to find the best solution as it may prune potentially optimal paths.
  • Memory Efficiency: The beam width bounds the memory required for the search, making beam search suitable for resource-constrained environments.

Working

Beam Search works by selecting only a limited number of the best nodes at each level based on heuristic values. Suppose the beam width \displaystyle W = 2, which means only the 2 most promising nodes are selected for further expansion at every level.

start
Beam Search Algorithm

Step 1: Start from the initial node Start.

Step 2: Generate all successor nodes: A, B, and C.

Step 3: Evaluate the nodes using heuristic values and select the best \displaystyle W = 2 nodes. Suppose A and B are selected, while C is discarded.

Step 4: Expand the selected nodes:

  • A → D, E
  • B → F, G

Step 5: Again evaluate the generated nodes (D, E, F, G) and keep only the best 2 nodes for further exploration.

Step 6: Repeat the process until the goal node is reached.

  • Efficient for large search spaces because it expands only limited nodes
  • Flexible since beam width and heuristic functions can be adjusted
  • Scalable for complex problems with many possible solution paths
  • Requires less memory than exhaustive search method
  • May miss the optimal solution because some paths are discarded early
  • Performance depends heavily on the quality of the heuristic function
  • Small beam width can remove potentially useful solutions
  • Large beam width increases computation time and memory usage

Applications

  • Used in machine translation, text generation, and speech recognition to predict the most likely sequence of words.
  • Helps robots find efficient paths and navigate through environments.
  • Used in strategic games where exploring every possible move is computationally expensive.
Comment