2-Best First Search (Informed Search)
2-Best First Search (Informed Search)
In BFS and DFS, when we are at a node, we can consider any of the adjacent as the next node. So both BFS and DFS blindly explore
paths without considering any cost function.
The idea of Best First Search is to use an evaluation function to decide which adjacent is most promising and then explore.
Best First Search falls under the category of Heuristic Search or Informed Search.
We use a priority queue or heap to store the costs of nodes that have the lowest evaluation function value. So the implementation is a
variation of BFS, we just need to change Queue to PriorityQueue.
Illustration:
We start from source “S” and search for goal “I” using given costs and Best First search.
pq initially contains S
int source = 0;
int target = 9;
// Function call
best_first_search(source, target, v);
return 0;
}
Output
0 1 3 2 8 9
Analysis :
The worst-case time complexity for Best First Search is O(n * log n) where n is the number of nodes. In the worst case, we may have
to visit all nodes before we reach goal. Note that priority queue is implemented using Min(or Max) Heap, and insert and remove
operations take O(log n) time.
The performance of the algorithm depends on how well the cost or evaluation function is designed.