Best-First Search is a graph and tree traversal algorithm that expands the most promising node, as determined by a domain-specific evaluation function f(n), before exploring less promising alternatives. Unlike systematic methods like breadth-first or depth-first search, it uses a priority queue (often a min-heap) to always select the node with the lowest estimated cost to the goal for expansion next. This makes it a greedy, informed search strategy designed to find a solution quickly, though not necessarily optimally, by leveraging heuristic guidance.
Glossary
Best-First Search

What is Best-First Search?
Best-First Search is a fundamental heuristic search algorithm that prioritizes exploration of the most promising path in a graph or tree based on an evaluation function.
The algorithm's efficiency hinges entirely on the quality of its heuristic function. A perfect heuristic leads directly to the goal, while a poor one can cause degenerate performance worse than uninformed search. Common implementations include Greedy Best-First Search, where f(n) = h(n) (the heuristic estimate), and the more sophisticated A Search*, where f(n) = g(n) + h(n) combines the path cost g(n) with the heuristic. It is a core component of Monte Carlo Tree Search for node selection and is widely used in pathfinding, puzzle solving, and automated planning systems within agentic architectures.
Best-First Search vs. Other Search Algorithms
A feature comparison of Best-First Search against other fundamental graph and tree traversal algorithms, highlighting their core mechanisms, data structures, and suitability for different problem types.
| Feature / Metric | Best-First Search (Greedy BFS) | Breadth-First Search (BFS) | Depth-First Search (DFS) | Uniform-Cost Search (Dijkstra) |
|---|---|---|---|---|
Primary Data Structure | Priority Queue (Heap) | Queue (FIFO) | Stack (LIFO) | Priority Queue (Heap) |
Node Expansion Order | Most promising node first (by heuristic h(n)) | Shallowest unexpanded node first | Deepest unexpanded node first | Lowest cumulative path cost g(n) first |
Evaluation Function Used | Heuristic h(n) only | None (blind search) | None (blind search) | Path cost g(n) only |
Completeness (finds solution if exists?) | ||||
Optimality (finds least-cost path?) | ||||
Time Complexity (worst-case) | O(b^m) | O(b^d) | O(b^m) | O(b^(1 + C*/ε)) |
Space Complexity (worst-case) | O(b^m) | O(b^d) | O(b*m) | O(b^(1 + C*/ε)) |
Requires Heuristic Function? | ||||
Prone to Getting Stuck in Local Optima? | ||||
Primary Use Case | Informed search with a good heuristic (e.g., pathfinding) | Finding shortest path in unweighted graphs, web crawling | Topological sorting, maze solving, cycle detection | Finding shortest path in weighted graphs |
Frequently Asked Questions
Best-First Search is a cornerstone heuristic algorithm for navigating complex decision spaces. These questions address its core mechanics, applications, and relationship to other search paradigms in AI and agentic systems.
Best-First Search is a graph or tree traversal algorithm that expands the most promising node next, as determined by an evaluation function f(n). It operates using a priority queue (often a min-heap) to manage the search frontier. The algorithm repeatedly dequeues the node with the best f(n) score, expands it to generate its children, evaluates them, and inserts them into the queue. This process continues until a goal node is found or the queue is exhausted. Unlike Breadth-First Search or Depth-First Search, its expansion order is not fixed by depth but dynamically guided by the heuristic, aiming to find a solution quickly by prioritizing nodes that appear closest to the goal.
Core Steps:
- Place the root node in the priority queue.
- While the queue is not empty:
a. Dequeue the node
nwith the optimalf(n). b. Ifnis the goal, return the solution path. c. Expandnto generate its successor nodes. d. For each successor, calculatef(successor)and enqueue it. - Return failure if the queue empties.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Best-First Search is a member of a broader family of heuristic search algorithms. Understanding these related concepts is essential for selecting the right tool for complex planning and reasoning tasks in AI systems.
Heuristic Function
A heuristic function is a problem-specific estimation function, denoted as h(n), that approximates the cost from a given node n to the goal. It is the core guiding mechanism in Best-First Search and other informed algorithms like A*. A good heuristic is admissible (never overestimates the true cost) and consistent, enabling the algorithm to find optimal paths efficiently. For example, in pathfinding, the straight-line Euclidean distance is a common heuristic.
Priority Queue
A priority queue is the fundamental data structure used to implement Best-First Search's open list. Nodes are stored not in the order they are discovered, but are ordered by a priority score derived from an evaluation function (e.g., heuristic value). The node with the most promising (lowest or highest) score is always selected for expansion next. This efficient ordering is what differentiates Best-First Search from uninformed methods like Breadth-First or Depth-First Search.
Greedy Best-First Search
Greedy Best-First Search is a specific, common variant of Best-First Search where the evaluation function f(n) is simply the heuristic estimate h(n). It expands the node that appears closest to the goal. While often very fast, it is not optimal and not complete (can get stuck in loops) because it ignores the cost already incurred to reach the node g(n). It tends to be myopic, potentially leading to suboptimal solutions.
A* Search Algorithm
A Search* is a seminal optimal search algorithm that extends Best-First Search. Its evaluation function is f(n) = g(n) + h(n), where g(n) is the actual cost from the start node to n, and h(n) is the heuristic estimate to the goal. By combining the path cost with the heuristic, A* guarantees finding an optimal solution if the heuristic is admissible. It is the workhorse algorithm for many pathfinding and planning applications in AI and robotics.
Beam Search
Beam Search is a best-first, breadth-limited search algorithm. At each level of the tree, it expands all successors of the current nodes but only retains the top-k most promising nodes (the beam width) based on an evaluation function. The rest are pruned permanently. This makes it a memory-efficient approximation of Best-First Search, suitable for large state spaces like those in neural sequence generation (e.g., machine translation, text summarization).
Evaluation Function
An evaluation function assigns a numerical score to a game state or partial solution, estimating its utility or desirability. In Best-First Search, this function guides node selection. In game-playing AI (e.g., chess engines), evaluation functions are complex, often combining material advantage, board control, and king safety into a single score. They serve as a static, heuristic assessment of a non-terminal state, crucial for algorithms like Minimax with Alpha-Beta pruning.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us