Best-First Search

Suppose PQ is a priority queue that stores states so that the state with the lowest heuristic value is removed first (of course there may be ties).

Then the following operation will construct a search tree in a "best-first" fashion:

Search(s)
   d[s] = 0
   pred[s] = null
   PQ = {s}
   while PQ ≠ {} do
      u = Remove[PQ]
      if success
         then return u
      else
         for each v ∈ Expand(u) do
             Add(PQ,v)
   return null