best first search sobreadth first search can find an optimal solution and deal with infinite search spacesbut it is not very efficient and can only be used in some smaller problems hill climbing is more efficientbut may not find an optimal solution combining the two we get best first search in best first search we order the entire queue according to the distance of each current node to the goal using the same heuristic as hill climbing best first example consider the example in fig step moves closer by moving down one row to step nowto the right of step is an equally good move (actually better knowing the optimal solution)but the next step is better at step than to the right of because it is closer to the eventual goal so best first proceeds down and to the right like hill climbing until it gets to step in red at this step it is forced to move up and away from the goal in this case red step looks just as good as blue step along the bottom the manhattan distance of both is when we reach red step then blue step in the middle of the maze looks just as good the effect of heading away from the goal is to start search all paths simultaneously that' how best first works it explores one path while it is moving towards the goal and multiple paths when moving away from the goal the code for best first search is lot like breadth first except that priority queue is used to sort the possible next steps on the queue according to their estimated distance from the goal best first has the advantage of considering multiple pathslike breadth first searchwhen heading away from the goal while performing like hill climbing when heading toward the goal fig best first search of maze this copy belongs to 'acha