Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
Introduction to Beam Search Algorithm
Next article icon

Introduction to Beam Search Algorithm

Last Updated : 03 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In artificial intelligence, finding the optimal solution to complex problems often involves navigating vast search spaces. Traditional search methods like depth-first and breadth-first searches have limitations, especially when it comes to efficiency and memory usage. This is where the Beam Search algorithm comes into play. Beam Search is a heuristic-based approach that offers a middle ground between these traditional methods by balancing memory consumption and solution optimality.

Introduction to Heuristic Techniques

Heuristic techniques are strategies that utilize specific criteria to determine the most effective approach among multiple options for achieving a desired goal. These techniques enhance the efficiency of search processes by prioritizing speed over systematic and exhaustive exploration. Heuristics are particularly useful for solving complex problems, such as the traveling salesman problem, in a time-efficient manner, often yielding good solutions without the exhaustive computational cost of exponential-time algorithms.

Understanding Beam Search Algorithm

Beam Search is a heuristic search algorithm that navigates a graph by systematically expanding the most promising nodes within a constrained set. This approach combines elements of breadth-first search to construct its search tree by generating all successors at each level. However, it only evaluates and expands a set number, W, of the best nodes at each level, based on their heuristic values. This selection process is repeated at each level of the tree.

Characteristics of Beam Search

  • 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.

Example: Consider a search tree where W = 2 and B = 3. Only two nodes (black nodes) are selected based on their heuristic values for further expansion at each level.

Beam Search

How Beam Search Works?

The process of Beam Search can be broken down into several steps:

  1. Initialization: Start with the root node and generate its successors.
  2. Node Expansion: From the current nodes, generate successors and apply the heuristic function to evaluate them.
  3. Selection: Select the top W nodes according to the heuristic values. These selected nodes form the next level to explore.
  4. Iteration: Repeat the process of expansion and selection for the new level of nodes until the goal is reached or a certain condition is met (like a maximum number of levels).
  5. Termination: The search stops when the goal is found or when no more nodes are available to expand.

LEARN-ONE-RULE Algorithm: A General-to-Specific Beam Search Approach

The LEARN_ONE_RULE function is a practical implementation of beam search designed to derive a single rule that covers a subset of examples. It utilizes a general-to-specific greedy search, guided by a performance metric to identify the most effective rule.

Algorithm Execution Flow

  1. Start:
    • Initialize the node to Root_Node and Found to False.
  2. Search Loop:
    • If the current node is the goal, set Found to True.
    • Otherwise, find successors and estimate costs, storing them in the OPEN list.
    • Continuously select the top W elements from the OPEN list for expansion.
  3. Evaluation:
    • If the goal is found during expansion, return Yes.
    • If the search concludes without finding the goal, return No.

Pseudocode

LEARN_ONE_RULE(Target_attribute, Attributes, Examples, k)
Initialize Best_hypothesis to the most general hypothesis (θ)
Initialize Candidate_hypotheses to {Best_hypothesis}

While Candidate_hypotheses is not empty:
All_constraints <- Set of all constraints (a = v) where:
a ∈ Attributes
v = value of a that occurs in Examples

New_candidate_hypotheses <- Empty Set
For each h in Candidate_hypotheses:
For each c in All_constraints:
new_h <- h + c
// Create specialization of h by adding the constraint c
If new_h is not duplicate, inconsistent, and maximally specific:
Add new_h to New_candidate_hypotheses

// Evaluate and update the best hypothesis
For each h in New_candidate_hypotheses:
If PERFORMANCE(h, Examples, Target_attribute) > PERFORMANCE(Best_hypothesis, Examples, Target_attribute):
Best_hypothesis <- h

// Narrow down to the k best hypotheses
Candidate_hypotheses <- Select the k best New_candidate_hypotheses based on PERFORMANCE

// Formulate the final rule
Return "IF Best_hypothesis THEN prediction"
Where prediction is the most frequent value of Target_attribute among Examples that match Best_hypothesis

Advantages of Beam Search

  • Efficiency: By limiting the number of nodes expanded, Beam Search can navigate large search spaces more efficiently than exhaustive searches.
  • Flexibility: The algorithm can be adjusted for different problems by modifying the beam width and heuristic function.
  • Scalability: Suitable for problems where the solution paths are vast and complex, as it does not require all nodes to be stored in memory.

Limitations of Beam Search

  • Suboptimality: There is no guarantee that Beam Search will find the optimal solution, especially if the beam width is too narrow.
  • Heuristic Dependency: The effectiveness of Beam Search is highly dependent on the quality of the heuristic function. Poor heuristics can lead to suboptimal searching and results.

Applications of Beam Search Algorithm in AI

Beam Search is widely used in various fields, including:

  • Natural Language Processing (NLP): For tasks like machine translation and speech recognition where the goal is to find the best sequence of words or phonemes.
  • Robotics: In pathfinding algorithms where a robot must find an efficient path in an environment.
  • Game AI: In strategic games where it is impractical to explore every possible move due to the enormous search space.

Conclusion

This structured approach to using heuristic techniques, particularly beam search, illustrates the potential to efficiently address complex search problems by balancing between breadth of search and memory constraints. By implementing the LEARN_ONE_RULE algorithm, we can effectively navigate through complex decision spaces to find practical solutions in various domains such as machine learning and optimization.


Next Article
Introduction to Beam Search Algorithm

S

sameekshakhandelwal1712
Improve
Article Tags :
  • Machine Learning
  • AI-ML-DS
Practice Tags :
  • Machine Learning

Similar Reads

    Search Algorithms in AI
    Artificial Intelligence is the study of building agents that act rationally. Most of the time, these agents perform some kind of search algorithm in the background in order to achieve their tasks. A search problem consists of: A State Space. Set of all possible states where you can be.A Start State.
    10 min read
    Bidirectional Search in AI
    Bidirectional search in AI is an algorithm that searches simultaneously from both the initial state and the goal state, meeting in the middle to reduce search time.The aim of the article is to provide an in-depth understanding of the bidirectional search algorithm, its working mechanism, benefits, a
    9 min read
    Greedy Best-First Search in AI
    Artificial Intelligence (AI) has evolved significantly, and various search algorithms have become fundamental in solving complex problems. Among these, Greedy Best-First Search stands out as a popular method for pathfinding and problem-solving due to its simplicity and efficiency in certain applicat
    11 min read
    Genetic Algorithms vs. Local Search Optimization Algorithms in AI
    Artificial Intelligence (AI) has revolutionized how we solve problems and optimize systems. Two popular methods in the optimization field are Local Search Optimization (LSO) algorithms and Genetic Algorithms (GAs). While both are used to tackle complex issues, their approaches, uses, and performance
    10 min read
    Local Search Algorithm in Artificial Intelligence
    Local search algorithms are essential tools in artificial intelligence and optimization, employed to find high-quality solutions in large and complex problem spaces. Key algorithms include Hill-Climbing Search, Simulated Annealing, Local Beam Search, Genetic Algorithms, and Tabu Search. Each of thes
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences