Best First Search in Artificial Intelligence

Dinesh GLB
3 min readJul 25, 2023

--

Searching entails locating a solution or the most efficient path within a given problem space in AI. It requires examining various states or configurations to achieve the desired goal state or identify the optimal solution.

Informed search comprises search algorithms that leverage domain-specific information or heuristics to efficiently find the goal state in a search space. These algorithms make informed decisions on which path to explore, avoiding blind exploration of all possibilities.

In AI, a heuristic is a problem-solving technique that uses practical rules or educated guesses to find solutions more quickly and efficiently. It provides a guiding principle or estimation to assess which actions or paths are more promising in reaching the goal state. Heuristics are often employed in informed search algorithms like Best First Search, A* search (discussed in a later section)to prioritize exploration of states that are likely to lead to the desired outcome, effectively reducing search complexity. However, the accuracy of heuristics heavily influences the algorithm’s performance and the quality of the solutions found.

Best First Search Search: The primary objective of the best-first search is to expand the most promising nodes by relying on an evaluation function or heuristic. It exploits the benefits of both BFS (Breadth First Search) and DFS (Depth First Search)strategies. The best first search can switch between BFS (Breadth First Search) and DFS (Depth First Search) by gaining the advantages of both algorithms. We expand the node which is closest to the goal node and the closest cost is estimated by heuristic function h(n),

f(n) = h(n)

Here are the steps involved in the best-first search algorithm:

  1. Initialization: Start with an initial state as the current state and create an empty priority queue to store the nodes.
  2. Priority Queue: Add the initial state to the priority queue, considering the evaluation function or heuristic value for each state.
  3. Loop: Repeat the following steps until either a goal state is found or the priority queue is empty.
  4. Select Node: Dequeue the node with the highest priority (the lowest heuristic value) from the priority queue. This node represents the most promising state to explore next.
  5. Goal Test: Check if the selected node is a goal state. If it is, the search is complete, and the solution is found.
  6. Expand Node: Generate all possible successor states from the selected node.
  7. Add to Queue: For each successor state, calculate its heuristic value using the evaluation function and add it to the priority queue.
  8. Repeat: Continue the loop, selecting the next most promising node from the priority queue.
Example: Graph
Given Heuristic value
Given Heuristic value

In this search example, we utilize two lists: OPEN and CLOSED Lists. These lists help in managing and tracking the exploration of nodes during the search process.

Expand the nodes of S and put them in the CLOSED list

Initialization: Open [A, B], Closed [S]

Iteration 1: Open [A], Closed [S, B]

Iteration 2: Open [E, F, A], Closed [S, B]
: Open [E, A], Closed [S, B, F]

Iteration 3: Open [I, G, E, A], Closed [S, B, F]
: Open [I, E, A], Closed [S, B, F, G]

Hence the final solution path will be: S — → B — — ->F — → G

--

--