Best First Search
Best-First Search (BFS) is an informed search algorithm that explores a search space by selecting nodes estimated to be closer to the goal. Unlike uninformed search algorithms such as Breadth-First Search or Depth-First Search, BFS uses a heuristic function to guide the search efficiently, making it suitable for large search spaces.
Key Concepts:
Heuristic Function (h(n)):
- Estimates the distance or cost from the current node to the goal.
- Guides the algorithm to select the most promising node first.
- Example: Euclidean distance or Manhattan distance between nodes.
Priority Queue (Open List):
- Stores nodes yet to be explored.
- Nodes with lower heuristic values (closer to goal) are given higher priority.
- Ensures efficient selection of nodes during search.
Node Expansion:
- The algorithm expands the current node to explore its neighbors.
- For each neighbor, the heuristic value is calculated.
- Neighboring nodes are added to the priority queue according to their heuristic values.
Node Selection:
- The next node to expand is selected from the priority queue based on the lowest heuristic value.
- This node is considered the most promising path toward the goal.
Goal Test:
- The search stops when the selected node is the goal.
- If the goal is found, the path from start to goal is returned as the solution.
Iteration:
- If the selected node is not the goal:
- Expand its neighboring nodes.
- Calculate heuristic values for neighbors.
- Add neighbors to the priority queue.
- Repeat until the goal is reached or the priority queue is empty.
- If the selected node is not the goal:
Termination:
- If the priority queue becomes empty and the goal is not found, the search terminates without a solution.
- BFS may not always find the shortest path unless the heuristic is admissible.
Advantages:
- Faster than uninformed search algorithms.
- Focuses on promising paths toward the goal.
Drawbacks:
- Not guaranteed to find the optimal path with a non-admissible heuristic.
- Can get stuck in local minima if heuristic is misleading.