Best First Search
Definition
Best First Search is an informed search algorithm that selects and expands the most promising node from the frontier based on a heuristic evaluation function.
In simple words, it chooses the “best-looking” node first according to a rule that estimates how close that node is to the goal. The evaluation function may be based on:
- an estimated cost from the current node to the goal,
- the cost already spent to reach the node,
- or a combination of both.
A common form is:
f(n) = h(n)whereh(n)is the heuristic estimate of the cost from nodento the goal.
In some related variants, the evaluation may be:
f(n) = g(n) + h(n)g(n)= cost from the start node tonh(n)= estimated cost fromnto the goal
This makes Best First Search a guided search method rather than a purely random or level-based search.
Main Content
1. Heuristic Evaluation Function
- The most important idea in Best First Search is the heuristic function, which helps the algorithm decide which node appears most promising.
- The heuristic is an estimate, not an exact answer. It uses domain knowledge to guess which node is likely closer to the goal or more useful to expand.
For example, in route planning, if the goal is a city, the heuristic might be the straight-line distance from the current city to the destination. Even though the actual road path may be longer, the straight-line distance gives a useful estimate.
A good heuristic should:
- guide the search toward the goal efficiently,
- be simple to compute,
- and ideally never overestimate too much if optimality is important.
If the heuristic is poor, the search may still work, but it may explore many unnecessary nodes and lose efficiency.
2. Frontier and Node Selection
- Best First Search maintains a frontier, also called the open list, which stores nodes that have been discovered but not yet expanded.
- At every step, it selects the node with the best evaluation value from this frontier.
This selection is what makes the algorithm “best first.” The “best” node is not necessarily the cheapest overall path, but the one that appears most promising according to the evaluation function.
Example behavior:
- Suppose the algorithm has three frontier nodes A, B, and C.
- Their heuristic values are:
- A = 8
- B = 3
- C = 5
- The algorithm will choose B first because it has the smallest value.
This process continues until:
- the goal is found, or
- the frontier becomes empty, meaning no solution exists.
3. Types and Related Forms
- Best First Search is a general strategy, and different search algorithms can be seen as special cases of it.
- The two most commonly discussed related forms are Greedy Best First Search and A* Search.
Greedy Best First Search:
- Uses only the heuristic value
h(n). - Expands the node that seems closest to the goal.
- Can be fast, but it does not always find the shortest or optimal path.
A* Search:
- Uses
f(n) = g(n) + h(n). - Combines actual cost from the start and estimated cost to the goal.
- More balanced and often optimal if the heuristic is admissible.
Comparison idea:
- Greedy Best First Search focuses on “what looks closest.”
- A* focuses on “what has the lowest estimated total cost.”
Thus, Best First Search is not one single rigid algorithm but a family of guided search methods built around choosing the most promising node first.
Working / Process
1. Initialize the frontier
- Start by placing the initial node into the frontier.
- Assign it a heuristic value or evaluation score based on the chosen function.
2. Select the best node
- Remove the node from the frontier that has the best evaluation value.
- Expand this node by generating its successor nodes.
3. Repeat until the goal is reached
- Add new successor nodes to the frontier.
- Keep selecting the most promising node again and again.
- Stop when the goal node is selected or when no nodes remain.
A simple process illustration:
Start
|
v
Add initial node to frontier
|
v
Pick node with best score
|
v
Is it goal?
|---- Yes ---> Stop
|
No
|
v
Expand node and add children
|
v
Repeat
Example: If a search is trying to reach a destination in a graph, the algorithm may first select the node that is geographically closest to the destination, then continue from there. This can significantly reduce the number of explored nodes compared to brute-force methods.
Important note:
- A node may be revisited if the algorithm does not properly maintain visited states.
- In practical implementations, a closed list is often used to avoid repeated work.
Advantages / Applications
Efficient search in large problem spaces
- Best First Search can drastically reduce the number of explored nodes by focusing only on promising candidates instead of exploring everything blindly.
Useful when heuristic knowledge is available
- It performs especially well when a good estimate can be designed for the problem, such as distance, similarity, or cost approximation.
Widely applied in real-world AI problems
- It is used in pathfinding, robotics, game AI, puzzle solving, scheduling, and routing problems where intelligent guidance improves performance.
Examples of applications:
- GPS route finding
- Maze solving
- Robot navigation
- Game tree exploration
- Medical diagnosis systems
- Automated planning
Limitations worth noting:
- It may not always find the shortest path if used in a greedy form.
- Its quality depends heavily on the heuristic.
- Poor heuristic design can make it inefficient or mislead the search.
Summary
- Best First Search is a heuristic-guided search method that always expands the most promising node first.
- It is effective when the problem provides useful knowledge for choosing the next node.
- It is commonly used in AI for efficient decision-making and pathfinding.
- Important terms to remember: heuristic, frontier, evaluation function, greedy search, A* search.