Best-first search is a search strategy that is more directed than simple breadth- or depth-first search. In best first search, all possible successor states are expanded from the current state, and then assigned a score based on some global measure of optimality. The next step proceeds from the highest-scoring state. The state ranking is typically maintained in a priority queue, with a secondary reverse lookup from states to scores in order to avoid double computation. The termination condition depends on the application.

The memory requirement of best-first search scales with the number of distinct states visited. In systems where the number of possible states is unbounded (or even extremely large), this can quickly grow intractable. One compromise solution is beam search, a greedier variant of best-first search.