VOOZH about

URL: https://www.geeksforgeeks.org/dsa/greedy-best-first-search-algorithm/

⇱ Greedy Best first search algorithm - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Greedy Best first search algorithm

Last Updated : 27 May, 2026

Greedy Best-First Search is an AI search algorithm used to find a path from a starting node to a goal node by selecting the path that appears most promising at each step. It uses heuristic values to guide the search toward the goal efficiently.

  • Prioritizes faster exploration over guaranteed optimal solutions
  • Expands the node with the lowest heuristic value
  • Reduces search effort by focusing on promising paths
  • Commonly applied in navigation systems and pathfinding problems

Working

Greedy Best-First Search works by selecting the node that appears closest to the goal using heuristic values and continues expanding the most promising path until the destination is reached.

  • Starts from the initial node and evaluates neighboring nodes using heuristic values
  • Selects the node with the lowest heuristic value for expansion
  • Expands the most promising path instead of exploring all possible paths
  • Repeats the process until the goal node is reached
  • Uses heuristic estimates to reduce search time and guide traversal efficiently
👁 greedy_best_first_search
Workflow of Greedy Best first Search Algorithm

Implementation

Let's implement the Greedy Best-First Search algorithm using a graph where heuristic values estimate the distance from each node to the goal node.

Step 1: Importing the heapq module for priority queue operations and define the graph structure.

Step 2: Now we assign heuristic values to each node representing estimated distance to the goal node.

Step 3: Creating a function that selects and expands the node with the lowest heuristic value until the goal node is reached.

Step 4: We call the function to find the path from node A to node G.

Output:

Path found: A -> C -> F -> G

Advantages

  • Easy to implement due to its simple heuristic-based approach
  • Finds solutions quickly by expanding the most promising nodes first
  • Requires comparatively less memory than many other search algorithms
  • Flexible enough to be adapted for different search and pathfinding problems
  • Performs efficiently when the heuristic function accurately estimates the goal distance

Limitations

  • Does not guarantee the shortest or most optimal solution as it only focuses on the most promising path
  • Can get trapped in local optima, leading to suboptimal path selection
  • Requires a suitable heuristic function, which may increase algorithm complexity
  • May fail in highly complex or cyclic search spaces without additional handling mechanisms

Applications

  • Pathfinding: Used to find efficient paths in video games, robotics, and navigation systems
  • Machine Learning: Helps explore promising solutions within large search spaces
  • Optimization: Assists in selecting parameter values for desired outcomes
  • Game AI: Evaluates possible moves to choose favorable actions
  • Natural Language Processing: Applied in tasks like language translation and speech recognition
  • Image Processing: Helps segment images into meaningful regions
Comment
Article Tags: